1
1
# docker-compose -f local.yml run --rm django pytest sde_collections/tests/test_workflow_status_triggers.py
2
+
2
3
from unittest .mock import Mock , patch
3
4
4
5
import pytest
9
10
ReindexingStatusChoices ,
10
11
WorkflowStatusChoices ,
11
12
)
12
- from sde_collections .models .delta_url import DeltaUrl , DumpUrl
13
- from sde_collections .tasks import fetch_and_replace_full_text
13
+ from sde_collections .models .delta_url import DumpUrl
14
+ from sde_collections .tasks import (
15
+ fetch_full_text ,
16
+ migrate_dump_to_delta_and_handle_status_transistions ,
17
+ )
14
18
from sde_collections .tests .factories import CollectionFactory , DumpUrlFactory
15
19
16
20
@@ -27,7 +31,7 @@ def test_ready_for_engineering_triggers_config_creation(self, mock_scraper, mock
27
31
28
32
mock_scraper .assert_called_once_with (overwrite = False )
29
33
30
- @patch ("sde_collections.tasks.fetch_and_replace_full_text .delay" )
34
+ @patch ("sde_collections.tasks.fetch_full_text .delay" )
31
35
def test_indexing_finished_triggers_full_text_fetch (self , mock_fetch ):
32
36
"""When status changes to INDEXING_FINISHED_ON_DEV, it should trigger full text fetch"""
33
37
self .collection .workflow_status = WorkflowStatusChoices .INDEXING_FINISHED_ON_DEV
@@ -82,7 +86,7 @@ def setUp(self):
82
86
reindexing_status = ReindexingStatusChoices .REINDEXING_NOT_NEEDED ,
83
87
)
84
88
85
- @patch ("sde_collections.tasks.fetch_and_replace_full_text .delay" )
89
+ @patch ("sde_collections.tasks.fetch_full_text .delay" )
86
90
def test_reindexing_finished_triggers_full_text_fetch (self , mock_fetch ):
87
91
"""When reindexing status changes to FINISHED, it should trigger full text fetch"""
88
92
self .collection .reindexing_status = ReindexingStatusChoices .REINDEXING_FINISHED_ON_DEV
@@ -420,16 +424,21 @@ def test_full_text_import_workflow(self, MockGitHub, MockApi, MockSlackNotificat
420
424
self .collection .workflow_status = WorkflowStatusChoices .INDEXING_FINISHED_ON_DEV
421
425
self .collection .save ()
422
426
423
- # Run the import
424
- fetch_and_replace_full_text (self .collection .id , "lrm_dev" )
427
+ # Step 1: Run fetch_full_text
428
+ with patch ("sde_collections.models.collection.Collection.queue_necessary_classifications" ) as mock_queue :
429
+ fetch_full_text (self .collection .id , "lrm_dev" )
430
+ mock_queue .assert_called_once ()
425
431
426
- # Verify old DumpUrls were cleared
432
+ # Verify old DumpUrls were cleared and new ones were also created
427
433
assert not DumpUrl .objects .filter (id = self .existing_dump .id ).exists ()
434
+ new_dumps = DumpUrl .objects .filter (collection = self .collection )
435
+ assert new_dumps .count () == 2
436
+ assert {dump .url for dump in new_dumps } == {"http://example.com/1" , "http://example.com/2" }
428
437
429
- # Verify new Delta urls were created
430
- new_deltas = DeltaUrl . objects . filter ( collection = self . collection )
431
- assert new_deltas . count () == 2
432
- assert { dump . url for dump in new_deltas } == { "http://example.com/1" , "http://example.com/2" }
438
+ # Step 2: Run migrate_dump_to_delta
439
+ with patch ( "sde_collections.models. collection.Collection.migrate_dump_to_delta" ) as mock_migrate :
440
+ migrate_dump_to_delta_and_handle_status_transistions ( self . collection . id )
441
+ mock_migrate . assert_called_once ()
433
442
434
443
# Verify status updates
435
444
self .collection .refresh_from_db ()
@@ -467,7 +476,7 @@ def test_full_text_fetch_failure_handling(self, MockApi):
467
476
initial_status = self .collection .workflow_status
468
477
469
478
with pytest .raises (Exception ):
470
- fetch_and_replace_full_text (self .collection .id , "lrm_dev" )
479
+ fetch_full_text (self .collection .id , "lrm_dev" )
471
480
472
481
# Verify status wasn't changed on error
473
482
self .collection .refresh_from_db ()
0 commit comments