summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-27 17:27:24 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:28 +0200
commit6d72d76f7753004c84d1a0eed6667b551c11b626 (patch)
treec66c8973389cd4b00a5356b87c5024e49aa7d30f /service/test
parentbf96b1077bdd777400a40fc2fe3acc83552d70de (diff)
Added add mailbox and add message behaviour.
- Add message does not yet mail index
Diffstat (limited to 'service/test')
-rw-r--r--service/test/integration/test_leap_mailstore.py11
-rw-r--r--service/test/support/integration/app_test_client.py10
-rw-r--r--service/test/support/integration/soledad_test_base.py1
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mailstore.py61
4 files changed, 77 insertions, 6 deletions
diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py
index f666b645..dbe0ffb0 100644
--- a/service/test/integration/test_leap_mailstore.py
+++ b/service/test/integration/test_leap_mailstore.py
@@ -26,8 +26,9 @@ from uuid import uuid4
class LeapMailStoreTest(SoledadTestBase):
+ @defer.inlineCallbacks
def setUp(self):
- super(LeapMailStoreTest, self).setUp()
+ yield super(LeapMailStoreTest, self).setUp()
self.adaptor = SoledadMailAdaptor()
self.mbox_uuid = str(uuid4())
self.store = LeapMailStore(self.soledad)
@@ -53,6 +54,14 @@ class LeapMailStoreTest(SoledadTestBase):
self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
@defer.inlineCallbacks
+ def test_add_mail(self):
+ yield self.adaptor.initialize_store(self.soledad)
+ mail = _load_mail_from_file('mbox00000000')
+ mailbox = yield self.store.add_mailbox('INBOX')
+
+ msg = yield self.store.add_mail('INBOX', mail.as_string())
+
+ @defer.inlineCallbacks
def _create_mail_in_soledad(self, mail):
message = self._convert_mail_to_leap_message(mail)
yield self.adaptor.initialize_store(self.soledad)
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index da237284..67cd9df0 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import json
import multiprocessing
+from leap.mail.adaptors.soledad import SoledadMailAdaptor
from mockito import mock
import os
import shutil
@@ -61,7 +62,8 @@ class AppTestClient(object):
PixelatedMail.from_email_address = self.MAIL_ADDRESS
- self.soledad = initialize_soledad(tempdir=soledad_test_folder)
+ self.soledad = yield initialize_soledad(tempdir=soledad_test_folder)
+
self.soledad_querier = self._create_soledad_querier(self.soledad, self.INDEX_KEY)
self.keymanager = mock()
@@ -225,6 +227,7 @@ class AppTestClient(object):
return res
+@defer.inlineCallbacks
def initialize_soledad(tempdir):
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
@@ -257,4 +260,7 @@ def initialize_soledad(tempdir):
cert_file,
defer_encryption=False,
syncable=False)
- return _soledad
+
+ yield SoledadMailAdaptor().initialize_store(_soledad)
+
+ defer.returnValue(_soledad)
diff --git a/service/test/support/integration/soledad_test_base.py b/service/test/support/integration/soledad_test_base.py
index 979b1f96..2ebd6749 100644
--- a/service/test/support/integration/soledad_test_base.py
+++ b/service/test/support/integration/soledad_test_base.py
@@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+from twisted.internet import defer
from twisted.trial import unittest
from test.support.integration.app_test_client import AppTestClient
diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
index 26dd21f0..57dfa292 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
@@ -18,13 +18,13 @@ from uuid import uuid4
from email.parser import Parser
import os
from leap.soledad.common.document import SoledadDocument
-
+from leap.mail.adaptors.soledad_indexes import MAIL_INDEXES
from twisted.internet.defer import FirstError
from twisted.trial.unittest import TestCase
from leap.mail import constants
from twisted.internet import defer
from mockito import mock, when, verify, any
-from leap.mail.adaptors.soledad import SoledadMailAdaptor
+from leap.mail.adaptors.soledad import SoledadMailAdaptor, MailboxWrapper
import pkg_resources
from leap.mail.mail import Message
@@ -171,6 +171,39 @@ class TestLeapMailStore(TestCase):
self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
self.assertEqual('Error illum dignissimos autem eos aspernatur.', mails[1].subject)
+ @defer.inlineCallbacks
+ def test_add_mailbox(self):
+ when(self.soledad).list_indexes().thenReturn(defer.succeed(MAIL_INDEXES)).thenReturn(defer.succeed(MAIL_INDEXES))
+ when(self.soledad).get_from_index('by-type-and-mbox', 'mbox', 'TEST').thenReturn(defer.succeed([]))
+ when(self.soledad).create_doc(any()).thenReturn(defer.succeed(None))
+ self._mock_create_doc(self.mbox_uuid, MailboxWrapper(mbox='TEST'))
+ store = LeapMailStore(self.soledad)
+
+ mbox = yield store.add_mailbox('TEST')
+
+ self.assertIsNotNone(mbox)
+ self.assertEqual(self.mbox_uuid, mbox.doc_id)
+ self.assertEqual('TEST', mbox.mbox)
+
+ @defer.inlineCallbacks
+ def test_add_mail(self):
+ {'multi': False, 'tags': [], 'deleted': False, 'mbox_uuid': '6e8e5a30_b784_43d4_a262_ad81962e5196', 'chash': 'DDE33BCB72DC69A0011CB1D4D4EF5A5F85E703C7C66C551AA51ED50334348A90', 'flags': [], 'seen': False, 'recent': False, 'type': 'flags', 'size': 566}
+ {'multi': False, 'tags': [], 'deleted': False, 'mbox_uuid': '', 'chash': 'DDE33BCB72DC69A0011CB1D4D4EF5A5F85E703C7C66C551AA51ED50334348A90', 'flags': [], 'seen': False, 'recent': False, 'type': 'flags', 'size': 566}
+
+ self._add_create_mail_mocks_to_soledad('mbox00000000')
+
+ mail = self._load_mail_from_file('mbox00000000')
+ when(self.soledad).list_indexes().thenReturn(defer.succeed(MAIL_INDEXES)).thenReturn(defer.succeed(MAIL_INDEXES))
+ mbox = MailboxWrapper(doc_id=self.mbox_uuid, mbox='INBOX')
+ soledad_doc = SoledadDocument(self.mbox_uuid, json=json.dumps(mbox.serialize()))
+ when(self.soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn(defer.succeed([soledad_doc]))
+
+ store = LeapMailStore(self.soledad)
+
+ mbx = yield store.add_mail('INBOX', mail.as_string())
+
+ self.assertEqual(self.mbox_uuid, mbx.doc_id)
+
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)
@@ -188,9 +221,24 @@ class TestLeapMailStore(TestCase):
return mdoc_id, fdoc_id
+ def _add_create_mail_mocks_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()
+
+ mdoc_id = wrapper.mdoc.future_doc_id
+ fdoc_id = wrapper.mdoc.fdoc
+ hdoc_id = wrapper.mdoc.hdoc
+ cdoc_id = wrapper.mdoc.cdocs[0]
+
+ self._mock_create_doc(mdoc_id, wrapper.mdoc)
+ self._mock_create_doc(fdoc_id, wrapper.fdoc)
+ self._mock_create_doc(hdoc_id, wrapper.hdoc)
+ self._mock_create_doc(cdoc_id, wrapper.cdocs[1])
+
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)
+ msg.get_wrapper().set_mbox_uuid(self.mbox_uuid)
return msg
def _mock_soledad_doc(self, doc_id, doc):
@@ -200,6 +248,13 @@ class TestLeapMailStore(TestCase):
self.doc_by_id[doc_id] = soledad_doc
+ def _mock_create_doc(self, doc_id, doc):
+ soledad_doc = SoledadDocument(doc_id, json=json.dumps(doc.serialize()))
+ if doc.future_doc_id:
+ when(self.soledad).create_doc(doc.serialize(), doc_id=doc_id).thenReturn(defer.succeed(soledad_doc))
+ else:
+ when(self.soledad).create_doc(doc.serialize()).thenReturn(defer.succeed(soledad_doc))
+
def _load_mail_from_file(self, mail_file):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
mail_file = os.path.join(mailset_dir, 'new', mail_file)