refactor MockBug in preperation for adding `status` field to `Node`
[utils.git] / src / budget_sync / test / test_mock_bug.py
1 import unittest
2 from budget_sync.test.mock_bug import MockBug
3 from budget_sync.util import BugStatus
4
5
6 class TestBugStatus(unittest.TestCase):
7 def test_values(self):
8 for i in BugStatus:
9 self.assertIs(i, getattr(BugStatus, i.value))
10 self.assertEqual(str(i), i.value)
11 self.assertEqual(repr(i), f"BugStatus.{i.value}")
12
13 def test_cast(self):
14 for i in BugStatus:
15 self.assertEqual(i, BugStatus.cast(i))
16 self.assertEqual(i, BugStatus.cast(str(i)))
17 self.assertEqual(i, BugStatus.cast(str(i), unknown_allowed=True))
18 with self.assertRaises(ValueError):
19 BugStatus.cast("<unknown>")
20 self.assertEqual("<unknown>",
21 BugStatus.cast("<unknown>", unknown_allowed=True))
22
23
24 class TestMockBug(unittest.TestCase):
25 maxDiff = None
26
27 def test_repr(self):
28 bug = MockBug(bug_id=12)
29 self.assertEqual(
30 repr(bug),
31 "MockBug(bug_id=12, cf_budget_parent=None, cf_budget='0', "
32 "cf_total_budget='0', cf_nlnet_milestone='---', "
33 "cf_payees_list='', summary='<default summary>', "
34 "status=BugStatus.CONFIRMED)")
35 bug = MockBug(bug_id=34,
36 cf_budget_parent=1,
37 cf_budget="45",
38 cf_total_budget="23",
39 cf_nlnet_milestone="abc",
40 cf_payees_list="# a",
41 summary="blah blah",
42 status="blah")
43 self.assertEqual(
44 repr(bug),
45 "MockBug(bug_id=34, cf_budget_parent=1, cf_budget='45', "
46 "cf_total_budget='23', cf_nlnet_milestone='abc', "
47 "cf_payees_list='# a', summary='blah blah', status='blah')")
48
49 def test_cf_budget_parent(self):
50 bug = MockBug(bug_id=1, cf_budget_parent=None)
51 with self.assertRaises(AttributeError):
52 bug.cf_budget_parent
53 self.assertIsNone(getattr(bug, "cf_budget_parent", None))
54 bug.cf_budget_parent = 1
55 self.assertEqual(bug.cf_budget_parent, 1)
56 with self.assertRaises(TypeError):
57 bug.cf_budget_parent = "abc"
58 del bug.cf_budget_parent
59 with self.assertRaises(AttributeError):
60 bug.cf_budget_parent
61 with self.assertRaises(AttributeError):
62 del bug.cf_budget_parent
63 with self.assertRaises(AttributeError):
64 bug.cf_budget_parent
65 bug.cf_budget_parent = 5
66 self.assertEqual(bug.cf_budget_parent, 5)
67 bug = MockBug(bug_id=1, cf_budget_parent=2)
68 self.assertEqual(bug.cf_budget_parent, 2)
69
70
71 if __name__ == "__main__":
72 unittest.main()