35
35
from datahub .company .test .factories import CompanyFactory , ContactFactory
36
36
from datahub .core .queues .errors import RetryError
37
37
from datahub .core .test_utils import HawkMockJSONResponse
38
+ from datahub .ingest .models import IngestedObject
39
+ from datahub .ingest .test .factories import IngestedObjectFactory
38
40
39
41
40
42
def generate_hawk_response (payload ):
@@ -527,11 +529,35 @@ def test_ingest_with_empty_s3_bucket_does_not_call_sync(self):
527
529
528
530
@mock_aws
529
531
@override_settings (S3_LOCAL_ENDPOINT_URL = None )
530
- def test_ingest_calls_sync_with_newest_file_order (self , test_files ):
532
+ def test_ingest_with_newest_file_key_equal_to_existing_file_key_does_not_call_sync (
533
+ self ,
534
+ test_files ,
535
+ ):
536
+ """
537
+ Test that the task returns when the latest file is equal to an existing ingested file
538
+ """
539
+ setup_s3_bucket (BUCKET , test_files )
540
+ IngestedObjectFactory (object_key = test_files [- 1 ])
541
+ task = ContactConsentIngestionTask ()
542
+ with mock .patch .multiple (
543
+ task ,
544
+ sync_file_with_database = mock .DEFAULT ,
545
+ ):
546
+ task .ingest ()
547
+ task .sync_file_with_database .assert_not_called ()
548
+
549
+ @mock_aws
550
+ @override_settings (S3_LOCAL_ENDPOINT_URL = None )
551
+ def test_ingest_calls_sync_with_newest_file_when_file_is_new (
552
+ self ,
553
+ test_files ,
554
+ ):
531
555
"""
532
- Test that the ingest calls the sync with the files in correct order
556
+ Test that the ingest calls the sync with the latest file when the file key does
557
+ not exist in the list of previously ingested files
533
558
"""
534
559
setup_s3_bucket (BUCKET , test_files )
560
+ IngestedObjectFactory ()
535
561
task = ContactConsentIngestionTask ()
536
562
with mock .patch .multiple (
537
563
task ,
@@ -542,6 +568,7 @@ def test_ingest_calls_sync_with_newest_file_order(self, test_files):
542
568
mock .ANY ,
543
569
test_files [- 1 ],
544
570
)
571
+ assert IngestedObject .objects .filter (object_key = test_files [- 1 ]).exists ()
545
572
546
573
@mock_aws
547
574
def test_sync_file_without_contacts_stops_job_processing (self ):
0 commit comments