working on implementing write_budget_markdown
[utils.git] / src / budget_sync / test / test_config.py
index 3b203a1b8b292f727a4c31416102bce8f63d069d..6a40c18c30237abb11bd2a9e1c4114120b7d2646 100644 (file)
@@ -78,25 +78,45 @@ class TestConfig(unittest.TestCase):
             [people]
             """,
             "`milestones` table is missing")
+        check_error(
+            """
+            bugzilla_url = ""
+            [people."person1"]
+            """,
+            "`output_markdown_file` field is missing in person entry for "
+            "'person1'")
+        check_error(
+            """
+            bugzilla_url = ""
+            [people."person1"]
+            output_markdown_file = 1
+            """,
+            "`output_markdown_file` field in person entry for 'person1' must "
+            "be a string")
         check(
             """
             bugzilla_url = ""
             [milestones]
             [people."person1"]
             aliases = ["a"]
+            output_markdown_file = "person1.mdwn"
             [people."person2"]
             aliases = ["b"]
+            output_markdown_file = "person2.mdwn"
             """,
             "Config(bugzilla_url='', people={"
             "'person1': Person(config=..., identifier='person1', "
+            "output_markdown_file='person1.mdwn', "
             "aliases={'a'}, email=None), "
             "'person2': Person(config=..., identifier='person2', "
+            "output_markdown_file='person2.mdwn', "
             "aliases={'b'}, email=None)}, milestones={})")
         check_error(
             """
             bugzilla_url = ""
             [people."person1"]
             email = 123
+            output_markdown_file = "person1.mdwn"
             """,
             "`email` field in person entry for 'person1' must be a string")
         check(
@@ -112,15 +132,18 @@ class TestConfig(unittest.TestCase):
             [milestones]
             [people."person1"]
             email = "email@example.com"
+            output_markdown_file = "person1.mdwn"
             """,
             "Config(bugzilla_url='', people={"
             "'person1': Person(config=..., identifier='person1', "
+            "output_markdown_file='person1.mdwn', "
             "aliases=set(), email='email@example.com')}, milestones={})")
         check_error(
             """
             bugzilla_url = ""
             [people."person1"]
             blah = 123
+            output_markdown_file = "person1.mdwn"
             """,
             "unknown field in person entry for 'person1': `blah`")
         check_error(
@@ -128,8 +151,10 @@ class TestConfig(unittest.TestCase):
             bugzilla_url = ""
             [milestones]
             [people."person1"]
+            output_markdown_file = "person1.mdwn"
             [people."person2"]
             aliases = ["person1"]
+            output_markdown_file = "person2.mdwn"
             """,
             "alias is not allowed to be the same as any person's identifier: "
             "in person entry for 'person2': 'person1' is also the identifier "
@@ -139,9 +164,11 @@ class TestConfig(unittest.TestCase):
             bugzilla_url = ""
             [milestones]
             [people."person1"]
+            output_markdown_file = "person1.mdwn"
             aliases = ["a"]
             [people."person2"]
             aliases = ["a"]
+            output_markdown_file = "person2.mdwn"
             """,
             "alias is not allowed to be the same as another person's alias: "
             "in person entry for 'person2': 'a' is also an alias for person "
@@ -205,8 +232,10 @@ class TestConfig(unittest.TestCase):
             [milestones]
             [people."person1"]
             aliases = ["person1_alias1", "alias1"]
+            output_markdown_file = "person1.mdwn"
             [people."person2"]
             aliases = ["person2_alias2", "alias2"]
+            output_markdown_file = "person2.mdwn"
             """)
         person1 = config.people['person1']
         person2 = config.people['person2']
@@ -237,6 +266,35 @@ class TestConfig(unittest.TestCase):
                              2: milestone2,
                          })
 
+    def test_bugzilla_url_stripped(self):
+        c = Config.from_str(
+            """
+            bugzilla_url = "https://bugzilla.example.com/prefix"
+            [people]
+            [milestones]
+            """
+        )
+        self.assertEqual(c.bugzilla_url_stripped,
+                         "https://bugzilla.example.com/prefix")
+        c = Config.from_str(
+            """
+            bugzilla_url = "https://bugzilla.example.com/prefix/"
+            [people]
+            [milestones]
+            """
+        )
+        self.assertEqual(c.bugzilla_url_stripped,
+                         "https://bugzilla.example.com/prefix")
+        c = Config.from_str(
+            """
+            bugzilla_url = "https://bugzilla.example.com/"
+            [people]
+            [milestones]
+            """
+        )
+        self.assertEqual(c.bugzilla_url_stripped,
+                         "https://bugzilla.example.com")
+
     def test_from_file(self):
         def load(text):
             with io.StringIO(text) as file:
@@ -257,11 +315,13 @@ class TestConfig(unittest.TestCase):
             [people."person1"]
             email = "person1@example.com"
             aliases = ["alias1"]
+            output_markdown_file = "person1.mdwn"
             [milestones]
             "Milestone 1" = { canonical_bug_id = 123 }
             """)),
             "Config(bugzilla_url='https://bugzilla.example.com/', "
             "people={'person1': Person(config=..., identifier='person1', "
+            "output_markdown_file='person1.mdwn', "
             "aliases={'alias1'}, email='person1@example.com')}, "
             "milestones={'Milestone 1': Milestone(config=..., "
             "identifier='Milestone 1', canonical_bug_id=123)})")