From f7c5b841568886be64695a14f341c4c7c58b3fba Mon Sep 17 00:00:00 2001 From: vrs Date: Sat, 8 Dec 2018 23:11:24 +0100 Subject: match addresses against accounts, not address lists fixes #1230, fixes an unfiled bug in clear_my_address() --- tests/account_test.py | 22 ++++++++++++++++------ tests/commands/thread_test.py | 43 ++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/account_test.py b/tests/account_test.py index 9f6287be..9d0ac125 100644 --- a/tests/account_test.py +++ b/tests/account_test.py @@ -32,20 +32,30 @@ class _AccountTestClass(account.Account): class TestAccount(unittest.TestCase): """Tests for the Account class.""" - def test_get_address(self): + def test_matches_address(self): """Tests address without aliases.""" acct = _AccountTestClass(address="foo@example.com") - self.assertListEqual(acct.get_addresses(), ['foo@example.com']) + self.assertTrue(acct.matches_address(u"foo@example.com")) + self.assertFalse(acct.matches_address(u"bar@example.com")) - def test_get_address_with_aliases(self): + def test_matches_address_with_aliases(self): """Tests address with aliases.""" acct = _AccountTestClass(address="foo@example.com", aliases=['bar@example.com']) - self.assertListEqual(acct.get_addresses(), - ['foo@example.com', 'bar@example.com']) + self.assertTrue(acct.matches_address(u"foo@example.com")) + self.assertTrue(acct.matches_address(u"bar@example.com")) + self.assertFalse(acct.matches_address(u"baz@example.com")) + + def test_matches_address_with_regex_aliases(self): + """Tests address with regex aliases.""" + acct = _AccountTestClass(address=u"foo@example.com", + alias_regexp=r'to\+.*@example.com') + self.assertTrue(acct.matches_address(u"to+foo@example.com")) + self.assertFalse(acct.matches_address(u"to@example.com")) + def test_deprecated_encrypt_by_default(self): - """Tests that depreacted values are still accepted.""" + """Tests that deprecated values are still accepted.""" for each in ['true', 'yes', '1']: acct = _AccountTestClass(address='foo@example.com', encrypt_by_default=each) diff --git a/tests/commands/thread_test.py b/tests/commands/thread_test.py index 315273c5..634c35e8 100644 --- a/tests/commands/thread_test.py +++ b/tests/commands/thread_test.py @@ -45,15 +45,27 @@ class Test_ensure_unique_address(unittest.TestCase): self.assertListEqual(actual, expected) +class _AccountTestClass(Account): + """Implements stubs for ABC methods.""" + + def send_mail(self, mail): + pass + + class TestClearMyAddress(unittest.TestCase): - me1 = 'me@example.com' - me2 = 'ME@example.com' - me_named = 'alot team ' - you = 'you@example.com' - named = 'somebody you know ' - imposter = 'alot team ' - mine = [me1, me2] + me1 = u'me@example.com' + me2 = u'ME@example.com' + me3 = u'me+label@example.com' + me4 = u'ME+label@example.com' + me_regex = r'me\+.*@example.com' + me_named = u'alot team ' + you = u'you@example.com' + named = u'somebody you know ' + imposter = u'alot team ' + mine = _AccountTestClass( + address=me1, aliases=[], alias_regexp=me_regex, case_sensitive_username=True) + def test_empty_input_returns_empty_list(self): self.assertListEqual( @@ -62,7 +74,7 @@ class TestClearMyAddress(unittest.TestCase): def test_only_my_emails_result_in_empty_list(self): expected = [] actual = thread.ReplyCommand.clear_my_address( - self.mine, self.mine+[self.me_named]) + self.mine, [self.me1, self.me3, self.me_named]) self.assertListEqual(actual, expected) def test_other_emails_are_untouched(self): @@ -72,22 +84,15 @@ class TestClearMyAddress(unittest.TestCase): self.assertListEqual(actual, expected) def test_case_matters(self): - expected = [self.me1] - mine = [self.me2] - actual = thread.ReplyCommand.clear_my_address(mine, expected) + input_ = [self.me1, self.me2, self.me3, self.me4] + expected = [self.me2, self.me4] + actual = thread.ReplyCommand.clear_my_address(self.mine, input_) self.assertListEqual(actual, expected) def test_same_address_with_different_real_name_is_removed(self): input_ = [self.me_named, self.you] - mine = [self.me1] expected = [self.you] - actual = thread.ReplyCommand.clear_my_address(mine, input_) - self.assertListEqual(actual, expected) - - def test_real_name_is_never_considered(self): - expected = [self.imposter] - mine = 'alot team' - actual = thread.ReplyCommand.clear_my_address(mine, expected) + actual = thread.ReplyCommand.clear_my_address(self.mine, input_) self.assertListEqual(actual, expected) -- cgit v1.2.3