Skip to content

Commit

Permalink
ODE-1264 Fix unit tests, replace assertEquals, comment print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Schwartz-Matthew-bah committed May 24, 2019
1 parent 949130f commit 3d231eb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
8 changes: 4 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ def assert_results(testcase, results, expected_fail_count):
for val in res.field_validations:
if not val.valid:
if not result_partition_printed:
print("\n========")
# print("\n========")
result_partition_printed = True

serial_id = res.serial_id
if not serial_id:
serial_id = val.serial_id
print("SerialId: %s, Field: %s, Details: %s\n--------\n%s" % (serial_id , val.field_path, val.details, res.record))

# print("SerialId: %s, Field: %s, Details: %s\n--------\n%s" % (serial_id , val.field_path, val.details, res.record))
fail_count += 1

testcase.assertEquals(expected_fail_count, fail_count, "Expected %s failures, got %s failures." % (expected_fail_count, fail_count))
testcase.assertEqual(expected_fail_count, fail_count, "Expected %s failures, got %s failures." % (expected_fail_count, fail_count))
16 changes: 8 additions & 8 deletions tests/result_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class ResultTest(unittest.TestCase):
def testFieldValidationResult(self):
f = FieldValidationResult()
self.assertTrue(f.valid)
self.assertEquals("", f.details)
self.assertEquals(None, f.field_path)
self.assertEquals('{"Field": null, "Valid": true, "Details": "", "SerialId": null}', json.dumps(f.to_json()))
self.assertEquals('{"Field": null, "Valid": true, "Details": "", "SerialId": null}', str(f))
self.assertEqual("", f.details)
self.assertEqual(None, f.field_path)
self.assertEqual('{"Field": null, "Valid": true, "Details": "", "SerialId": null}', json.dumps(f.to_json()))
self.assertEqual('{"Field": null, "Valid": true, "Details": "", "SerialId": null}', str(f))

def testRecordValidationResult(self):
f = RecordValidationResult("serial_id", [FieldValidationResult()], "record")
self.assertEquals("serial_id", f.serial_id)
self.assertEquals("record", f.record)
self.assertEquals('{"SerialId": "serial_id", "Validations": [{"Field": null, "Valid": true, "Details": "", "SerialId": null}], "Record": "record"}', json.dumps(f.to_json()))
self.assertEquals('{"SerialId": "serial_id", "Validations": [{"Field": null, "Valid": true, "Details": "", "SerialId": null}], "Record": "record"}', str(f))
self.assertEqual("serial_id", f.serial_id)
self.assertEqual("record", f.record)
self.assertEqual('{"SerialId": "serial_id", "Validations": [{"Field": null, "Valid": true, "Details": "", "SerialId": null}], "Record": "record"}', json.dumps(f.to_json()))
self.assertEqual('{"SerialId": "serial_id", "Validations": [{"Field": null, "Valid": true, "Details": "", "SerialId": null}], "Record": "record"}', str(f))
13 changes: 6 additions & 7 deletions tests/sequential_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ def setUp(self):
self.record_list = self.build_happy_path(self.json_seed)

def test_happy_path(self):
print("Testing Happy Path ...")
# print("Testing Happy Path ...")
record_list = self.build_happy_path(self.json_seed)
results = self.seq.perform_sequential_validations(record_list)
assert_results(self, results, 0)

def test_missing_records(self):
print("Testing Missing recordId, serialNumber ...")
# print("Testing Missing recordId, serialNumber ...")
self.record_list.remove(self.record_list[19])
self.record_list.remove(self.record_list[8])
self.record_list.remove(self.record_list[2])
results = self.seq.perform_sequential_validations(self.record_list)
assert_results(self, results, 7)

def test_invalid_bundle_size(self):
print("Testing invalid bundleSize ...")
# print("Testing invalid bundleSize ...")
self.record_list.remove(self.record_list[15])
self.record_list.remove(self.record_list[6])
results = self.seq.perform_sequential_validations(self.record_list)
# Even though we have removed the last record of a full bundle, the validator can't detect if this is a head of a full list or a full list.
# Even though we have removed the last record of a full bundle, the validator can't detect if this is a head of a full list or a full list.
# Therefore, we should get only one validation error
assert_results(self, results, 1)

