summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py15
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mailstore.py31
2 files changed, 42 insertions, 4 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 7bcd8a6a..60068322 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -93,6 +93,21 @@ class LeapMailStore(MailStore):
defer.returnValue(mailbox)
@defer.inlineCallbacks
+ def get_mailbox_names(self):
+ mbox_map = set((yield self._mailbox_uuid_to_name()).values())
+
+ defer.returnValue(mbox_map.union({'INBOX'}))
+
+ @defer.inlineCallbacks
+ def _mailbox_uuid_to_name(self):
+ map = {}
+ mbox_docs = yield self.soledad.get_from_index('by-type', 'mbox')
+ for doc in mbox_docs:
+ map[doc.doc_id] = doc.content.get('mbox')
+
+ defer.returnValue(map)
+
+ @defer.inlineCallbacks
def add_mail(self, mailbox_name, raw_msg):
mailbox = yield self._get_or_create_mailbox(mailbox_name)
message = SoledadMailAdaptor().get_msg_from_string(Message, raw_msg)
diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
index 92a4b63d..89b19f18 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
@@ -71,6 +71,9 @@ class TestLeapMailStore(TestCase):
self.mbox_uuid = str(uuid4())
self.doc_by_id = {}
self.mbox_uuid_by_name = {}
+ self.mbox_soledad_docs = []
+
+ when(self.soledad).get_from_index('by-type', 'mbox').thenAnswer(lambda: defer.succeed(self.mbox_soledad_docs))
@defer.inlineCallbacks
def test_get_mail_not_exist(self):
@@ -190,6 +193,23 @@ class TestLeapMailStore(TestCase):
# assert index got updated
@defer.inlineCallbacks
+ def test_get_mailbox_names_always_contains_inbox(self):
+ store = LeapMailStore(self.soledad)
+
+ names = yield store.get_mailbox_names()
+
+ self.assertEqual({'INBOX'}, names)
+
+ @defer.inlineCallbacks
+ def test_get_mailbox_names(self):
+ self._mock_get_mailbox('OTHER', create_new_uuid=True)
+ store = LeapMailStore(self.soledad)
+
+ names = yield store.get_mailbox_names()
+
+ self.assertEqual({'INBOX', 'OTHER'}, names)
+
+ @defer.inlineCallbacks
def test_add_mail(self):
expected_message = self._add_create_mail_mocks_to_soledad('mbox00000000')
mail = self._load_mail_from_file('mbox00000000')
@@ -210,8 +230,7 @@ class TestLeapMailStore(TestCase):
yield store.delete_mail(mdoc_id)
- verify(self.soledad).delete_doc(self.doc_by_id[mdoc_id])
- verify(self.soledad).delete_doc(self.doc_by_id[fdoc_id])
+ self._assert_mail_got_deleted(fdoc_id, mdoc_id)
@defer.inlineCallbacks
def test_get_mailbox_mail_ids(self):
@@ -257,8 +276,11 @@ class TestLeapMailStore(TestCase):
mail = yield store.move_mail_to_mailbox(mail_id, 'TRASH')
self._assert_message_docs_created(expected_message, mail, only_mdoc_and_fdoc=True)
- # verify(self.soledad).delete_doc(self.doc_by_id[mail_id])
- # verify(self.soledad).delete_doc(self.doc_by_id[fdoc_id])
+ self._assert_mail_got_deleted(fdoc_id, mail_id)
+
+ def _assert_mail_got_deleted(self, fdoc_id, mail_id):
+ verify(self.soledad).delete_doc(self.doc_by_id[mail_id])
+ verify(self.soledad).delete_doc(self.doc_by_id[fdoc_id])
def _assert_message_docs_created(self, expected_message, actual_message, only_mdoc_and_fdoc=False):
wrapper = expected_message.get_wrapper()
@@ -280,6 +302,7 @@ class TestLeapMailStore(TestCase):
self._mock_soledad_doc(mbox_uuid, mbox)
self.mbox_uuid_by_name[mailbox_name] = mbox_uuid
+ self.mbox_soledad_docs.append(soledad_doc)
return mbox, soledad_doc