summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-24 10:49:35 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:28 +0200
commit46e891c2d827d267e2daef45140eedf5d7d1261b (patch)
tree06581a3979bd666b7a9f3427e031bc3f69ce09e6
parent23f838490f8485a5b5011d77612e6b948a823f73 (diff)
Refactored test_leap_mailstore.py.
-rw-r--r--service/test/integration/test_leap_mailstore.py8
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mailstore.py45
2 files changed, 31 insertions, 22 deletions
diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py
index 612e2082..2b9639e3 100644
--- a/service/test/integration/test_leap_mailstore.py
+++ b/service/test/integration/test_leap_mailstore.py
@@ -45,13 +45,17 @@ class LeapMailStoreTest(SoledadTestBase):
@defer.inlineCallbacks
def _create_mail_in_soledad(self, mail):
- message = self.adaptor.get_msg_from_string(Message, mail.as_string())
- message.get_wrapper().set_mbox_uuid(self.mbox_uuid)
+ message = self._convert_mail_to_leap_message(mail)
yield self.adaptor.initialize_store(self.soledad)
yield self.adaptor.create_msg(self.soledad, message)
defer.returnValue(message.get_wrapper().mdoc.doc_id)
+ def _convert_mail_to_leap_message(self, mail):
+ message = self.adaptor.get_msg_from_string(Message, mail.as_string())
+ message.get_wrapper().set_mbox_uuid(self.mbox_uuid)
+ return message
+
def _load_mail_from_file(mail_file):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
index aa4e62fd..36458d1e 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
@@ -67,6 +67,7 @@ class TestLeapMailStore(TestCase):
def setUp(self):
self.soledad = mock()
self.mbox_uuid = str(uuid4())
+ self.doc_by_id = {}
@defer.inlineCallbacks
def test_get_mail_not_exist(self):
@@ -140,8 +141,9 @@ class TestLeapMailStore(TestCase):
@defer.inlineCallbacks
def test_update_mail(self):
- mdoc_id, flags_doc = self._add_mail_fixture_to_soledad('mbox00000000')
- when(self.soledad).put_doc(flags_doc).thenReturn(defer.succeed(None))
+ mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad('mbox00000000')
+ soledad_fdoc = self.doc_by_id[fdoc_id]
+ when(self.soledad).put_doc(soledad_fdoc).thenReturn(defer.succeed(None))
store = LeapMailStore(self.soledad)
@@ -151,34 +153,37 @@ class TestLeapMailStore(TestCase):
yield store.update_mail(mail)
- verify(self.soledad).put_doc(flags_doc)
- self.assertTrue('new_tag' in flags_doc.content['tags'])
+ verify(self.soledad).put_doc(soledad_fdoc)
+ self.assertTrue('new_tag' in soledad_fdoc.content['tags'])
def _add_mail_fixture_to_soledad(self, mail_file):
mail = self._load_mail_from_file(mail_file)
+ msg = self._convert_mail_to_leap_message(mail)
+ wrapper = msg.get_wrapper()
- msg = SoledadMailAdaptor().get_msg_from_string(Message, mail.as_string())
-
- msg.get_wrapper().mdoc.set_mbox_uuid(self.mbox_uuid)
+ mdoc_id = wrapper.mdoc.future_doc_id
+ fdoc_id = wrapper.mdoc.fdoc
+ hdoc_id = wrapper.mdoc.hdoc
+ cdoc_id = wrapper.mdoc.cdocs[0]
- mdoc_id = msg.get_wrapper().mdoc.future_doc_id
- fdoc_id = msg.get_wrapper().mdoc.fdoc
- hdoc_id = msg.get_wrapper().mdoc.hdoc
- cdoc_id = msg.get_wrapper().mdoc.cdocs[0]
+ self._mock_soledad_doc(mdoc_id, wrapper.mdoc)
+ self._mock_soledad_doc(fdoc_id, wrapper.fdoc)
+ self._mock_soledad_doc(hdoc_id, wrapper.hdoc)
+ self._mock_soledad_doc(cdoc_id, wrapper.cdocs[1])
- when(self.soledad).get_doc(mdoc_id).thenReturn(defer.succeed(msg.get_wrapper().mdoc.serialize()))
+ return mdoc_id, fdoc_id
- flags_doc = SoledadDocument(doc_id=fdoc_id, json=json.dumps(msg.get_wrapper().fdoc.serialize()))
- when(self.soledad).get_doc(fdoc_id).thenReturn(defer.succeed(flags_doc))
-
- # when(self.soledad).get_doc(fdoc_id).thenReturn(defer.succeed(msg.get_wrapper().fdoc.serialize()))
- when(self.soledad).get_doc(hdoc_id).thenReturn(defer.succeed(msg.get_wrapper().hdoc.serialize()))
+ def _convert_mail_to_leap_message(self, mail):
+ msg = SoledadMailAdaptor().get_msg_from_string(Message, mail.as_string())
+ msg.get_wrapper().mdoc.set_mbox_uuid(self.mbox_uuid)
+ return msg
- content = SoledadDocument(doc_id=cdoc_id, json=json.dumps(msg.get_wrapper().cdocs[1].serialize()))
+ def _mock_soledad_doc(self, doc_id, doc):
+ soledad_doc = SoledadDocument(doc_id, json=json.dumps(doc.serialize()))
- when(self.soledad).get_doc(cdoc_id).thenReturn(defer.succeed(content))
+ when(self.soledad).get_doc(doc_id).thenReturn(defer.succeed(soledad_doc))
- return mdoc_id, flags_doc
+ self.doc_by_id[doc_id] = soledad_doc
def _load_mail_from_file(self, mail_file):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')