diff --git a/AIPscan/Aggregator/tests/test_tasks.py b/AIPscan/Aggregator/tests/test_tasks.py index 858af35d..9aa296c0 100644 --- a/AIPscan/Aggregator/tests/test_tasks.py +++ b/AIPscan/Aggregator/tests/test_tasks.py @@ -462,34 +462,6 @@ def test_store_fetch_job_error_during_workflow_coordinator( index_task_obj = index_tasks.query.filter_by(fetch_job_id=fetch_job.id).first() assert index_task_obj is None - -def test_index_task(app_instance, enable_typesense, mocker): - """Test index task.""" - # Create test fetch job - storage_service = test_helpers.create_test_storage_service() - - fetch_job = test_helpers.create_test_fetch_job( - storage_service_id=storage_service.id - ) - - # Mock call to index initialize function - mocker.patch("AIPscan.typesense_helpers.initialize_index") - - # Create test index tasks object and test index task with fake Celery task ID - task_id = celery.uuid() - test_helpers.create_test_index_tasks(fetch_job.id, task_id) - - # Mock call to finish bulk document creation function - mock_finish_bulk_doc = mocker.patch( - "AIPscan.typesense_helpers.finish_bulk_document_creation" - ) - - # Start index task - index_task.apply((fetch_job.id,), task_id=task_id) - - # Make sure finish bulk document creation function got called - mock_finish_bulk_doc.assert_called() - # Make sure no fetch job errors exist for test fetch job fetch_job_error = FetchJobError.query.filter_by(fetch_job_id=fetch_job.id).first() @@ -530,3 +502,31 @@ class MockPackageListsRequestAsyncResult: assert fetch_job_error is not None assert fetch_job_error.message == "workflow_coordinator: Task error" assert fetch_job_error.fetch_job_id == fetch_job.id + + +def test_index_task(app_instance, enable_typesense, mocker): + """Test index task.""" + # Create test fetch job + storage_service = test_helpers.create_test_storage_service() + + fetch_job = test_helpers.create_test_fetch_job( + storage_service_id=storage_service.id + ) + + # Mock call to index initialize function + mocker.patch("AIPscan.typesense_helpers.initialize_index") + + # Create test index tasks object and test index task with fake Celery task ID + task_id = celery.uuid() + test_helpers.create_test_index_tasks(fetch_job.id, task_id) + + # Mock call to finish bulk document creation function + mock_finish_bulk_doc = mocker.patch( + "AIPscan.typesense_helpers.finish_bulk_document_creation" + ) + + # Start index task + index_task.apply((fetch_job.id,), task_id=task_id) + + # Make sure finish bulk document creation function got called + mock_finish_bulk_doc.assert_called()