diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-05-04 10:36:21 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-05-04 12:06:00 +0200 |
commit | 4a0e23cf0b94ce1d9e4d8664532989ddd994dc88 (patch) | |
tree | b44a74f40f2fd67c6164519106da8a7f338b468b /service/test/unit/maintenance | |
parent | 427fefd7856bd31d5e4f5ddf42b6b88c397c39d1 (diff) |
Changed maintenance load mails format from mbox to maildir.
- Can now import mails from maildir (allows import of old mail accounts,
too)
- Flags currently supported: Replied, Seen
- Issue #336
Diffstat (limited to 'service/test/unit/maintenance')
-rw-r--r-- | service/test/unit/maintenance/test_commands.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py index 6c881cb9..6f993106 100644 --- a/service/test/unit/maintenance/test_commands.py +++ b/service/test/unit/maintenance/test_commands.py @@ -19,10 +19,12 @@ import email from pixelated.maintenance import delete_all_mails, load_mails from pixelated.bitmask_libraries.session import LeapSession from leap.mail.imap.account import SoledadBackedAccount +from leap.mail.imap.fields import WithMsgFields from leap.soledad.client import Soledad from leap.soledad.common.document import SoledadDocument from mock import MagicMock, ANY from os.path import join, dirname +from twisted.internet import defer, reactor class TestCommands(unittest.TestCase): @@ -78,13 +80,33 @@ class TestCommands(unittest.TestCase): self.assertFalse(self.mailbox.called) def test_load_mails_adds_mails(self): + # given mail_root = join(dirname(__file__), '..', 'fixtures', 'mailset') + firstMailDeferred = defer.Deferred() + secondMailDeferred = defer.Deferred() + self.mailbox.addMessage.side_effect = [firstMailDeferred, secondMailDeferred] - foo = load_mails(self.args, [mail_root]) + # when + d = load_mails(self.args, [mail_root]) - self.assertTrue(self.mailbox.addMessage.called) - self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'mbox00000000')), flags=("\\RECENT",), notify_on_disk=False) - self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'mbox00000001')), flags=("\\RECENT",), notify_on_disk=False) + # 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=(WithMsgFields.RECENT_FLAG,), notify_on_disk=False) + self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'new', 'mbox00000001')), flags=(WithMsgFields.RECENT_FLAG,), notify_on_disk=False) + + def error_callack(err): + print err + self.assertTrue(False) + + 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): with open(mail_file, 'r') as fp: |