diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-02-06 14:15:56 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-02-06 17:11:05 +0100 |
commit | fbdde65a7f5eab74d2334481cee52ba429910c22 (patch) | |
tree | 736fcada5039b05a729f92695bf8c37c0a67872f | |
parent | af713c2fad332f74c8b37d07e3c58bda979b2a4d (diff) |
db/message: forbid instantiating Message with thread = None
It should always be instantiated from a Thread instance.
-rw-r--r-- | alot/db/message.py | 8 | ||||
-rw-r--r-- | tests/db/test_message.py | 13 |
2 files changed, 11 insertions, 10 deletions
diff --git a/alot/db/message.py b/alot/db/message.py index 8c3392e9..67a16e1e 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -25,14 +25,14 @@ class Message: It it uses a :class:`~alot.db.DBManager` for cached manipulation and lazy lookups. """ - def __init__(self, dbman, msg, thread=None): + def __init__(self, dbman, msg, thread): """ :param dbman: db manager that is used for further lookups :type dbman: alot.db.DBManager :param msg: the wrapped message :type msg: notmuch.database.Message - :param thread: this messages thread (will be looked up later if `None`) - :type thread: :class:`~alot.db.Thread` or `None` + :param thread: this messages thread + :type thread: :class:`~alot.db.Thread` """ self._dbman = dbman self._id = msg.get_message_id() @@ -125,8 +125,6 @@ class Message: def get_thread(self): """returns the :class:`~alot.db.Thread` this msg belongs to""" - if not self._thread: - self._thread = self._dbman.get_thread(self._thread_id) return self._thread def get_datestring(self): diff --git a/tests/db/test_message.py b/tests/db/test_message.py index adc099f6..953d0fe4 100644 --- a/tests/db/test_message.py +++ b/tests/db/test_message.py @@ -65,7 +65,8 @@ class TestMessage(unittest.TestCase): email address is provided. """ msg = message.Message(mock.Mock(), - MockNotmuchMessage({'From': 'user@example.com'})) + MockNotmuchMessage({'From': 'user@example.com'}), + mock.Mock()) self.assertEqual(msg.get_author(), ('', 'user@example.com')) def test_get_author_name_and_email(self): @@ -74,7 +75,8 @@ class TestMessage(unittest.TestCase): """ msg = message.Message( mock.Mock(), - MockNotmuchMessage({'From': '"User Name" <user@example.com>'})) + MockNotmuchMessage({'From': '"User Name" <user@example.com>'}), + mock.Mock()) self.assertEqual(msg.get_author(), ('User Name', 'user@example.com')) def test_get_author_sender(self): @@ -83,7 +85,8 @@ class TestMessage(unittest.TestCase): """ msg = message.Message( mock.Mock(), - MockNotmuchMessage({'Sender': '"User Name" <user@example.com>'})) + MockNotmuchMessage({'Sender': '"User Name" <user@example.com>'}), + mock.Mock()) self.assertEqual(msg.get_author(), ('User Name', 'user@example.com')) def test_get_author_no_name_draft(self): @@ -96,7 +99,7 @@ class TestMessage(unittest.TestCase): with mock.patch('alot.db.message.settings.get_accounts', mock.Mock(return_value=[acc])): msg = message.Message( - mock.Mock(), MockNotmuchMessage(tags=['draft'])) + mock.Mock(), MockNotmuchMessage(tags=['draft']), mock.Mock()) self.assertEqual(msg.get_author(), ('User Name', 'user@example.com')) def test_get_author_no_name(self): @@ -108,5 +111,5 @@ class TestMessage(unittest.TestCase): acc.realname = 'User Name' with mock.patch('alot.db.message.settings.get_accounts', mock.Mock(return_value=[acc])): - msg = message.Message(mock.Mock(), MockNotmuchMessage()) + msg = message.Message(mock.Mock(), MockNotmuchMessage(), mock.Mock()) self.assertEqual(msg.get_author(), ('Unknown', '')) |