summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-31 06:46:57 +0000
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:30 +0200
commit3d79c0d150300d4f59531c8610f85f3927b085bc (patch)
treeebd85b012dd202010f120b7f38a0525c26081be3
parent1074ae5256ee296ec2efe5407a330a933e2e3b78 (diff)
Adapted maintenace.load_mails to new data model.
- Issue #420
-rw-r--r--service/pixelated/maintenance.py9
-rw-r--r--service/test/unit/maintenance/test_commands.py19
2 files changed, 13 insertions, 15 deletions
diff --git a/service/pixelated/maintenance.py b/service/pixelated/maintenance.py
index bffc272f..fd81f8a8 100644
--- a/service/pixelated/maintenance.py
+++ b/service/pixelated/maintenance.py
@@ -119,7 +119,7 @@ def is_keep_file(mail):
@defer.inlineCallbacks
def add_mail_folder(store, maildir, folder_name, deferreds):
- store.add_mailbox(folder_name)
+ yield store.add_mailbox(folder_name)
for mail in maildir:
if is_keep_file(mail):
@@ -144,12 +144,13 @@ def load_mails(args, mail_paths):
for path in mail_paths:
maildir = Maildir(path, factory=None)
- add_mail_folder(store, maildir, 'INBOX', deferreds)
+ yield add_mail_folder(store, maildir, 'INBOX', deferreds)
for mail_folder_name in maildir.list_folders():
mail_folder = maildir.get_folder(mail_folder_name)
- add_mail_folder(store, mail_folder, mail_folder_name, deferreds)
+ yield add_mail_folder(store, mail_folder, mail_folder_name, deferreds)
+
+ yield defer.gatherResults(deferreds, consumeErrors=True)
- yield defer.DeferredList(deferreds)
defer.returnValue(args)
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py
index 8a573766..abebe997 100644
--- a/service/test/unit/maintenance/test_commands.py
+++ b/service/test/unit/maintenance/test_commands.py
@@ -35,7 +35,6 @@ class TestCommands(unittest.TestCase):
self.leap_session = MagicMock(spec=LeapSession)
self.soledad = MagicMock(spec=Soledad)
self.account = MagicMock(spec=IMAPAccount)
- self.mailbox = MagicMock()
self.mail_store = MagicMock(spec=MailStore)
self.leap_session.account = self.account
self.leap_session.mail_store = self.mail_store
@@ -85,18 +84,20 @@ class TestCommands(unittest.TestCase):
def test_load_mails_adds_mails(self):
# given
mail_root = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
- firstMailDeferred = defer.Deferred()
- secondMailDeferred = defer.Deferred()
- self.mailbox.addMessage.side_effect = [firstMailDeferred, secondMailDeferred]
+ firstMailDeferred = defer.succeed(None)
+ secondMailDeferred = defer.succeed(None)
+ self.mail_store.add_mail.side_effect = [firstMailDeferred, secondMailDeferred]
+ self.mail_store.add_mailbox.return_value = defer.succeed(None)
# when
d = load_mails(self.args, [mail_root])
# then
def assert_mails_added(_):
- self.assertTrue(self.mailbox.addMessage.called)
- self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'new', 'mbox00000000')), flags=(MessageFlags.RECENT_FLAG,), notify_on_disk=False)
- self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'new', 'mbox00000001')), flags=(MessageFlags.RECENT_FLAG,), notify_on_disk=False)
+ self.assertTrue(self.mail_store.add_mail.called)
+ self.mail_store.add_mail.assert_any_call('INBOX', self._mail_content(join(mail_root, 'new', 'mbox00000000')))
+ self.mail_store.add_mail.assert_any_call('INBOX', self._mail_content(join(mail_root, 'new', 'mbox00000001')))
+ # TODO Should we check for flags?
def error_callack(err):
print err
@@ -105,10 +106,6 @@ class TestCommands(unittest.TestCase):
d.addCallback(assert_mails_added)
d.addErrback(error_callack)
- # trigger callbacks for both mails
- reactor.callLater(0, firstMailDeferred.callback, None)
- reactor.callLater(0, secondMailDeferred.callback, None)
-
return d
def _mail_content(self, mail_file):