From 25f024fc5d2a1612e56cb230995b74e5f7495377 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 17 Sep 2020 19:50:10 -0700 Subject: [PATCH] add email to Person.all_names and Config.all_names --- src/budget_sync/config.py | 29 ++++++++++++++---------- src/budget_sync/test/test_config.py | 34 ++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/budget_sync/config.py b/src/budget_sync/config.py index 8a490b5..28b584c 100644 --- a/src/budget_sync/config.py +++ b/src/budget_sync/config.py @@ -28,6 +28,8 @@ class Person: def all_names(self) -> Set[str]: retval = self.aliases.copy() retval.add(self.identifier) + if self.email is not None: + retval.add(self.email) return retval def __eq__(self, other): @@ -84,22 +86,25 @@ class Config: retval = self.people.copy() for person in self.people.values(): - for alias in person.aliases: - other_person = retval.get(alias) - if other_person is not None: - if alias in self.people: + for name in person.all_names: + other_person = retval.get(name) + if other_person is not None and other_person is not person: + alias_or_email = "alias" + if name == person.email: + alias_or_email = "email" + if name in self.people: raise ConfigParseError( - f"alias is not allowed to be the same as any" - f" person's identifier: in person entry for " - f"{person.identifier!r}: {alias!r} is also the " + f"{alias_or_email} is not allowed to be the same " + f"as any person's identifier: in person entry for " + f"{person.identifier!r}: {name!r} is also the " f"identifier for person" f" {other_person.identifier!r}") raise ConfigParseError( - f"alias is not allowed to be the same as another" - f" person's alias: in person entry for " - f"{person.identifier!r}: {alias!r} is also an alias " - f"for person {other_person.identifier!r}") - retval[alias] = person + f"{alias_or_email} is not allowed to be the same as " + f"another person's alias or email: in person entry " + f"for {person.identifier!r}: {name!r} is also an alias" + f" or email for person {other_person.identifier!r}") + retval[name] = person return retval @cached_property diff --git a/src/budget_sync/test/test_config.py b/src/budget_sync/test/test_config.py index 6a40c18..156aa39 100644 --- a/src/budget_sync/test/test_config.py +++ b/src/budget_sync/test/test_config.py @@ -170,9 +170,37 @@ class TestConfig(unittest.TestCase): 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 " - "'person1'") + "alias is not allowed to be the same as another person's alias or " + "email: in person entry for 'person2': 'a' is also an alias or " + "email for person 'person1'") + check_error( + """ + bugzilla_url = "" + [milestones] + [people."person1"] + output_markdown_file = "person1.mdwn" + aliases = ["abc@example.com"] + [people."person2"] + email = "abc@example.com" + output_markdown_file = "person2.mdwn" + """, + "email is not allowed to be the same as another person's alias or " + "email: in person entry for 'person2': 'abc@example.com' is also " + "an alias or email for person 'person1'") + check_error( + """ + bugzilla_url = "" + [milestones] + [people."person2"] + email = "abc@example.com" + output_markdown_file = "person2.mdwn" + [people."person1"] + output_markdown_file = "person1.mdwn" + aliases = ["abc@example.com"] + """, + "alias is not allowed to be the same as another person's alias or " + "email: in person entry for 'person1': 'abc@example.com' is also " + "an alias or email for person 'person2'") check_error( """ bugzilla_url = "" -- 2.30.2