implement calculating subtotals for MoU Milestones for subsets of bugs
[utils.git] / src / budget_sync / test / test_write_budget_markdown.py
index 16987670289c6c57499cdef8d15e3e463742335b..e26e92abf10c902e7800b8638aa5c3960cc90640 100644 (file)
@@ -1,11 +1,12 @@
 import unittest
 from budget_sync.config import Config
+from budget_sync.ordered_set import OrderedSet
 from budget_sync.test.mock_bug import MockBug
 from budget_sync.test.mock_path import MockFilesystem, MockPath, DIR
 from budget_sync.test.test_mock_path import make_filesystem_and_report_if_error
 from budget_sync.budget_graph import BudgetGraph
 from budget_sync.write_budget_markdown import (
-    write_budget_markdown, DisplayStatus, markdown_escape)
+    write_budget_markdown, DisplayStatus, markdown_escape, markdown_for_person)
 from budget_sync.util import BugStatus
 
 
@@ -70,7 +71,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     cf_total_budget="0",
                     cf_nlnet_milestone=None,
                     cf_payees_list="",
-                    summary="",
+                    summary="summary1",
                     assigned_to="person1@example.com"),
         ], config)
         self.assertEqual([], budget_graph.get_errors())
@@ -121,7 +122,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     cf_total_budget="1000",
                     cf_nlnet_milestone="milestone 1",
                     cf_payees_list="",
-                    summary="",
+                    summary="summary1",
                     assigned_to="person1@example.com"),
             MockBug(bug_id=2,
                     cf_budget_parent=1,
@@ -129,7 +130,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     cf_total_budget="300",
                     cf_nlnet_milestone="milestone 1",
                     cf_payees_list="person2 = 100",
-                    summary="",
+                    summary="summary2",
                     assigned_to="person1@example.com"),
             MockBug(bug_id=3,
                     cf_budget_parent=2,
@@ -137,7 +138,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     cf_total_budget="200",
                     cf_nlnet_milestone="milestone 1",
                     cf_payees_list="person1 = 100",
-                    summary="",
+                    summary="summary3",
                     assigned_to="person1@example.com"),
             MockBug(bug_id=4,
                     cf_budget_parent=3,
@@ -145,7 +146,7 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     cf_total_budget="100",
                     cf_nlnet_milestone="milestone 1",
                     cf_payees_list="person2 = 100",
-                    summary="",
+                    summary="summary4",
                     assigned_to="person1@example.com"),
         ], config)
         self.assertEqual([], budget_graph.get_errors())
@@ -171,10 +172,16 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     b'### milestone 1\n'
                     b'\n'
                     b'* [Bug #3](https://bugzilla.example.com/show_bug.cgi?id=3):\n'
-                    b'  \n'
+                    b'  summary3\n'
                     b'    * €100 which is the total amount\n'
                     b'    * this task is part of MoU Milestone\n'
                     b'      [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2)\n'
+                    b'\n'
+                    b'#### MoU Milestone subtotals for not yet submitted payments\n'
+                    b'\n'
+                    b'* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n'
+                    b'  summary2\n'
+                    b'    * subtotal €100 out of total including subtasks of €300\n'
                 ),
                 '/output_dir/person2.mdwn': (
                     b'<!-- autogenerated by budget-sync -->\n'
@@ -192,16 +199,116 @@ class TestWriteBudgetMarkdown(unittest.TestCase):
                     b'### milestone 1\n'
                     b'\n'
                     b'* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n'
-                    b'  \n'
+                    b'  summary2\n'
                     b'    * &euro;100 which is the total amount\n'
                     b'    * this task is a MoU Milestone\n'
                     b'* [Bug #4](https://bugzilla.example.com/show_bug.cgi?id=4):\n'
-                    b'  \n'
+                    b'  summary4\n'
                     b'    * &euro;100 which is the total amount\n'
                     b'    * this task is part of MoU Milestone\n'
                     b'      [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2)\n'
+                    b'\n'
+                    b'#### MoU Milestone subtotals for not yet submitted payments\n'
+                    b'\n'
+                    b'* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n'
+                    b'  summary2\n'
+                    b'    * subtotal &euro;200 out of total including subtasks of &euro;300\n'
                 ),
             }, filesystem)
