summaryrefslogtreecommitdiff
path: root/service/test/unit/maintenance/test_commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'service/test/unit/maintenance/test_commands.py')
-rw-r--r--service/test/unit/maintenance/test_commands.py36
1 files changed, 16 insertions, 20 deletions
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py
index f1bf6e45..52fe6ca2 100644
--- a/service/test/unit/maintenance/test_commands.py
+++ b/service/test/unit/maintenance/test_commands.py
@@ -18,13 +18,13 @@ 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 pixelated.adapter.mailstore import MailStore
from leap.soledad.client import Soledad
from leap.soledad.common.document import SoledadDocument
from mock import MagicMock
-from os.path import join, dirname
-from twisted.internet import defer, reactor
+from os.path import join
+from twisted.internet import defer
+import pkg_resources
class TestCommands(unittest.TestCase):
@@ -32,10 +32,8 @@ class TestCommands(unittest.TestCase):
def setUp(self):
self.leap_session = MagicMock(spec=LeapSession)
self.soledad = MagicMock(spec=Soledad)
- self.account = MagicMock(spec=SoledadBackedAccount)
- self.mailbox = MagicMock()
- self.leap_session.account = self.account
- self.account.getMailbox.return_value = self.mailbox
+ self.mail_store = MagicMock(spec=MailStore)
+ self.leap_session.mail_store = self.mail_store
self.args = (self.leap_session, self.soledad)
@@ -77,23 +75,25 @@ class TestCommands(unittest.TestCase):
def test_load_mails_empty_path_list(self):
load_mails(self.args, [])
- self.assertFalse(self.mailbox.called)
+ self.assertFalse(self.mail_store.add_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]
+ mail_root = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
+ 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=(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)
+ 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
@@ -102,10 +102,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):