def test_dup_and_chronological(self):
print("Testing Duplicate recordId and serialNumber and non-chronological odeReceivedAt and recordGeneratedAt ...")
# print("Testing Duplicate recordId and serialNumber and non-chronological odeReceivedAt and recordGeneratedAt ...")
self.record_list[18] = copy.deepcopy(self.record_list[16])
self.record_list[9] = copy.deepcopy(self.record_list[7])
self.record_list[2] = copy.deepcopy(self.record_list[0])
Expand Down Expand Up @@ -89,7 +89,7 @@ def _build_bundle(self, seed_record, count):
bundle.append(cur_record)
cur_record = self._next_record(cur_record)
count -= 1

return bundle

def _next_record(self, cur_record):
Expand All @@ -101,4 +101,3 @@ def _next_record(self, cur_record):
next_record['metadata']['odeReceivedAt'] = received_at.isoformat()
next_record['metadata']['recordGeneratedAt'] = generated_at.isoformat()
return next_record

11 changes: 5 additions & 6 deletions tests/validator_field_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_constructor_fails_no_type(self):
self.assertEqual("Missing required configuration property 'Type' for field a.b.c={}", str(e))

def test_constructor_fails_no_field_config(self):
self.assertEquals('{"Path": "a.b.c", "Type": null, "UpperLimit": null, "LowerLimit": null, "Values": null, "EqualsValue": null, "EarliestTime": null, "LatestTime": null, "AllowEmpty": null}', str(Field("a.b.c")))
self.assertEqual('{"Path": "a.b.c", "Type": null, "UpperLimit": null, "LowerLimit": null, "Values": null, "EqualsValue": null, "EarliestTime": null, "LatestTime": null, "AllowEmpty": null}', str(Field("a.b.c")))

def test_constructor_fails_invalid_earliesttime(self):
input_field_object = {"Type":"timestamp", "EarliestTime":"invalidtimestamp"}
Expand All @@ -34,7 +34,7 @@ def test_constructor_fails_invalid_earliesttime(self):
def test_constructor_succeeds_valid_earliesttime(self):
input_field_object = {"Type":"timestamp", "EarliestTime":"2019-03-14T14:54:21.596Z"}
actual_field = Field("a.b.c", input_field_object)
self.assertEqual("2019-03-14 14:54:21.596000+00:00", str(actual_field.earliest_time))
self.assertEqual("2019-03-14 14:54:21+00:00", str(actual_field.earliest_time))

def test_constructor_fails_invalid_latesttime(self):
input_field_object = {"Type":"timestamp", "LatestTime":"invalidtimestamp"}
Expand All @@ -47,7 +47,7 @@ def test_constructor_fails_invalid_latesttime(self):
def test_constructor_succeeds_valid_latesttime(self):
input_field_object = {"Type":"timestamp", "LatestTime":"2019-03-14T14:54:21.596Z"}
actual_field = Field("a.b.c", input_field_object)
self.assertEqual("2019-03-14 14:54:21.596000+00:00", str(actual_field.latest_time))
self.assertEqual("2019-03-14 14:54:21+00:00", str(actual_field.latest_time))

def test_constructor_succeeds_latesttime_now_keyword(self):
input_field_object = {"Type":"timestamp", "LatestTime":"NOW"}
Expand Down Expand Up @@ -169,6 +169,5 @@ def test_validate_returns_success_timestamp_after_earliest_time(self):
def testFieldSerialization(self):
test_field_object = {"Type":"timestamp", "EarliestTime":"2019-03-14T14:54:20.000Z"}
test_field = Field("a.b.c", test_field_object)
self.assertEquals('{"Path": "a.b.c", "Type": "timestamp", "UpperLimit": null, "LowerLimit": null, "Values": null, "EqualsValue": null, "EarliestTime": "2019-03-14T14:54:20+00:00", "LatestTime": null, "AllowEmpty": false}', json.dumps(test_field.to_json()))
self.assertEquals('{"Path": "a.b.c", "Type": "timestamp", "UpperLimit": null, "LowerLimit": null, "Values": null, "EqualsValue": null, "EarliestTime": "2019-03-14T14:54:20+00:00", "LatestTime": null, "AllowEmpty": false}', str(test_field))

self.assertEqual('{"Path": "a.b.c", "Type": "timestamp", "UpperLimit": null, "LowerLimit": null, "Values": null, "EqualsValue": null, "EarliestTime": "2019-03-14T14:54:20+00:00", "LatestTime": null, "AllowEmpty": false}', json.dumps(test_field.to_json()))
self.assertEqual('{"Path": "a.b.c", "Type": "timestamp", "UpperLimit": null, "LowerLimit": null, "Values": null, "EqualsValue": null, "EarliestTime": "2019-03-14T14:54:20+00:00", "LatestTime": null, "AllowEmpty": false}', str(test_field))

0 comments on commit 3d231eb

Please sign in to comment.