88@patch ('log_structure.logger' )
99class TestFunctionInfoWrapper (unittest .TestCase ):
1010
11+ def setUp (self ):
12+ super ().setUp ()
13+ self .redis_patcher = patch ("models.utils.validation_utils.redis_client" )
14+ self .mock_redis_client = self .redis_patcher .start ()
15+
16+ def tearDown (self ):
17+ self .redis_patcher .stop ()
18+ super ().tearDown ()
19+
1120 @staticmethod
1221 def mock_success_function (_event , _context ):
1322 return "Success"
@@ -18,6 +27,7 @@ def mock_function_raises(_event, _context):
1827
1928 def test_successful_execution (self , mock_logger , mock_firehose_logger ):
2029 # Arrange
30+ self .mock_redis_client .hget .return_value = "FLU"
2131 wrapped_function = function_info (self .mock_success_function )
2232 event = {
2333 'headers' : {
@@ -26,7 +36,7 @@ def test_successful_execution(self, mock_logger, mock_firehose_logger):
2636 },
2737 'path' : '/test' ,
2838 'requestContext' : {'resourcePath' : '/test' },
29- 'body' : "{\" identifier\" : [{\" system\" : \" http://test\" , \" value\" : \" 12345\" }]}"
39+ 'body' : "{\" identifier\" : [{\" system\" : \" http://test\" , \" value\" : \" 12345\" }], \" protocolApplied \" : [{ \" targetDisease \" : [{ \" coding \" : [{ \" system \" : \" http://snomed.info/sct \" , \" code \" : \" 840539006 \" , \" display \" : \" Disease caused by severe acute respiratory syndrome coronavirus 2 \" }]}]}] }"
3040 }
3141
3242 # Act
@@ -47,8 +57,11 @@ def test_successful_execution(self, mock_logger, mock_firehose_logger):
4757 self .assertEqual (logged_info ['actual_path' ], '/test' )
4858 self .assertEqual (logged_info ['resource_path' ], '/test' )
4959 self .assertEqual (logged_info ['local_id' ], '12345^http://test' )
60+ self .assertEqual (logged_info ['vaccine_type' ], 'FLU' )
5061
5162 def test_exception_handling (self , mock_logger , mock_firehose_logger ):
63+ # Arrange
64+ self .mock_redis_client .hget .return_value = "FLU"
5265
5366 #Act
5467 decorated_function_raises = function_info (self .mock_function_raises )
@@ -60,7 +73,7 @@ def test_exception_handling(self, mock_logger, mock_firehose_logger):
6073 'X-Request-ID' : 'failed_test_request'
6174 },
6275 'path' : '/failed_test' , 'requestContext' : {'resourcePath' : '/failed_test' },
63- 'body' : "{\" identifier\" : [{\" system\" : \" http://test\" , \" value\" : \" 12345\" }]}" }
76+ 'body' : "{\" identifier\" : [{\" system\" : \" http://test\" , \" value\" : \" 12345\" }], \" protocolApplied \" : [{ \" targetDisease \" : [{ \" coding \" : [{ \" system \" : \" http://snomed.info/sct \" , \" code \" : \" 840539006 \" , \" display \" : \" Disease caused by severe acute respiratory syndrome coronavirus 2 \" }]}]}] }" }
6477
6578 context = {}
6679 decorated_function_raises (event , context )
@@ -80,3 +93,4 @@ def test_exception_handling(self, mock_logger, mock_firehose_logger):
8093 self .assertEqual (logged_info ['resource_path' ], '/failed_test' )
8194 self .assertEqual (logged_info ['error' ], str (ValueError ("Test error" )))
8295 self .assertEqual (logged_info ['local_id' ], '12345^http://test' )
96+ self .assertEqual (logged_info ['vaccine_type' ], 'FLU' )
0 commit comments