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,14 +27,16 @@ 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' : {
2434 'X-Correlation-ID' : 'test_correlation' ,
2535 'X-Request-ID' : 'test_request'
2636 },
2737 'path' : '/test' ,
28- 'requestContext' : {'resourcePath' : '/test' }
38+ 'requestContext' : {'resourcePath' : '/test' },
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\" }]}]}]}"
2940 }
3041
3142 # Act
@@ -45,8 +56,12 @@ def test_successful_execution(self, mock_logger, mock_firehose_logger):
4556 self .assertEqual (logged_info ['X-Request-ID' ], 'test_request' )
4657 self .assertEqual (logged_info ['actual_path' ], '/test' )
4758 self .assertEqual (logged_info ['resource_path' ], '/test' )
59+ self .assertEqual (logged_info ['local_id' ], '12345^http://test' )
60+ self .assertEqual (logged_info ['vaccine_type' ], 'FLU' )
4861
4962 def test_exception_handling (self , mock_logger , mock_firehose_logger ):
63+ # Arrange
64+ self .mock_redis_client .hget .return_value = "FLU"
5065
5166 #Act
5267 decorated_function_raises = function_info (self .mock_function_raises )
@@ -57,7 +72,9 @@ def test_exception_handling(self, mock_logger, mock_firehose_logger):
5772 'X-Correlation-ID' : 'failed_test_correlation' ,
5873 'X-Request-ID' : 'failed_test_request'
5974 },
60- 'path' : '/failed_test' , 'requestContext' : {'resourcePath' : '/failed_test' }}
75+ 'path' : '/failed_test' , 'requestContext' : {'resourcePath' : '/failed_test' },
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\" }]}]}]}" }
77+
6178 context = {}
6279 decorated_function_raises (event , context )
6380
@@ -74,4 +91,6 @@ def test_exception_handling(self, mock_logger, mock_firehose_logger):
7491 self .assertEqual (logged_info ['X-Request-ID' ], 'failed_test_request' )
7592 self .assertEqual (logged_info ['actual_path' ], '/failed_test' )
7693 self .assertEqual (logged_info ['resource_path' ], '/failed_test' )
77- self .assertEqual (logged_info ['error' ], str (ValueError ("Test error" )))
94+ self .assertEqual (logged_info ['error' ], str (ValueError ("Test error" )))
95+ self .assertEqual (logged_info ['local_id' ], '12345^http://test' )
96+ self .assertEqual (logged_info ['vaccine_type' ], 'FLU' )
0 commit comments