summaryrefslogtreecommitdiff
path: root/tests/settings
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-07-19 11:21:50 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-07-27 12:57:53 -0700
commit084e37cc9b5148d75f88936a353d5249824a4b60 (patch)
treea862d480f0571f827b63a88c6602840b77096e96 /tests/settings
parent2504de648dd6413625387924baaca126eac68016 (diff)
settings/manager: Extend the get_account_by_address with return_default
This new return_default flag (which is an optional and default to False) will try to return the default account if it cannot find an account matching the address hint.
Diffstat (limited to 'tests/settings')
-rw-r--r--tests/settings/manager_test.py53
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)