1- # docker-compose -f local.yml run --rm django pytest sde_collections/tests/test_import_fulltexts.py
2-
31from unittest .mock import patch
42
53import pytest
64from django .db .models .signals import post_save
75
6+ from inference .models .inference import ModelVersion
7+ from inference .models .inference_choice_fields import ClassificationType
88from sde_collections .models .collection import create_configs_on_status_change
99from sde_collections .models .delta_url import DeltaUrl , DumpUrl
10- from sde_collections .tasks import fetch_and_replace_full_text
10+ from sde_collections .tasks import (
11+ fetch_full_text ,
12+ migrate_dump_to_delta_and_handle_status_transistions ,
13+ )
1114from sde_collections .tests .factories import CollectionFactory
1215
1316
@@ -20,8 +23,19 @@ def disconnect_signals():
2023 post_save .connect (create_configs_on_status_change , sender = "sde_collections.Collection" )
2124
2225
26+ @pytest .fixture
27+ def model_version ():
28+ """Create a model version for testing"""
29+ return ModelVersion .objects .create (
30+ api_identifier = "test_model" ,
31+ description = "Test model version" ,
32+ classification_type = ClassificationType .TDAMM ,
33+ is_active = True ,
34+ )
35+
36+
2337@pytest .mark .django_db
24- def test_fetch_and_replace_full_text (disconnect_signals ):
38+ def test_fetch_and_replace_full_text (disconnect_signals , model_version ):
2539 collection = CollectionFactory (config_folder = "test_folder" )
2640
2741 mock_batch = [
@@ -37,14 +51,21 @@ def mock_generator():
3751 ), patch ("sde_collections.utils.slack_utils.send_detailed_import_notification" ):
3852 mock_get_full_texts .return_value = mock_generator ()
3953
40- fetch_and_replace_full_text (collection .id , "lrm_dev" )
54+ # First fetch the full text
55+ fetch_full_text (collection .id , "lrm_dev" )
56+
57+ # Verify DumpUrls were created
58+ assert DumpUrl .objects .filter (collection = collection ).count () == 2
4159
42- assert DumpUrl .objects .filter (collection = collection ).count () == 0
60+ # Then migrate the data
61+ migrate_dump_to_delta_and_handle_status_transistions (collection .id )
62+
63+ # Verify DeltaUrls were created
4364 assert DeltaUrl .objects .filter (collection = collection ).count () == 2
4465
4566
4667@pytest .mark .django_db
47- def test_fetch_and_replace_full_text_large_dataset (disconnect_signals ):
68+ def test_fetch_and_replace_full_text_large_dataset (disconnect_signals , model_version ):
4869 """Test processing a large number of records with proper pagination and batching."""
4970 collection = CollectionFactory (config_folder = "test_folder" )
5071
@@ -68,8 +89,14 @@ def mock_batch_generator():
6889 ), patch ("sde_collections.utils.slack_utils.send_detailed_import_notification" ):
6990 mock_get_full_texts .return_value = mock_batch_generator ()
7091
71- # Execute the task
72- result = fetch_and_replace_full_text (collection .id , "lrm_dev" )
92+ # Execute the fetch task
93+ result = fetch_full_text (collection .id , "lrm_dev" )
94+
95+ # Verify DumpUrls were created
96+ assert DumpUrl .objects .filter (collection = collection ).count () == 20000
97+
98+ # Execute the migration task
99+ migrate_result = migrate_dump_to_delta_and_handle_status_transistions (collection .id )
73100
74101 # Verify total number of records
75102 assert DeltaUrl .objects .filter (collection = collection ).count () == 20000
@@ -82,6 +109,4 @@ def mock_batch_generator():
82109
83110 # Verify batch processing worked by checking the success message
84111 assert "Successfully processed 20000 records" in result
85-
86- # Verify no DumpUrls remain (should all be migrated to DeltaUrls)
87- assert DumpUrl .objects .filter (collection = collection ).count () == 0
112+ assert "Successfully migrated DumpUrls to DeltaUrls" in migrate_result
0 commit comments