Brief
Write positive and negative tests for the v2 contract and explain how CI can block publication if the rule regresses.
The corrected report is due to Imani. Just before release, a supplier-reader code change arrives; Voss insists on publishing anyway. Mara lets you inspect five practice checks: complete E8, missing operator, empty operator, numeric operator, and old version. Explain what change they would catch and why release should wait for a fix. The meeting is urgent in the story, but the exercise has no real time limit.
Your mission
- Classify the five tests as positive or negative.
- Explain the result if the reader stops checking operator_id.
- Describe CI steps between code change and publication.
- Name two claims that all-green tests still cannot support.
How to check your work
- One positive and four negative tests are identified.
- Removing the check fails at least one negative test.
- CI reports failure and publication waits for correction and review.
- Tests prove neither data authenticity nor a real operator's identity.
Course example
import unittest
def accepts(event):
if not isinstance(event, dict) or event.get("schema_version") != 2:
return False
for field in ("event_id", "event_type", "event_at", "vehicle_label",
"operator_id", "source_file"):
if not isinstance(event.get(field), str) or not event[field].strip():
return False
return True
GOOD = {
"schema_version": 2, "event_id": "E8", "event_type": "CHECK",
"event_at": "2026-04-13T11:50:00Z", "vehicle_label": "NOCTIS-01",
"operator_id": "OP-8", "source_file": "supplier-page3.json"
}
class ContractTests(unittest.TestCase):
def test_complete_v2_is_accepted(self):
self.assertTrue(accepts(GOOD))
def test_missing_operator_is_rejected(self):
bad = {key: value for key, value in GOOD.items() if key != "operator_id"}
self.assertFalse(accepts(bad))
def test_empty_operator_is_rejected(self):
self.assertFalse(accepts({**GOOD, "operator_id": " "}))
def test_wrong_operator_type_is_rejected(self):
self.assertFalse(accepts({**GOOD, "operator_id": 17}))
def test_old_version_is_rejected_by_v2_reader(self):
self.assertFalse(accepts({**GOOD, "schema_version": 1}))
suite = unittest.defaultTestLoader.loadTestsFromTestCase(ContractTests)
result = unittest.TextTestRunner(verbosity=1).run(suite)
if not result.wasSuccessful():
raise SystemExit(1)