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-
2011 @staticmethod
2112 def mock_success_function (_event , _context ):
2213 return "Success"
@@ -27,16 +18,14 @@ def mock_function_raises(_event, _context):
2718
2819 def test_successful_execution (self , mock_logger , mock_firehose_logger ):
2920 # Arrange
30- self .mock_redis_client .hget .return_value = "FLU"
3121 wrapped_function = function_info (self .mock_success_function )
3222 event = {
3323 'headers' : {
3424 'X-Correlation-ID' : 'test_correlation' ,
3525 'X-Request-ID' : 'test_request'
3626 },
3727 'path' : '/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\" }]}]}]}"
28+ 'requestContext' : {'resourcePath' : '/test' }
4029 }
4130
4231 # Act
@@ -56,12 +45,8 @@ def test_successful_execution(self, mock_logger, mock_firehose_logger):
5645 self .assertEqual (logged_info ['X-Request-ID' ], 'test_request' )
5746 self .assertEqual (logged_info ['actual_path' ], '/test' )
5847 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' )
6148
6249 def test_exception_handling (self , mock_logger , mock_firehose_logger ):
63- # Arrange
64- self .mock_redis_client .hget .return_value = "FLU"
6550
6651 #Act
6752 decorated_function_raises = function_info (self .mock_function_raises )
@@ -72,9 +57,7 @@ def test_exception_handling(self, mock_logger, mock_firehose_logger):
7257 'X-Correlation-ID' : 'failed_test_correlation' ,
7358 'X-Request-ID' : 'failed_test_request'
7459 },
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-
60+ 'path' : '/failed_test' , 'requestContext' : {'resourcePath' : '/failed_test' }}
7861 context = {}
7962 decorated_function_raises (event , context )
8063
@@ -91,6 +74,4 @@ def test_exception_handling(self, mock_logger, mock_firehose_logger):
9174 self .assertEqual (logged_info ['X-Request-ID' ], 'failed_test_request' )
9275 self .assertEqual (logged_info ['actual_path' ], '/failed_test' )
9376 self .assertEqual (logged_info ['resource_path' ], '/failed_test' )
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' )
77+ self .assertEqual (logged_info ['error' ], str (ValueError ("Test error" )))
0 commit comments