+
+    def test_markdown_for_person(self):
+        config = Config.from_str(
+            """
+            bugzilla_url = "https://bugzilla.example.com/"
+            [milestones]
+            "milestone 1" = { canonical_bug_id = 1 }
+            [people."person1"]
+            email = "person1@example.com"
+            full_name = "Person One"
+            [people."person2"]
+            full_name = "Person Two"
+            """)
+        budget_graph = BudgetGraph([
+            MockBug(bug_id=1,
+                    cf_budget_parent=None,
+                    cf_budget="600",
+                    cf_total_budget="1000",
+                    cf_nlnet_milestone="milestone 1",
+                    cf_payees_list="",
+                    summary="summary1",
+                    assigned_to="person1@example.com"),
+            MockBug(bug_id=2,
+                    cf_budget_parent=1,
+                    cf_budget="100",
+                    cf_total_budget="400",
+                    cf_nlnet_milestone="milestone 1",
+                    cf_payees_list="person2 = 100",
+                    summary="summary2",
+                    assigned_to="person1@example.com"),
+            MockBug(bug_id=3,
+                    cf_budget_parent=2,
+                    cf_budget="100",
+                    cf_total_budget="300",
+                    cf_nlnet_milestone="milestone 1",
+                    cf_payees_list="person1 = 100",
+                    summary="summary3",
+                    assigned_to="person1@example.com"),
+            MockBug(bug_id=4,
+                    cf_budget_parent=3,
+                    cf_budget="100",
+                    cf_total_budget="100",
+                    cf_nlnet_milestone="milestone 1",
+                    cf_payees_list="person2 = 100",
+                    summary="summary4",
+                    assigned_to="person1@example.com"),
+            MockBug(bug_id=5,
+                    cf_budget_parent=3,
+                    cf_budget="100",
+                    cf_total_budget="100",
+                    cf_nlnet_milestone="milestone 1",
+                    cf_payees_list="person2 = 100",
+                    summary="summary4",
+                    assigned_to="person1@example.com"),
+        ], config)
+        self.assertEqual([], budget_graph.get_errors())
+        person = config.all_names["person2"]
+        nodes_subset = OrderedSet([budget_graph.nodes[2],
+                                   budget_graph.nodes[3],
+                                   budget_graph.nodes[4]])
+        expected = [
+            '<!-- autogenerated by budget-sync -->\n',
+            '\n',
+            '# Person Two (person2)\n',
+            '\n',
+            '\n',
+            '\n',
+            '# Status Tracking\n',
+            '\n',
+            '\n',
+            '## Payment not yet submitted\n',
+            '\n',
+            '\n',
+            '### milestone 1\n',
+            '\n',
+            '* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n',
+            '  summary2\n',
+            '    * &euro;100 which is the total amount\n',
+            '    * this task is a MoU Milestone\n',
+            '* [Bug #4](https://bugzilla.example.com/show_bug.cgi?id=4):\n',
+            '  summary4\n',
+            '    * &euro;100 which is the total amount\n',
+            '    * this task is part of MoU Milestone\n',
+            '      [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2)\n',
+            '\n',
+            '#### MoU Milestone subtotals for not yet submitted payments\n',
+            '\n',
+            '* [Bug #2](https://bugzilla.example.com/show_bug.cgi?id=2):\n',
+            '  summary2\n',
+            '    * subtotal &euro;200 out of total including subtasks of &euro;400\n',
+        ]
+        self.assertEqual(markdown_for_person(
+            budget_graph, person, nodes_subset).splitlines(keepends=True),
+            expected)
     # TODO: add more test cases