Skip to content

Commit a239677

Browse files
committed
Test Assertions
1 parent 9105a20 commit a239677

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

delta_backend/tests/test_convert_to_flat_json.py

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@
2727
with patch.dict("os.environ", MOCK_ENV_VARS):
2828
from delta import handler, Converter
2929

30-
class TestRecordError(unittest.TestCase):
31-
def test_fields_and_str(self):
32-
err = RecordError(
33-
code=5,
34-
message="Test failed",
35-
details="Something went wrong"
36-
)
37-
38-
# The attributes should round‑trip
39-
self.assertEqual(err.code, 5)
40-
self.assertEqual(err.message, "Test failed")
41-
self.assertEqual(err.details, "Something went wrong")
42-
43-
# __repr__ and __str__ both produce the tuple repr
44-
expected = "(5, 'Test failed', 'Something went wrong')"
45-
self.assertEqual(str(err), expected)
46-
self.assertEqual(repr(err), expected)
47-
48-
def test_default_args(self):
49-
# If you omit arguments they default to None
50-
err = RecordError()
51-
self.assertIsNone(err.code)
52-
self.assertIsNone(err.message)
53-
self.assertIsNone(err.details)
54-
55-
# repr shows three Nones
56-
self.assertEqual(str(err), "(None, None, None)")
30+
# class TestRecordError(unittest.TestCase):
31+
# def test_fields_and_str(self):
32+
# err = RecordError(
33+
# code=5,
34+
# message="Test failed",
35+
# details="Something went wrong"
36+
# )
37+
38+
# # The attributes should round‑trip
39+
# self.assertEqual(err.code, 5)
40+
# self.assertEqual(err.message, "Test failed")
41+
# self.assertEqual(err.details, "Something went wrong")
42+
43+
# # __repr__ and __str__ both produce the tuple repr
44+
# expected = "(5, 'Test failed', 'Something went wrong')"
45+
# self.assertEqual(str(err), expected)
46+
# self.assertEqual(repr(err), expected)
47+
48+
# def test_default_args(self):
49+
# # If you omit arguments they default to None
50+
# err = RecordError()
51+
# self.assertIsNone(err.code)
52+
# self.assertIsNone(err.message)
53+
# self.assertIsNone(err.details)
54+
55+
# # repr shows three Nones
56+
# self.assertEqual(str(err), "(None, None, None)")
5757

5858
@patch.dict("os.environ", MOCK_ENV_VARS, clear=True)
5959
@mock_dynamodb
@@ -99,9 +99,13 @@ def setUp(self):
9999
self.logger_exception_patcher = patch("logging.Logger.exception")
100100
self.mock_logger_exception = self.logger_exception_patcher.start()
101101

102+
self.firehose_logger_patcher = patch("delta.firehose_logger")
103+
self.mock_firehose_logger = self.firehose_logger_patcher.start()
104+
102105
def tearDown(self):
103106
self.logger_exception_patcher.stop()
104107
self.logger_info_patcher.stop()
108+
self.mock_firehose_logger.stop()
105109

106110
@staticmethod
107111
def get_event(event_name="INSERT", operation="operation", supplier="EMIS"):
@@ -140,8 +144,6 @@ def test_fhir_converter_json_direct_data(self):
140144
"""it should convert fhir json data to flat json"""
141145
json_data = json.dumps(ValuesForTests.json_data)
142146

143-
start = time.time()
144-
145147
FHIRConverter = Converter(json_data)
146148
FlatFile = FHIRConverter.runConversion(ValuesForTests.json_data, False, True)
147149

@@ -151,15 +153,8 @@ def test_fhir_converter_json_direct_data(self):
151153
self.assertEqual(flatJSON, expected_imms)
152154

153155
errorRecords = FHIRConverter.getErrorRecords()
154-
# print(flatJSON)
155-
156-
if len(errorRecords) > 0:
157-
print("Converted With Errors")
158-
else:
159-
print("Converted Successfully")
160-
161-
end = time.time()
162-
print(end - start)
156+
157+
self.assertEqual(len(errorRecords), 0)
163158

164159
def test_fhir_converter_json_error_scenario(self):
165160
"""it should convert fhir json data to flat json - error scenarios"""
@@ -168,23 +163,13 @@ def test_fhir_converter_json_error_scenario(self):
168163
for test_case in error_test_cases:
169164
json_data = json.dumps(test_case)
170165

171-
start = time.time()
172-
173166
FHIRConverter = Converter(json_data)
174-
FlatFile = FHIRConverter.runConversion(ValuesForTests.json_data, False, True)
175-
176-
flatJSON = json.dumps(FlatFile)
167+
FHIRConverter.runConversion(ValuesForTests.json_data, False, True)
177168

178169
errorRecords = FHIRConverter.getErrorRecords()
179170

180-
if len(errorRecords) > 0:
181-
print("Converted With Errors")
182-
print(f"Error records -error scenario {errorRecords}")
183-
else:
184-
print("Converted Successfully")
185-
186-
end = time.time()
187-
print(end - start)
171+
# Check if bad data creates error records
172+
self.assertEqual(len(errorRecords) > 0)
188173

189174
def test_handler_imms_convert_to_flat_json(self):
190175
"""Test that the Imms field contains the correct flat JSON data for CREATE, UPDATE, and DELETE operations."""

0 commit comments

Comments
 (0)