diff options
Diffstat (limited to 'tests/settings/manager_test.py')
-rw-r--r-- | tests/settings/manager_test.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/settings/manager_test.py b/tests/settings/manager_test.py index 17a228a2..3201ad41 100644 --- a/tests/settings/manager_test.py +++ b/tests/settings/manager_test.py @@ -12,7 +12,9 @@ import textwrap import unittest from alot.settings.manager import SettingsManager -from alot.settings.errors import ConfigError +from alot.settings.errors import ConfigError, NoMatchingAccount + +from .. import utilities class TestSettingsManager(unittest.TestCase): @@ -60,3 +62,52 @@ class TestSettingsManager(unittest.TestCase): manager.reload() actual = manager.get_notmuch_setting('maildir', 'synchronize_flags') self.assertTrue(actual) + + +class TestSettingsManagerGetAccountByAddress(utilities.TestCaseClassCleanup): + """Test the get_account_by_address helper.""" + + @classmethod + def setUpClass(cls): + config = textwrap.dedent("""\ + [accounts] + [[default]] + realname = That Guy + address = that_guy@example.com + sendmail_commnd = /bin/true + + [[other]] + realname = A Dude + address = a_dude@example.com + sendmail_command = /bin/true + """) + + # Allow settings.reload to work by not deleting the file until the end + with tempfile.NamedTemporaryFile(delete=False) as f: + f.write(config) + cls.addClassCleanup(os.unlink, f.name) + + # Replace the actual settings object with our own using mock, but + # ensure it's put back afterwards + cls.manager = SettingsManager(alot_rc=f.name) + + def test_exists_addr(self): + acc = self.manager.get_account_by_address('that_guy@example.com') + self.assertEqual(acc.realname, 'That Guy') + + def test_doesnt_exist_return_default(self): + acc = self.manager.get_account_by_address('doesntexist@example.com', + return_default=True) + self.assertEqual(acc.realname, 'That Guy') + + def test_doesnt_exist_raise(self): + with self.assertRaises(NoMatchingAccount): + self.manager.get_account_by_address('doesntexist@example.com') + + def test_doesnt_exist_no_default(self): + with tempfile.NamedTemporaryFile() as f: + f.write('') + settings = SettingsManager(alot_rc=f.name) + with self.assertRaises(NoMatchingAccount): + settings.get_account_by_address('that_guy@example.com', + return_default=True) |