summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-28 10:49:52 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:28 +0200
commit37dc1b4d597b6c6d4801cfd41037763f82233ee0 (patch)
treebea7b574dd40c441422558444e1450c983473376 /service
parent6450be6dd2eb2d5a683f81657ed197c930fd9784 (diff)
Added delete mail to mail store.
- Fix for empty mails returned by leap_mail.
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py17
-rw-r--r--service/test/integration/test_leap_mailstore.py10
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mailstore.py27
3 files changed, 42 insertions, 12 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 3c6544df..238fcf86 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -56,7 +56,10 @@ class LeapMailStore(MailStore):
def get_mail(self, mail_id, include_body=False):
try:
message = yield self._fetch_msg_from_soledad(mail_id)
- leap_mail = yield self._leap_message_to_leap_mail(mail_id, message, include_body)
+ if not _is_empty_message(message):
+ leap_mail = yield self._leap_message_to_leap_mail(mail_id, message, include_body)
+ else:
+ leap_mail = None
defer.returnValue(leap_mail)
except AttributeError, e:
@@ -98,7 +101,13 @@ class LeapMailStore(MailStore):
yield message.get_wrapper().create(self.soledad)
# add behavious from insert_mdoc_id from mail.py
- defer.returnValue(message)
+ mail = yield self._leap_message_to_leap_mail(message.get_wrapper().mdoc.doc_id, message, include_body=False)
+ defer.returnValue(mail)
+
+ @defer.inlineCallbacks
+ def delete_mail(self, mail_id):
+ message = yield self._fetch_msg_from_soledad(mail_id)
+ yield message.get_wrapper().delete(self.soledad)
@defer.inlineCallbacks
def _leap_message_to_leap_mail(self, mail_id, message, include_body):
@@ -115,3 +124,7 @@ class LeapMailStore(MailStore):
def _fetch_msg_from_soledad(self, mail_id):
return SoledadMailAdaptor().get_msg_from_mdoc_id(Message, self.soledad, mail_id)
+
+
+def _is_empty_message(message):
+ return (message is None) or (message.get_wrapper().mdoc.doc_id is None)
diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py
index dbe0ffb0..a71df74d 100644
--- a/service/test/integration/test_leap_mailstore.py
+++ b/service/test/integration/test_leap_mailstore.py
@@ -54,13 +54,19 @@ class LeapMailStoreTest(SoledadTestBase):
self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
@defer.inlineCallbacks
- def test_add_mail(self):
+ def test_add_and_remove_mail(self):
yield self.adaptor.initialize_store(self.soledad)
mail = _load_mail_from_file('mbox00000000')
- mailbox = yield self.store.add_mailbox('INBOX')
+ yield self.store.add_mailbox('INBOX')
msg = yield self.store.add_mail('INBOX', mail.as_string())
+ yield self.store.delete_mail(msg.mail_id)
+
+ deleted_msg = yield self.store.get_mail(msg.mail_id)
+
+ self.assertIsNone(deleted_msg)
+
@defer.inlineCallbacks
def _create_mail_in_soledad(self, mail):
message = self._convert_mail_to_leap_message(mail)
diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
index 154bc3e0..3a862da7 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
@@ -195,17 +195,28 @@ class TestLeapMailStore(TestCase):
message = yield store.add_mail('INBOX', mail.as_string())
+ self.assertIsInstance(message, LeapMail)
self._assert_message_docs_created(expected_message, message)
+ @defer.inlineCallbacks
+ def test_delete_mail(self):
+ mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad('mbox00000000')
+
+ store = LeapMailStore(self.soledad)
+
+ 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])
+
def _assert_message_docs_created(self, expected_message, actual_message):
- expected_wrapper = expected_message.get_wrapper()
- actual_wrapper = actual_message.get_wrapper()
-
- verify(self.soledad).create_doc(expected_wrapper.mdoc.serialize(), doc_id=actual_wrapper.mdoc.doc_id)
- verify(self.soledad).create_doc(expected_wrapper.fdoc.serialize(), doc_id=actual_wrapper.fdoc.doc_id)
- verify(self.soledad).create_doc(expected_wrapper.hdoc.serialize(), doc_id=actual_wrapper.hdoc.doc_id)
- for nr, cdoc in expected_wrapper.cdocs.items():
- verify(self.soledad).create_doc(cdoc.serialize(), doc_id=actual_wrapper.cdocs[nr].doc_id)
+ wrapper = expected_message.get_wrapper()
+
+ verify(self.soledad).create_doc(wrapper.mdoc.serialize(), doc_id=actual_message.mail_id)
+ verify(self.soledad).create_doc(wrapper.fdoc.serialize(), doc_id=wrapper.fdoc.future_doc_id)
+ verify(self.soledad).create_doc(wrapper.hdoc.serialize(), doc_id=wrapper.hdoc.future_doc_id)
+ for nr, cdoc in wrapper.cdocs.items():
+ verify(self.soledad).create_doc(cdoc.serialize(), doc_id=wrapper.cdocs[nr].future_doc_id)
def _mock_get_mailbox(self, mailbox_name):
when(self.soledad).list_indexes().thenReturn(defer.succeed(MAIL_INDEXES)).thenReturn(