add assignee to budget_graph.Node
[utils.git] / src / budget_sync / test / test_budget_graph.py
index 60ce3d00b53435bb5252971cf6c82eb1a8d9b660..9a71119c24bb0a90fc37a5ce13928b9517b7d098 100644 (file)
@@ -8,7 +8,7 @@ from budget_sync.budget_graph import (
     BudgetGraphNegativePayeeMoney, BudgetGraphPayeesParseError,
     BudgetGraphPayeesMoneyMismatch, BudgetGraphUnknownMilestone,
     BudgetGraphDuplicatePayeesForTask, BudgetGraphIncorrectRootForMilestone,
-    BudgetGraphUnknownStatus)
+    BudgetGraphUnknownStatus, BudgetGraphUnknownAssignee)
 from budget_sync.money import Money
 from budget_sync.util import BugStatus
 from typing import List, Type
@@ -60,6 +60,12 @@ class TestErrorFormatting(unittest.TestCase):
             "failed to parse status field of bug "
             "#123: unknown status: 'fake status'")
 
+    def test_budget_graph_unknown_assignee(self):
+        self.assertEqual(str(BudgetGraphUnknownAssignee(
+            123, "unknown@example.com")),
+            "Bug #123 is assigned to an unknown person:"
+            " 'unknown@example.com'")
+
     def test_budget_graph_money_mismatch(self):
         self.assertEqual(str(
             BudgetGraphMoneyMismatchForBudgetExcludingSubtasks(
@@ -146,9 +152,11 @@ EXAMPLE_CONFIG = Config.from_str(
     aliases = ["person1_alias1", "alias1"]
     output_markdown_file = "person1.mdwn"
     [people."person2"]
+    email = "person2@example.com"
     aliases = ["person1_alias2", "alias2", "person 2"]
     output_markdown_file = "person2.mdwn"
     [people."person3"]
+    email = "user@example.com"
     output_markdown_file = "person3.mdwn"
     [milestones]
     "milestone 1" = { canonical_bug_id = 1 }
@@ -188,7 +196,8 @@ class TestBudgetGraph(unittest.TestCase):
             "milestone_str='milestone 1', milestone=Milestone(config=..., "
             "identifier='milestone 1', canonical_bug_id=1), "
             "immediate_children=[#2], payments=[], "
-            "status=BugStatus.CONFIRMED), Node(graph=..., id=#2, root=#1, "
+            "status=BugStatus.CONFIRMED, assignee=Person<'person3'>), "
+            "Node(graph=..., id=#2, root=#1, "
             "parent=#1, budget_excluding_subtasks=10, "
             "budget_including_subtasks=10, "
             "fixed_budget_excluding_subtasks=10, "
@@ -196,8 +205,10 @@ class TestBudgetGraph(unittest.TestCase):
             "milestone_str='milestone 1', milestone=Milestone(config=..., "
             "identifier='milestone 1', canonical_bug_id=1), "
             "immediate_children=[], payments=[], "
-            "status=BugStatus.CONFIRMED)], roots=[#1]}")
-        bg = BudgetGraph([MockBug(bug_id=1, status="blah")],
+            "status=BugStatus.CONFIRMED, assignee=Person<'person3'>)], "
+            "roots=[#1]}")
+        bg = BudgetGraph([MockBug(bug_id=1, status="blah",
+                                  assigned_to="unknown@example.com")],
                          EXAMPLE_CONFIG)
         self.assertEqual(
             repr(bg),
@@ -206,7 +217,9 @@ class TestBudgetGraph(unittest.TestCase):
             "fixed_budget_excluding_subtasks=0, "
             "fixed_budget_including_subtasks=0, milestone_str=None, "
             "milestone=None, immediate_children=[], payments=[], "
-            "status=<unknown status: 'blah'>)], roots=[#1]}")
+            "status=<unknown status: 'blah'>, "
+            "assignee=<unknown assignee: 'unknown@example.com'>)], "
+            "roots=[#1]}")
 
     def test_empty(self):
         bg = BudgetGraph([], EXAMPLE_CONFIG)
@@ -1243,6 +1256,21 @@ class TestBudgetGraph(unittest.TestCase):
             self.assertErrorTypesMatches(bg.get_errors(), [])
             self.assertEqual(bg.nodes[1].status, status)
 
+    def test_assignee(self):
+        bg = BudgetGraph([MockBug(bug_id=1, assigned_to="blah")],
+                         EXAMPLE_CONFIG)
+        errors = bg.get_errors()
+        self.assertErrorTypesMatches(errors,
+                                     [BudgetGraphUnknownAssignee])
+        self.assertEqual(errors[0].bug_id, 1)
+        self.assertEqual(errors[0].assignee, "blah")
+        bg = BudgetGraph([MockBug(bug_id=1,
+                                  assigned_to="person2@example.com")],
+                         EXAMPLE_CONFIG)
+        self.assertErrorTypesMatches(bg.get_errors(), [])
+        self.assertEqual(bg.nodes[1].assignee,
+                         EXAMPLE_CONFIG.people["person2"])
+
 
 if __name__ == "__main__":
     unittest.main()