"""Author: Sandeep Belgavi. Release identity and gate tests.""" import unittest from pattern_14 import Bundle, ReleaseGate class ReleaseTests(unittest.TestCase): def setUp(self): self.base = Bundle('c1', 'p1', 'm1', 't1', 's1') self.new = Bundle('c2', 'p2', 'm1', 't1', 's1') self.g = ReleaseGate(self.base, self.new) def test_prompt_changes_bundle_identity(self): changed = Bundle('c1', 'p2', 'm1', 't1', 's1') self.assertNotEqual(self.base.digest(), changed.digest()) def test_incompatible_schema_rejected(self): with self.assertRaises(ValueError): ReleaseGate(self.base, Bundle('c2','p2','m1','t1','s2')) def test_insufficient_observation_holds(self): self.assertEqual(self.g.assess(100, 0, 19, 0, approved=True), 'hold') self.assertEqual(self.g.active, self.base) def test_bad_quality_rolls_back(self): self.assertEqual(self.g.assess(100, 0, 20, 5, approved=True), 'rollback') def test_requires_approval(self): self.assertEqual(self.g.assess(100, 0, 20, 0), 'await_approval') self.assertEqual(self.g.active, self.base) def test_authorization_violation_overrides_good_average(self): self.g.assess(100, 0, 20, 0, approved=True) self.assertEqual(self.g.assess(100, 0, 20, 0, unauthorized=1), 'rollback') self.assertEqual(self.g.active, self.base) def test_invalid_counts_rejected(self): with self.assertRaises(ValueError): self.g.assess(10, 11, 20, 0) def test_cohort_stable_and_boundaries(self): self.assertEqual(self.g.cohort('a','INC-1'), self.g.cohort('a','INC-1')) self.assertEqual(ReleaseGate(self.base,self.new,0).cohort('a','1'), 'baseline') self.assertEqual(ReleaseGate(self.base,self.new,100).cohort('a','1'), 'candidate') if __name__ == '__main__': unittest.main()