diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2018-06-26 10:47:59 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2018-07-24 22:05:57 +0100 |
commit | 7f9215bbe1f089d0d9077bf2bd09d16699b492e5 (patch) | |
tree | 32882eef7f54b73116060fbc898ff56127f0a71b /tests/db | |
parent | e4662ce7228082f801a92e40b7d9be732c401cb9 (diff) |
tests for alot.db.manager
This adds a new TestCase for the database manager
and adds a test for saving/reading named query strings to the database.
Diffstat (limited to 'tests/db')
-rw-r--r-- | tests/db/manager_test.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/db/manager_test.py b/tests/db/manager_test.py new file mode 100644 index 00000000..e675aed4 --- /dev/null +++ b/tests/db/manager_test.py @@ -0,0 +1,53 @@ +# Copyright (C) 2018 Patrick Totzke +# This file is released under the GNU GPL, version 3 or a later revision. +# For further details see the COPYING file + +"""Test suite for alot.db.manager module.""" + +import tempfile +import textwrap +import os +import shutil + +from alot.db.manager import DBManager +from alot.settings.const import settings +from notmuch import Database + +from .. import utilities + + +class TestDBManager(utilities.TestCaseClassCleanup): + + @classmethod + def setUpClass(cls): + + # create temporary notmuch config + with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f: + f.write(textwrap.dedent("""\ + [maildir] + synchronize_flags = true + """)) + cls.notmuch_config_path = f.name + cls.addClassCleanup(os.unlink, f.name) + + # define an empty notmuch database in a temporary directory + cls.dbpath = tempfile.mkdtemp() + cls.db = Database(path=cls.dbpath, create=True) + cls.db.close() + cls.manager = DBManager(cls.dbpath) + + # clean up temporary database + cls.addClassCleanup(cls.manager.kill_search_processes) + cls.addClassCleanup(shutil.rmtree, cls.dbpath) + + # let global settings manager read our temporary notmuch config + settings.read_notmuch_config(cls.notmuch_config_path) + + def test_save_named_query(self): + alias = 'key' + querystring = 'query string' + self.manager.save_named_query(alias, querystring) + self.manager.flush() + + named_queries_dict = self.manager.get_named_queries() + self.assertDictEqual(named_queries_dict, {alias: querystring}) |