1
- # docker-compose -f local.yml run --rm django pytest sde_collections/tests/test_import_fulltexts.py
2
-
3
1
from unittest .mock import patch
4
2
5
3
import pytest
6
4
from django .db .models .signals import post_save
7
5
6
+ from inference .models .inference import ModelVersion
7
+ from inference .models .inference_choice_fields import ClassificationType
8
8
from sde_collections .models .collection import create_configs_on_status_change
9
9
from 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
+ )
11
14
from sde_collections .tests .factories import CollectionFactory
12
15
13
16
@@ -20,8 +23,19 @@ def disconnect_signals():
20
23
post_save .connect (create_configs_on_status_change , sender = "sde_collections.Collection" )
21
24
22
25
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
+
23
37
@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 ):
25
39
collection = CollectionFactory (config_folder = "test_folder" )
26
40
27
41
mock_batch = [
@@ -37,14 +51,21 @@ def mock_generator():
37
51
), patch ("sde_collections.utils.slack_utils.send_detailed_import_notification" ):
38
52
mock_get_full_texts .return_value = mock_generator ()
39
53
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
41
59
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
43
64
assert DeltaUrl .objects .filter (collection = collection ).count () == 2
44
65
45
66
46
67
@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 ):
48
69
"""Test processing a large number of records with proper pagination and batching."""
49
70
collection = CollectionFactory (config_folder = "test_folder" )
50
71
@@ -68,8 +89,14 @@ def mock_batch_generator():
68
89
), patch ("sde_collections.utils.slack_utils.send_detailed_import_notification" ):
69
90
mock_get_full_texts .return_value = mock_batch_generator ()
70
91
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 )
73
100
74
101
# Verify total number of records
75
102
assert DeltaUrl .objects .filter (collection = collection ).count () == 20000
@@ -82,6 +109,4 @@ def mock_batch_generator():
82
109
83
110
# Verify batch processing worked by checking the success message
84
111
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