diff options
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/mailsets/common/cur/mbox00000002:2,S | 19 | ||||
-rw-r--r-- | service/test/mailsets/common/new/mbox00000000:2, (renamed from service/test/mailsets/common/mbox00000000) | 2 | ||||
-rw-r--r-- | service/test/mailsets/common/new/mbox00000001 (renamed from service/test/mailsets/common/mbox00000001) | 2 | ||||
-rw-r--r-- | service/test/mailsets/common/tmp/.keep | 0 | ||||
-rw-r--r-- | service/test/unit/fixtures/mailset/cur/.keep | 0 | ||||
-rw-r--r-- | service/test/unit/fixtures/mailset/new/mbox00000000 (renamed from service/test/unit/fixtures/mailset/mbox00000000) | 0 | ||||
-rw-r--r-- | service/test/unit/fixtures/mailset/new/mbox00000001 (renamed from service/test/unit/fixtures/mailset/mbox00000001) | 0 | ||||
-rw-r--r-- | service/test/unit/fixtures/mailset/tmp/.keep | 0 | ||||
-rw-r--r-- | service/test/unit/maintenance/test_commands.py | 30 |
9 files changed, 47 insertions, 6 deletions
diff --git a/service/test/mailsets/common/cur/mbox00000002:2,S b/service/test/mailsets/common/cur/mbox00000002:2,S new file mode 100644 index 00000000..2881e352 --- /dev/null +++ b/service/test/mailsets/common/cur/mbox00000002:2,S @@ -0,0 +1,19 @@ +Subject: A read mail +From: bob@try.pixelated-project.org +To: alice@try.pixelated-project.org +X-Pixelated-encryption-status: true +Date: Tue, 08 Apr 2015 18:32:05 +0000 (UTC) + +Q: How many hardware engineers does it take to change a lightbulb? +A: None. We'll fix it in software. + +Q: How many system programmers does it take to change a light bulb? +A: None. The application can work around it. + +Q: How many software engineers does it take to change a lightbulb? +A: None. We'll document it in the manual. + +Q: How many tech writers does it take to change a lightbulb? +A: None. The user can figure it out. + + diff --git a/service/test/mailsets/common/mbox00000000 b/service/test/mailsets/common/new/mbox00000000:2, index c3fab833..a35e63f0 100644 --- a/service/test/mailsets/common/mbox00000000 +++ b/service/test/mailsets/common/new/mbox00000000:2, @@ -1,5 +1,5 @@ -From bob@try.pixelated-project.org Subject: Hey Alice +From: bob@try.pixelated-project.org To: alice@try.pixelated-project.org X-TW-Pixelated-Tags: cia X-Pixelated-encryption-status: true diff --git a/service/test/mailsets/common/mbox00000001 b/service/test/mailsets/common/new/mbox00000001 index f80a35cb..e1c6ba8b 100644 --- a/service/test/mailsets/common/mbox00000001 +++ b/service/test/mailsets/common/new/mbox00000001 @@ -1,5 +1,5 @@ -From bob@try.pixelated-project.org Subject: Garbage collection works +From: bob@try.pixelated-project.org To: alice@try.pixelated-project.org X-TW-Pixelated-Tags: garbage X-Pixelated-encryption-status: true diff --git a/service/test/mailsets/common/tmp/.keep b/service/test/mailsets/common/tmp/.keep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/service/test/mailsets/common/tmp/.keep diff --git a/service/test/unit/fixtures/mailset/cur/.keep b/service/test/unit/fixtures/mailset/cur/.keep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/service/test/unit/fixtures/mailset/cur/.keep diff --git a/service/test/unit/fixtures/mailset/mbox00000000 b/service/test/unit/fixtures/mailset/new/mbox00000000 index 3d01c203..3d01c203 100644 --- a/service/test/unit/fixtures/mailset/mbox00000000 +++ b/service/test/unit/fixtures/mailset/new/mbox00000000 diff --git a/service/test/unit/fixtures/mailset/mbox00000001 b/service/test/unit/fixtures/mailset/new/mbox00000001 index fc76bba2..fc76bba2 100644 --- a/service/test/unit/fixtures/mailset/mbox00000001 +++ b/service/test/unit/fixtures/mailset/new/mbox00000001 diff --git a/service/test/unit/fixtures/mailset/tmp/.keep b/service/test/unit/fixtures/mailset/tmp/.keep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/service/test/unit/fixtures/mailset/tmp/.keep 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: |