@@ -28,7 +28,7 @@ def setUp(self):
2828 # Start moto AWS mocks
2929 self .mock = mock_aws ()
3030 self .mock .start ()
31-
31+
3232 """Set up mock DynamoDB table."""
3333 self .dynamodb_resource = boto3_resource ("dynamodb" , "eu-west-2" )
3434 self .table = self .dynamodb_resource .create_table (
@@ -74,7 +74,7 @@ def tearDown(self):
7474 self .logger_exception_patcher .stop ()
7575 self .logger_info_patcher .stop ()
7676 self .mock_firehose_logger .stop ()
77-
77+
7878 self .mock .stop ()
7979
8080 @staticmethod
@@ -126,34 +126,18 @@ def test_fhir_converter_json_direct_data(self):
126126 json_data = json .dumps (ValuesForTests .json_data )
127127
128128 fhir_converter = Converter (json_data )
129- FlatFile = fhir_converter .run_conversion ()
129+ result = fhir_converter .run_conversion ()
130130
131- flatJSON = json .dumps (FlatFile )
131+ result_str = json .dumps (result )
132132 expected_imms_value = deepcopy (ValuesForTests .expected_imms2 ) # UPDATE is currently the default action-flag
133133 expected_imms = json .dumps (expected_imms_value )
134- self .assertEqual (flatJSON , expected_imms )
134+ self .assertEqual (result_str , expected_imms )
135135
136- errorRecords = fhir_converter .get_error_records ()
136+ error_records = fhir_converter .get_error_records ()
137137
138- self .assertEqual (len (errorRecords ), 0 )
139-
140- def test_fhir_converter_json_direct_data (self ):
141- """it should convert fhir json data to flat json"""
142- json_data = json .dumps (ValuesForTests .json_data )
143-
144- fhir_converter = Converter (json_data )
145- FlatFile = fhir_converter .run_conversion ()
138+ self .assertEqual (len (error_records ), 0 )
146139
147- flatJSON = json .dumps (FlatFile )
148- expected_imms_value = deepcopy (ValuesForTests .expected_imms2 ) # UPDATE is currently the default action-flag
149- expected_imms = json .dumps (expected_imms_value )
150- self .assertEqual (flatJSON , expected_imms )
151-
152- errorRecords = fhir_converter .get_error_records ()
153-
154- self .assertEqual (len (errorRecords ), 0 )
155-
156- def test_fhir_converter_json_error_scenario_reporting_on (self ):
140+ def test_fhir_converter_json_error_scenario (self ):
157141 """it should convert fhir json data to flat json - error scenarios"""
158142 error_test_cases = [ErrorValuesForTests .missing_json , ErrorValuesForTests .json_dob_error ]
159143
@@ -163,42 +147,18 @@ def test_fhir_converter_json_error_scenario_reporting_on(self):
163147 fhir_converter = Converter (json_data )
164148 fhir_converter .run_conversion ()
165149
166- errorRecords = fhir_converter .get_error_records ()
150+ error_records = fhir_converter .get_error_records ()
167151
168152 # Check if bad data creates error records
169- self .assertTrue (len (errorRecords ) > 0 )
170-
171- def test_fhir_converter_json_error_scenario_reporting_off (self ):
172- """it should convert fhir json data to flat json - error scenarios"""
173- error_test_cases = [ErrorValuesForTests .missing_json , ErrorValuesForTests .json_dob_error ]
174-
175- for test_case in error_test_cases :
176- json_data = json .dumps (test_case )
177-
178- fhir_converter = Converter (json_data , report_unexpected_exception = False )
179- fhir_converter .run_conversion ()
180-
181- errorRecords = fhir_converter .get_error_records ()
153+ self .assertTrue (len (error_records ) > 0 )
182154
183- # Check if bad data creates error records
184- self .assertTrue (len (errorRecords ) == 0 )
185-
186- def test_fhir_converter_json_incorrect_data_scenario_reporting_on (self ):
155+ def test_fhir_converter_json_incorrect_data_scenario (self ):
187156 """it should convert fhir json data to flat json - error scenarios"""
188157
189158 with self .assertRaises (ValueError ):
190159 fhir_converter = Converter (None )
191- errorRecords = fhir_converter .get_error_records ()
192- self .assertTrue (len (errorRecords ) > 0 )
193-
194-
195- def test_fhir_converter_json_incorrect_data_scenario_reporting_off (self ):
196- """it should convert fhir json data to flat json - error scenarios"""
197-
198- with self .assertRaises (ValueError ):
199- fhir_converter = Converter (None , report_unexpected_exception = False )
200- errorRecords = fhir_converter .get_error_records ()
201- self .assertTrue (len (errorRecords ) == 0 )
160+ error_records = fhir_converter .get_error_records ()
161+ self .assertTrue (len (error_records ) > 0 )
202162
203163 def test_handler_imms_convert_to_flat_json (self ):
204164 """Test that the Imms field contains the correct flat JSON data for CREATE, UPDATE, and DELETE operations."""
@@ -231,17 +191,13 @@ def test_handler_imms_convert_to_flat_json(self):
231191 response
232192 )
233193
234- result = self .table .scan ()
235- items = result .get ("Items" , [])
236194 self .clear_table ()
237195
238196 def clear_table (self ):
239197 scan = self .table .scan ()
240198 with self .table .batch_writer () as batch :
241199 for item in scan .get ("Items" , []):
242200 batch .delete_item (Key = {"PK" : item ["PK" ]})
243- result = self .table .scan ()
244- items = result .get ("Items" , [])
245201
246202 if __name__ == "__main__" :
247203 unittest .main ()
0 commit comments