@@ -245,7 +245,8 @@ def test_lambda_handler_non_root_file(self):
245245 self .assert_no_sqs_message ()
246246 self .assert_no_ack_file (file_details )
247247
248- def test_lambda_handler_extended_attributes_success (self ):
248+ @patch ("elasticache.get_redis_client" )
249+ def test_lambda_handler_extended_attributes_success (self , mock_get_redis_client ):
249250 """
250251 Tests that for an extended attributes file (prefix starts with 'Vaccination_Extended_Attributes'):
251252 * The file is added to the audit table with a status of 'Processed'
@@ -263,7 +264,11 @@ def test_lambda_handler_extended_attributes_success(self):
263264 Body = MOCK_EXTENDED_ATTRIBUTES_FILE_CONTENT ,
264265 )
265266
266- # TODO: rewrite the bucket patches to use moto
267+ # Mock Redis so EA validation passes: supplier present and COVID valid
268+ mock_redis = fakeredis .FakeStrictRedis ()
269+ mock_redis .hget = Mock (side_effect = create_mock_hget ({"X8E5B" : "RAVS" }, {}))
270+ mock_redis .hkeys = Mock (return_value = ["COVID" , * all_vaccine_types_in_this_test_file ])
271+ mock_get_redis_client .return_value = mock_redis
267272
268273 # Patch uuid4 (message id), and prevent external copy issues by simulating move
269274 with (
@@ -312,7 +317,8 @@ def test_lambda_handler_extended_attributes_success(self):
312317 self .assert_no_sqs_message ()
313318 self .assert_no_ack_file (test_cases [0 ])
314319
315- def test_lambda_handler_extended_attributes_failure (self ):
320+ @patch ("elasticache.get_redis_client" )
321+ def test_lambda_handler_extended_attributes_failure (self , mock_get_redis_client ):
316322 """
317323 Tests that for an extended attributes file (prefix starts with 'Vaccination_Extended_Attributes'):
318324 Where the file has not been copied to the destination bucket
@@ -334,7 +340,11 @@ def test_lambda_handler_extended_attributes_failure(self):
334340 Body = MOCK_EXTENDED_ATTRIBUTES_FILE_CONTENT ,
335341 )
336342
337- # TODO: rewrite the bucket patches to use moto
343+ # Mock Redis so EA validation passes: supplier present and COVID valid
344+ mock_redis = fakeredis .FakeStrictRedis ()
345+ mock_redis .hget = Mock (side_effect = create_mock_hget ({"X8E5B" : "RAVS" }, {}))
346+ mock_redis .hkeys = Mock (return_value = ["COVID" , * all_vaccine_types_in_this_test_file ])
347+ mock_get_redis_client .return_value = mock_redis
338348
339349 # Patch uuid4 (message id), and raise an exception instead of moving the file.
340350 with (
@@ -612,7 +622,8 @@ def test_unexpected_bucket_name(self, mock_get_redis_client):
612622 self .assertIn (ravs_record .file_key , args )
613623 self .assertIn ("unknown-bucket" , args )
614624
615- def test_unexpected_bucket_name_with_extended_attributes_file (self ):
625+ @patch ("elasticache.get_redis_client" )
626+ def test_unexpected_bucket_name_with_extended_attributes_file (self , mock_get_redis_client ):
616627 """Tests if extended attributes file is handled when bucket name is incorrect"""
617628 valid_file_key = "Vaccination_Extended_Attributes_V1_5_X8E5B_20000101T00000001.csv"
618629 record = {
@@ -622,6 +633,12 @@ def test_unexpected_bucket_name_with_extended_attributes_file(self):
622633 }
623634 }
624635
636+ # Mock Redis so EA filename validation can succeed (supplier present and COVID is a valid vaccine type)
637+ mock_redis = Mock ()
638+ mock_redis .hget .side_effect = create_mock_hget ({"X8E5B" : "RAVS" }, {})
639+ mock_redis .hkeys .return_value = ["COVID" , * all_vaccine_types_in_this_test_file ]
640+ mock_get_redis_client .return_value = mock_redis
641+
625642 with patch ("file_name_processor.logger" ) as mock_logger :
626643 result = handle_record (record )
627644
0 commit comments