Skip to content

Commit 49d174d

Browse files
committed
Updated test_workflow_status_triggers
1 parent 0bf0f98 commit 49d174d

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

sde_collections/tests/test_workflow_status_triggers.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# docker-compose -f local.yml run --rm django pytest sde_collections/tests/test_workflow_status_triggers.py
2+
23
from unittest.mock import Mock, patch
34

45
import pytest
@@ -9,8 +10,11 @@
910
ReindexingStatusChoices,
1011
WorkflowStatusChoices,
1112
)
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+
)
1418
from sde_collections.tests.factories import CollectionFactory, DumpUrlFactory
1519

1620

@@ -27,7 +31,7 @@ def test_ready_for_engineering_triggers_config_creation(self, mock_scraper, mock
2731

2832
mock_scraper.assert_called_once_with(overwrite=False)
2933

30-
@patch("sde_collections.tasks.fetch_and_replace_full_text.delay")
34+
@patch("sde_collections.tasks.fetch_full_text.delay")
3135
def test_indexing_finished_triggers_full_text_fetch(self, mock_fetch):
3236
"""When status changes to INDEXING_FINISHED_ON_DEV, it should trigger full text fetch"""
3337
self.collection.workflow_status = WorkflowStatusChoices.INDEXING_FINISHED_ON_DEV
@@ -82,7 +86,7 @@ def setUp(self):
8286
reindexing_status=ReindexingStatusChoices.REINDEXING_NOT_NEEDED,
8387
)
8488

85-
@patch("sde_collections.tasks.fetch_and_replace_full_text.delay")
89+
@patch("sde_collections.tasks.fetch_full_text.delay")
8690
def test_reindexing_finished_triggers_full_text_fetch(self, mock_fetch):
8791
"""When reindexing status changes to FINISHED, it should trigger full text fetch"""
8892
self.collection.reindexing_status = ReindexingStatusChoices.REINDEXING_FINISHED_ON_DEV
@@ -420,16 +424,21 @@ def test_full_text_import_workflow(self, MockGitHub, MockApi, MockSlackNotificat
420424
self.collection.workflow_status = WorkflowStatusChoices.INDEXING_FINISHED_ON_DEV
421425
self.collection.save()
422426

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()
425431

426-
# Verify old DumpUrls were cleared
432+
# Verify old DumpUrls were cleared and new ones were also created
427433
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"}
428437

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()
433442

434443
# Verify status updates
435444
self.collection.refresh_from_db()
@@ -467,7 +476,7 @@ def test_full_text_fetch_failure_handling(self, MockApi):
467476
initial_status = self.collection.workflow_status
468477

469478
with pytest.raises(Exception):
470-
fetch_and_replace_full_text(self.collection.id, "lrm_dev")
479+
fetch_full_text(self.collection.id, "lrm_dev")
471480

472481
# Verify status wasn't changed on error
473482
self.collection.refresh_from_db()

0 commit comments

Comments
 (0)