From 9ba07cc943f1d85664b70546404ee26b1313dcee Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Tue, 28 Jul 2015 15:50:38 +0200 Subject: Added delete_mailbox to leap mail store. --- service/pixelated/adapter/mailstore/__init__.py | 3 +++ service/pixelated/adapter/mailstore/leap_mailstore.py | 5 +++++ service/test/integration/test_leap_mailstore.py | 3 ++- service/test/unit/adapter/mailstore/test_leap_mailstore.py | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) (limited to 'service') diff --git a/service/pixelated/adapter/mailstore/__init__.py b/service/pixelated/adapter/mailstore/__init__.py index 6983194d..ab7bfb94 100644 --- a/service/pixelated/adapter/mailstore/__init__.py +++ b/service/pixelated/adapter/mailstore/__init__.py @@ -40,6 +40,9 @@ class MailStore(object): def add_mailbox(self, mailbox_name): pass + def delete_mailbox(self, mailbox_name): + pass + def get_mailbox_mail_ids(self, mailbox_name): pass diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index ee40e03b..70c19bca 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -118,6 +118,11 @@ class LeapMailStore(MailStore): defer.returnValue(mail_ids) + @defer.inlineCallbacks + def delete_mailbox(self, mailbox_name): + mbx_wrapper = yield self._get_or_create_mailbox(mailbox_name) + yield SoledadMailAdaptor().delete_mbox(self.soledad, mbx_wrapper) + @defer.inlineCallbacks def _leap_message_to_leap_mail(self, mail_id, message, include_body): if include_body: diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py index 1cca6903..d4589a1a 100644 --- a/service/test/integration/test_leap_mailstore.py +++ b/service/test/integration/test_leap_mailstore.py @@ -71,11 +71,12 @@ class LeapMailStoreTest(SoledadTestBase): def test_get_mailbox_mail_ids(self): mail = _load_mail_from_file('mbox00000000') yield self.store.add_mailbox('INBOX') - yield self.store.add_mail('INBOX', mail.as_string()) + mail = yield self.store.add_mail('INBOX', mail.as_string()) mails = yield self.store.get_mailbox_mail_ids('INBOX') self.assertEqual(1, len(mails)) + self.assertEqual(mail.mail_id, mails[0]) @defer.inlineCallbacks def _create_mail_in_soledad(self, mail): diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py index f860455d..ec68f3b7 100644 --- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py +++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py @@ -222,6 +222,17 @@ class TestLeapMailStore(TestCase): self.assertEqual(1, len(mail_ids)) self.assertEqual(mdoc_id, mail_ids[0]) + @defer.inlineCallbacks + def test_delete_mailbox(self): + _, mbox_soledad_doc = self._mock_get_mailbox('INBOX') + store = LeapMailStore(self.soledad) + when(self.soledad).delete_doc(mbox_soledad_doc).thenReturn(defer.succeed(None)) + + yield store.delete_mailbox('INBOX') + + verify(self.soledad).delete_doc(self.doc_by_id[mbox_soledad_doc.doc_id]) + # should also verify index is updated + def _assert_message_docs_created(self, expected_message, actual_message): wrapper = expected_message.get_wrapper() @@ -237,6 +248,9 @@ class TestLeapMailStore(TestCase): mbox = MailboxWrapper(doc_id=self.mbox_uuid, mbox=mailbox_name, uuid=self.mbox_uuid) soledad_doc = SoledadDocument(self.mbox_uuid, json=json.dumps(mbox.serialize())) when(self.soledad).get_from_index('by-type-and-mbox', 'mbox', mailbox_name).thenReturn(defer.succeed([soledad_doc])) + self._mock_soledad_doc(self.mbox_uuid, mbox) + + return mbox, soledad_doc def _add_mail_fixture_to_soledad(self, mail_file): mail = self._load_mail_from_file(mail_file) -- cgit v1.2.3