@@ -428,8 +428,17 @@ def test_files():
428
428
@mock_aws
429
429
def setup_s3_bucket (bucket_name , test_files ):
430
430
mock_s3_client = _create_bucket (bucket_name )
431
+
432
+ last_modfied = datetime .datetime .now ()
431
433
for file in test_files :
432
- mock_s3_client .put_object (Bucket = bucket_name , Key = file , Body = json .dumps ('Test contents' ))
434
+ # use freeze_time to allow uploaded files to have a different LastModified date
435
+ with freeze_time (last_modfied ):
436
+ mock_s3_client .put_object (
437
+ Bucket = bucket_name ,
438
+ Key = file ,
439
+ Body = json .dumps ('Test contents' ),
440
+ )
441
+ last_modfied = last_modfied + datetime .timedelta (seconds = 3 )
433
442
434
443
435
444
def _create_bucket (bucket_name ):
@@ -503,7 +512,7 @@ def test_ingest_with_exception_logs_error_and_reraises_original_exception(self,
503
512
task .ingest ()
504
513
505
514
@mock_aws
506
- def test_ingest_with_empty_s3_bucket_does_not_call_sync_or_delete (self ):
515
+ def test_ingest_with_empty_s3_bucket_does_not_call_sync (self ):
507
516
"""
508
517
Test that the task can handle an empty S3 bucket
509
518
"""
@@ -512,15 +521,13 @@ def test_ingest_with_empty_s3_bucket_does_not_call_sync_or_delete(self):
512
521
with mock .patch .multiple (
513
522
task ,
514
523
sync_file_with_database = mock .DEFAULT ,
515
- delete_file = mock .DEFAULT ,
516
524
):
517
525
task .ingest ()
518
526
task .sync_file_with_database .assert_not_called ()
519
- task .delete_file .assert_not_called ()
520
527
521
528
@mock_aws
522
529
@override_settings (S3_LOCAL_ENDPOINT_URL = None )
523
- def test_ingest_calls_sync_with_correct_files_order (self , test_files ):
530
+ def test_ingest_calls_sync_with_newest_file_order (self , test_files ):
524
531
"""
525
532
Test that the ingest calls the sync with the files in correct order
526
533
"""
@@ -529,32 +536,11 @@ def test_ingest_calls_sync_with_correct_files_order(self, test_files):
529
536
with mock .patch .multiple (
530
537
task ,
531
538
sync_file_with_database = mock .DEFAULT ,
532
- delete_file = mock .DEFAULT ,
533
539
):
534
540
task .ingest ()
535
- task .sync_file_with_database .assert_has_calls (
536
- [mock .call (mock .ANY , file ) for file in test_files ],
537
- )
538
-
539
- @mock_aws
540
- @override_settings (S3_LOCAL_ENDPOINT_URL = None )
541
- def test_ingest_calls_delete_for_all_files (
542
- self ,
543
- test_files ,
544
- ):
545
- """
546
- Test that the ingest calls delete with the files in correct order
547
- """
548
- setup_s3_bucket (BUCKET , test_files )
549
- task = ContactConsentIngestionTask ()
550
- with mock .patch .multiple (
551
- task ,
552
- sync_file_with_database = mock .DEFAULT ,
553
- delete_file = mock .DEFAULT ,
554
- ):
555
- task .ingest ()
556
- task .delete_file .assert_has_calls (
557
- [mock .call (mock .ANY , file ) for file in test_files ],
541
+ task .sync_file_with_database .assert_called_once_with (
542
+ mock .ANY ,
543
+ test_files [- 1 ],
558
544
)
559
545
560
546
@mock_aws
@@ -884,19 +870,3 @@ def test_should_update_contact_with_row_date_newer_than_contact_date_should_retu
884
870
contact ,
885
871
row ,
886
872
)
887
-
888
- @mock_aws
889
- def test_delete_file_removes_file_using_boto3 (self ):
890
- """
891
- Test that the file is deleted from the bucket
892
- """
893
- filename = f'{ CONSENT_PREFIX } file_{ uuid .uuid4 ()} .jsonl'
894
- upload_file_to_s3 (BUCKET , filename , 'test' )
895
- client = boto3 .client ('s3' , REGION )
896
-
897
- ContactConsentIngestionTask ().delete_file (client , filename )
898
- with pytest .raises (client .exceptions .NoSuchKey ):
899
- client .get_object (
900
- Bucket = BUCKET ,
901
- Key = filename ,
902
- )
0 commit comments