summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-17 11:15:00 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:24 +0200
commit953fa104ab56d38d65b21f9d2108a95f62a0e8b6 (patch)
tree8f2168b709b5ae54ec7aaff8cbac348d516d36f5
parent1ee61a27b1a11f6e60dfd34fb72d3c63f05e7e24 (diff)
Fixing integration tests.
-rw-r--r--service/pixelated/adapter/services/mailbox.py9
-rw-r--r--service/pixelated/adapter/soledad/soledad_facade_mixin.py10
-rw-r--r--service/pixelated/adapter/soledad/soledad_writer_mixin.py13
-rw-r--r--service/test/integration/test_delete_mail.py5
-rw-r--r--service/test/support/integration/app_test_client.py23
5 files changed, 41 insertions, 19 deletions
diff --git a/service/pixelated/adapter/services/mailbox.py b/service/pixelated/adapter/services/mailbox.py
index a4029d78..a083e8a6 100644
--- a/service/pixelated/adapter/services/mailbox.py
+++ b/service/pixelated/adapter/services/mailbox.py
@@ -14,6 +14,8 @@
# 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
+
class Mailbox(object):
@@ -30,10 +32,13 @@ class Mailbox(object):
def mail(self, mail_id):
return self.querier.mail(mail_id)
+ @defer.inlineCallbacks
def add(self, mail):
- added_mail = self.querier.create_mail(mail, self.mailbox_name)
+ added_mail = yield self.querier.create_mail(mail, self.mailbox_name)
+
+ import pdb; pdb.set_trace()
self.search_engine.index_mail(added_mail)
- return added_mail
+ defer.returnValue(added_mail)
def remove(self, ident):
mail = self.querier.mail(ident)
diff --git a/service/pixelated/adapter/soledad/soledad_facade_mixin.py b/service/pixelated/adapter/soledad/soledad_facade_mixin.py
index b58bb02f..e5dbb458 100644
--- a/service/pixelated/adapter/soledad/soledad_facade_mixin.py
+++ b/service/pixelated/adapter/soledad/soledad_facade_mixin.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from twisted.internet import defer
+from leap.mail.mailbox_indexer import MailboxIndexer
class SoledadDbFacadeMixin(object):
@@ -72,10 +73,15 @@ class SoledadDbFacadeMixin(object):
def get_mbox(self, mbox):
return self.soledad.get_from_index('by-type-and-mbox', 'mbox', mbox) if mbox else []
+ @defer.inlineCallbacks
def get_lastuid(self, mbox):
if isinstance(mbox, str):
- mbox = self.get_mbox(mbox)[0]
- return mbox.content['lastuid']
+ mbox = (yield defer.maybeDeferred(self.get_mbox(mbox)))[0]
+
+ indexer = MailboxIndexer(self.soledad)
+ last_uuid = yield indexer.get_last_uid(mbox.content['uuid'])
+
+ defer.returnValue(last_uuid)
def get_search_index_masterkey(self):
return self.soledad.get_from_index('by-type', 'index_key')
diff --git a/service/pixelated/adapter/soledad/soledad_writer_mixin.py b/service/pixelated/adapter/soledad/soledad_writer_mixin.py
index ed18c0d0..262351cb 100644
--- a/service/pixelated/adapter/soledad/soledad_writer_mixin.py
+++ b/service/pixelated/adapter/soledad/soledad_writer_mixin.py
@@ -33,15 +33,18 @@ class SoledadWriterMixin(SoledadDbFacadeMixin, object):
def save_mail(self, mail):
self.put_doc(mail.fdoc)
+ @defer.inlineCallbacks
def create_mail(self, mail, mailbox_name):
- mbox_doc = self.get_mbox(mailbox_name)[0]
- uid = self.get_lastuid(mbox_doc)
+ mbox_doc = (yield self.get_mbox(mailbox_name))[0]
+ uid = 1 + (yield self.get_lastuid(mbox_doc))
+
self.create_docs(mail.get_for_save(next_uid=uid, mailbox=mailbox_name))
- mbox_doc.content['lastuid'] = uid + 1
- self.put_doc(mbox_doc)
+ # FIXME need to update meta message (mdoc)
+ # mbox_doc.content['lastuid'] = uid + 1
+ # self.put_doc(mbox_doc)
- return self.mail(mail.ident)
+ defer.returnValue((yield self.mail(mail.ident)))
def remove_mail(self, mail):
# FIX-ME: Must go through all the part_map phash to delete all the cdocs
diff --git a/service/test/integration/test_delete_mail.py b/service/test/integration/test_delete_mail.py
index 987cf307..18bae44a 100644
--- a/service/test/integration/test_delete_mail.py
+++ b/service/test/integration/test_delete_mail.py
@@ -13,7 +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 test.support.integration import SoledadTestBase, MailBuilder
@@ -33,8 +33,9 @@ class DeleteMailTest(SoledadTestBase):
trash_mails = self.get_mails_by_tag('trash')
self.assertEquals(1, len(trash_mails))
+ @defer.inlineCallbacks
def test_delete_mail_when_trashing_mail_from_trash_mailbox(self):
- mails = self.add_multiple_to_mailbox(1, 'trash')
+ mails = yield self.add_multiple_to_mailbox(1, 'trash')
self.delete_mails([mails[0].ident])
trash_mails = self.get_mails_by_tag('trash')
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 52372507..80b399ed 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -21,10 +21,10 @@ import shutil
import time
import uuid
-from leap.mail.imap.account import SoledadBackedAccount
+from leap.mail.imap.account import IMAPAccount
from leap.soledad.client import Soledad
from mock import MagicMock, Mock
-from twisted.internet import reactor
+from twisted.internet import reactor, defer
from twisted.internet.defer import succeed
from twisted.web.resource import getChildForRequest
from twisted.web.server import Site
@@ -50,6 +50,7 @@ class AppTestClient(object):
def __init__(self):
self.start_client()
+ @defer.inlineCallbacks
def start_client(self):
soledad_test_folder = self._generate_soledad_test_folder_name()
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
@@ -65,12 +66,12 @@ class AppTestClient(object):
self.search_engine = SearchEngine(self.INDEX_KEY, agent_home=soledad_test_folder)
self.mail_sender = self._create_mail_sender()
- self.account = SoledadBackedAccount(self.ACCOUNT, self.soledad, MagicMock())
+ self.account = IMAPAccount(self.ACCOUNT, self.soledad, MagicMock())
self.mailboxes = Mailboxes(self.account, self.soledad_querier, self.search_engine)
self.draft_service = DraftService(self.mailboxes)
self.mail_service = self._create_mail_service(self.mailboxes, self.mail_sender, self.soledad_querier, self.search_engine)
- self.search_engine.index_mails(self.mail_service.all_mails())
+ self.search_engine.index_mails((yield self.mail_service.all_mails()))
self.resource = RootResource()
self.resource.initialize(self.keymanager, self.search_engine, self.mail_service, self.draft_service)
@@ -124,21 +125,26 @@ class AppTestClient(object):
def add_document_to_soledad(self, _dict):
self.soledad_querier.soledad.create_doc(_dict)
+ @defer.inlineCallbacks
def add_mail_to_inbox(self, input_mail):
- mail = self.mailboxes.inbox.add(input_mail)
+ inbox = yield self.mailboxes.inbox
+ mail = yield inbox.add(input_mail)
if input_mail.tags:
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
+ @defer.inlineCallbacks
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[], to='recipient@to.com', cc='recipient@cc.com', bcc='recipient@bcc.com'):
mails = []
for _ in range(num):
input_mail = MailBuilder().with_status(flags).with_tags(tags).with_to(to).with_cc(cc).with_bcc(bcc).build_input_mail()
- mail = self.mailboxes._create_or_get(mailbox).add(input_mail)
+ mbx = yield self.mailboxes._create_or_get(mailbox)
+ mail = yield mbx.add(input_mail)
mails.append(mail)
mail.update_tags(input_mail.tags) if tags else None
self.search_engine.index_mails(mails) if tags else None
- return mails
+
+ defer.returnValue(mails)
def _create_soledad_querier(self, soledad, index_key):
soledad_querier = SoledadQuerier(soledad)
@@ -240,5 +246,6 @@ def initialize_soledad(tempdir):
local_db_path,
server_url,
cert_file,
- defer_encryption=False)
+ defer_encryption=False,
+ syncable=False)
return _soledad