diff options
author | Kali Kaneko <kali@leap.se> | 2015-02-25 14:08:01 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-03-03 14:22:15 -0400 |
commit | 521aeb49e333da02a428b605e95876d13a772df5 (patch) | |
tree | c0f43b168f6543f63a5bf8da59d6ba52f1621771 | |
parent | f30d72a3b8c6187d5fc29e05c44b03f2d46eeac3 (diff) |
fix delete_msg test
bug: delete_msg was still passing the mbox_name instead of the mbox_uuid
as it should.
-rw-r--r-- | mail/src/leap/mail/mail.py | 2 | ||||
-rw-r--r-- | mail/src/leap/mail/tests/test_mail.py | 21 |
2 files changed, 17 insertions, 6 deletions
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py index f9e99f0..37ab829 100644 --- a/mail/src/leap/mail/mail.py +++ b/mail/src/leap/mail/mail.py @@ -624,7 +624,7 @@ class MessageCollection(object): def delete_mdoc_id(_, wrapper): doc_id = wrapper.mdoc.doc_id return self.mbox_indexer.delete_doc_by_hash( - self.mbox_name, doc_id) + self.mbox_uuid, doc_id) d = wrapper.delete(self.store) d.addCallback(delete_mdoc_id, wrapper) return d diff --git a/mail/src/leap/mail/tests/test_mail.py b/mail/src/leap/mail/tests/test_mail.py index 9bc553f..7009b2f 100644 --- a/mail/src/leap/mail/tests/test_mail.py +++ b/mail/src/leap/mail/tests/test_mail.py @@ -56,17 +56,19 @@ def _get_msg_time(): class CollectionMixin(object): - def get_collection(self, mbox_collection=True): + def get_collection(self, mbox_collection=True, mbox_name=None, + mbox_uuid=None): """ Get a collection for tests. """ adaptor = SoledadMailAdaptor() store = self._soledad adaptor.store = store + if mbox_collection: mbox_indexer = MailboxIndexer(store) - mbox_name = "TestMbox" - mbox_uuid = str(uuid.uuid4()) + mbox_name = mbox_name or "TestMbox" + mbox_uuid = mbox_uuid or str(uuid.uuid4()) else: mbox_indexer = mbox_name = None @@ -209,6 +211,8 @@ class MessageCollectionTestCase(SoledadTestMixin, CollectionMixin): """ Tests for the MessageCollection class. """ + _mbox_uuid = None + def assert_collection_count(self, _, expected): def _assert_count(count): self.assertEqual(count, expected) @@ -222,8 +226,12 @@ class MessageCollectionTestCase(SoledadTestMixin, CollectionMixin): raw = _get_raw_msg() def add_msg_to_collection(collection): + # We keep the uuid in case we need to instantiate the same + # collection afterwards. + self._mbox_uuid = collection.mbox_uuid d = collection.add_msg(raw, date=_get_msg_time()) return d + d = self.get_collection() d.addCallback(add_msg_to_collection) return d @@ -253,7 +261,7 @@ class MessageCollectionTestCase(SoledadTestMixin, CollectionMixin): def _test_add_and_count_msg_cb(self, _): return partial(self.assert_collection_count, expected=1) - def test_coppy_msg(self): + def test_copy_msg(self): # TODO ---- update when implementing messagecopier # interface self.fail("Not Yet Implemented") @@ -263,13 +271,16 @@ class MessageCollectionTestCase(SoledadTestMixin, CollectionMixin): def del_msg(collection): def _delete_it(msg): + self.assertTrue(msg is not None) return collection.delete_msg(msg) d = collection.get_message_by_uid(1) d.addCallback(_delete_it) return d - d.addCallback(lambda _: self.get_collection()) + # We need to instantiate an mbox collection with the same uuid that + # the one in which we inserted the doc. + d.addCallback(lambda _: self.get_collection(mbox_uuid=self._mbox_uuid)) d.addCallback(del_msg) d.addCallback(self._test_delete_msg_cb) return d |