@@ -27,8 +27,6 @@ def sample_collection(database, user_id):
2727
2828@pytest .fixture
2929def mock_scheduler ():
30- """Mock the APScheduler to run jobs synchronously for testing."""
31-
3230 with patch ("pydatalab.routes.v0_1.export.export_scheduler" ) as mock_scheduler :
3331 mock_scheduler .add_job = MagicMock ()
3432
@@ -40,43 +38,34 @@ def mock_add_job(func, args, job_id=None):
4038 yield mock_scheduler
4139
4240
43- @pytest .fixture
44- def mock_current_user ():
45- """Mock the current user for testing."""
46- with patch ("pydatalab.routes.v0_1.export.current_user" ) as mock_user :
47- mock_person = MagicMock ()
48- mock_person .immutable_id = "test_user_id"
49- mock_user .person = mock_person
50- mock_user .is_authenticated = True
51- yield mock_user
52-
53-
5441class TestExportRoutes :
5542 def test_start_collection_export_success (self , client , sample_collection , mock_scheduler ):
5643 collection_id = sample_collection ["collection_id" ]
5744
58- response = client .post (f"/collections/{ collection_id } /export" )
45+ with patch ("pydatalab.routes.v0_1.export.current_app" ) as mock_app :
46+ mock_app ._get_current_object .return_value = MagicMock ()
5947
60- assert response . status_code == 202
48+ response = client . post ( f"/collections/ { collection_id } /export" )
6149
62- data = json .loads (response .data )
63- assert data ["status" ] == "success"
64- assert "task_id" in data
65- assert "status_url" in data
66- assert data ["status_url" ] == f"/exports/{ data ['task_id' ]} /status"
50+ assert response .status_code == 202
51+
52+ data = json .loads (response .data )
53+ assert data ["status" ] == "success"
54+ assert "task_id" in data
55+ assert "status_url" in data
56+ assert data ["status_url" ] == f"/exports/{ data ['task_id' ]} /status"
6757
68- assert mock_scheduler .add_job .called
58+ assert mock_scheduler .add_job .called
6959
7060 def test_start_collection_export_not_found (self , client ):
7161 response = client .post ("/collections/nonexistent/export" )
72- assert response .status_code == 403
62+ assert response .status_code == 404
7363
7464 data = json .loads (response .data )
7565 assert data ["status" ] == "error"
76- assert "not found" in data ["message" ].lower () or "access denied" in data [ "message" ]. lower ()
66+ assert "not found" in data ["message" ].lower ()
7767
7868 def test_get_export_status_pending (self , client , database ):
79- """Test getting status of pending export task."""
8069 task_id = "test-task-pending"
8170 task = ExportTask (
8271 task_id = task_id ,
@@ -96,7 +85,6 @@ def test_get_export_status_pending(self, client, database):
9685 database .export_tasks .delete_one ({"task_id" : task_id })
9786
9887 def test_get_export_status_ready (self , client , database , tmp_path ):
99- """Test getting status of completed export task."""
10088 task_id = "test-task-ready"
10189 file_path = tmp_path / f"{ task_id } .eln"
10290 file_path .write_text ("test content" )
@@ -122,7 +110,6 @@ def test_get_export_status_ready(self, client, database, tmp_path):
122110 database .export_tasks .delete_one ({"task_id" : task_id })
123111
124112 def test_get_export_status_error (self , client , database ):
125- """Test getting status of failed export task."""
126113 task_id = "test-task-error"
127114 error_message = "Export failed due to test error"
128115
@@ -147,7 +134,6 @@ def test_get_export_status_error(self, client, database):
147134 database .export_tasks .delete_one ({"task_id" : task_id })
148135
149136 def test_get_export_status_not_found (self , client ):
150- """Test getting status of non-existent export task."""
151137 response = client .get ("/exports/nonexistent-task/status" )
152138 assert response .status_code == 404
153139
@@ -156,7 +142,6 @@ def test_get_export_status_not_found(self, client):
156142 assert "not found" in data ["message" ].lower ()
157143
158144 def test_download_export_success (self , client , database , tmp_path ):
159- """Test downloading completed export file."""
160145 task_id = "test-download-task"
161146 collection_id = "test_collection"
162147 file_path = tmp_path / f"{ task_id } .eln"
@@ -179,7 +164,6 @@ def test_download_export_success(self, client, database, tmp_path):
179164 database .export_tasks .delete_one ({"task_id" : task_id })
180165
181166 def test_download_export_not_ready (self , client , database ):
182- """Test downloading export that's not ready."""
183167 task_id = "test-not-ready-task"
184168
185169 task = ExportTask (
@@ -199,7 +183,6 @@ def test_download_export_not_ready(self, client, database):
199183 database .export_tasks .delete_one ({"task_id" : task_id })
200184
201185 def test_download_export_file_missing (self , client , database ):
202- """Test downloading export when file is missing."""
203186 task_id = "test-missing-file-task"
204187
205188 task = ExportTask (
0 commit comments