summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
Diffstat (limited to 'service/test')
-rw-r--r--service/test/mailsets/common/cur/mbox00000002:2,S19
-rw-r--r--service/test/mailsets/common/cur/mbox00000003:2,S17
-rw-r--r--service/test/mailsets/common/cur/mbox00000004:2,S9
-rw-r--r--service/test/mailsets/common/cur/mbox00000005:2,S12
-rw-r--r--service/test/mailsets/common/new/mbox00000000:2,12
-rw-r--r--service/test/mailsets/common/new/mbox0000000122
-rw-r--r--service/test/mailsets/common/tmp/.keep0
-rw-r--r--service/test/unit/adapter/test_mail_service.py10
-rw-r--r--service/test/unit/adapter/test_mailboxes.py40
-rw-r--r--service/test/unit/fixtures/mailset/cur/.keep0
-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/.keep0
-rw-r--r--service/test/unit/maintenance/test_commands.py110
14 files changed, 207 insertions, 44 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/cur/mbox00000003:2,S b/service/test/mailsets/common/cur/mbox00000003:2,S
new file mode 100644
index 00000000..36c6706a
--- /dev/null
+++ b/service/test/mailsets/common/cur/mbox00000003:2,S
@@ -0,0 +1,17 @@
+Subject: Scott's Laws
+From: scott@try.pixelated-project.org
+To: alice@try.pixelated-project.org
+X-Pixelated-encryption-status: true
+Date: Tue, 09 Apr 2015 23:42:05 +0000 (UTC)
+
+Scott's First Law:
+ No matter what goes wrong, it will probably look right.
+
+Scott's Second Law:
+ When an error has been detected and corrected, it will be found
+ to have been wrong in the first place.
+Corollary:
+ After the correction has been found in error, it will be
+ impossible to fit the original quantity back into the
+ equation.
+
diff --git a/service/test/mailsets/common/cur/mbox00000004:2,S b/service/test/mailsets/common/cur/mbox00000004:2,S
new file mode 100644
index 00000000..db3be01d
--- /dev/null
+++ b/service/test/mailsets/common/cur/mbox00000004:2,S
@@ -0,0 +1,9 @@
+Subject: Progress is only made on alternate Fridays
+From: bob@try.pixelated-project.org
+To: alice@try.pixelated-project.org
+X-Pixelated-encryption-status: true
+Date: Tue, 10 Apr 2015 03:15:38 +0000 (UTC)
+
+Weinberg's First Law:
+ Progress is only made on alternate Fridays.
+
diff --git a/service/test/mailsets/common/cur/mbox00000005:2,S b/service/test/mailsets/common/cur/mbox00000005:2,S
new file mode 100644
index 00000000..e02718f1
--- /dev/null
+++ b/service/test/mailsets/common/cur/mbox00000005:2,S
@@ -0,0 +1,12 @@
+Subject: bypassing trouble
+From: oliver@try.pixelated-project.org
+To: alice@try.pixelated-project.org
+X-Pixelated-encryption-status: true
+Date: Tue, 04 Apr 2015 16:41:39 +0000 (UTC)
+
+If I had a formula for bypassing trouble, I would not pass it around.
+Trouble creates a capacity to handle it. I don't say embrace trouble; that's
+as bad as treating it as an enemy. But I do say meet it as a friend, for
+you'll see a lot of it and you had better be on speaking terms with it.
+ -- Oliver Wendell Holmes, Jr.
+
diff --git a/service/test/mailsets/common/new/mbox00000000:2, b/service/test/mailsets/common/new/mbox00000000:2,
new file mode 100644
index 00000000..a35e63f0
--- /dev/null
+++ b/service/test/mailsets/common/new/mbox00000000:2,
@@ -0,0 +1,12 @@
+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
+Date: Tue, 01 Apr 2015 08:43:27 +0000 (UTC)
+
+Yesterday upon the stair
+I met a man who wasn't there.
+He wasn't there again today --
+I think he's from the CIA.
+
diff --git a/service/test/mailsets/common/new/mbox00000001 b/service/test/mailsets/common/new/mbox00000001
new file mode 100644
index 00000000..e1c6ba8b
--- /dev/null
+++ b/service/test/mailsets/common/new/mbox00000001
@@ -0,0 +1,22 @@
+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
+Date: Tue, 05 Apr 2015 13:52:05 +0000 (UTC)
+
+=== ALL USERS PLEASE NOTE ========================
+
+The garbage collector now works. In addition a new, experimental garbage
+collection algorithm has been installed. With SI:%DSK-GC-QLX-BITS set to 17,
+(NOT the default) the old garbage collection algorithm remains in force; when
+virtual storage is filled, the machine cold boots itself. With SI:%DSK-GC-
+QLX-BITS set to 23, the new garbage collector is enabled. Unlike most garbage
+collectors, the new gc starts its mark phase from the mind of the user, rather
+than from the obarray. This allows the garbage collection of significantly
+more Qs. As the garbage collector runs, it may ask you something like "Do you
+remember what SI:RDTBL-TRANS does?", and if you can't give a reasonable answer
+in thirty seconds, the symbol becomes a candidate for GCing. The variable
+SI:%GC-QLX-LUSER-TM governs how long the GC waits before timing out the user.
+
+
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/adapter/test_mail_service.py b/service/test/unit/adapter/test_mail_service.py
index 34fec708..f4b89f57 100644
--- a/service/test/unit/adapter/test_mail_service.py
+++ b/service/test/unit/adapter/test_mail_service.py
@@ -101,3 +101,13 @@ class TestMailService(unittest.TestCase):
self.mail_service.delete_mail(1)
verify(self.mailboxes).move_to_trash(1)
+
+ def test_recover_mail(self):
+ mail_to_recover = PixelatedMail.from_soledad(*leap_mail(), soledad_querier=None)
+ when(self.mail_service).mail(1).thenReturn(mail_to_recover)
+ when(self.mailboxes).move_to_inbox(1).thenReturn(mail_to_recover)
+
+ self.mail_service.recover_mail(1)
+
+ verify(self.mailboxes).move_to_inbox(1)
+ verify(self.search_engine).index_mail(mail_to_recover)
diff --git a/service/test/unit/adapter/test_mailboxes.py b/service/test/unit/adapter/test_mailboxes.py
new file mode 100644
index 00000000..5b4548eb
--- /dev/null
+++ b/service/test/unit/adapter/test_mailboxes.py
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2014 ThoughtWorks, Inc.
+#
+# Pixelated is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pixelated is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import unittest
+
+from pixelated.adapter.model.mail import PixelatedMail
+from pixelated.adapter.services.mailboxes import Mailboxes
+from mockito import mock, when, verify
+from test.support import test_helper
+from mock import MagicMock
+
+
+class PixelatedMailboxesTest(unittest.TestCase):
+ def setUp(self):
+ self.querier = mock()
+ self.search_engine = mock()
+ self.account = MagicMock()
+ self.mailboxes = Mailboxes(self.account, self.querier, self.search_engine)
+
+ def test_move_to_inbox(self):
+ mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
+ when(self.querier).mail(1).thenReturn(mail)
+ when(mail).save().thenReturn(None)
+
+ mail.set_mailbox('TRASH')
+ recovered_mail = self.mailboxes.move_to_inbox(1)
+ self.assertEquals('INBOX', recovered_mail.mailbox_name)
+ verify(mail).save()
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 f23655d8..6f993106 100644
--- a/service/test/unit/maintenance/test_commands.py
+++ b/service/test/unit/maintenance/test_commands.py
@@ -19,74 +19,96 @@ 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):
- 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
+ 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.args = (self.leap_session, self.soledad)
+ self.args = (self.leap_session, self.soledad)
- def test_delete_all_mails_supports_empty_doclist(self):
- self.soledad.get_all_docs.return_value = (1, [])
+ def test_delete_all_mails_supports_empty_doclist(self):
+ self.soledad.get_all_docs.return_value = (1, [])
- delete_all_mails(self.args)
+ delete_all_mails(self.args)
- self.assertFalse(self.soledad.delete_doc.called)
+ self.assertFalse(self.soledad.delete_doc.called)
- def test_delete_all_mails(self):
- doc = MagicMock(spec=SoledadDocument)
- doc.content = {'type': 'head'}
- self.soledad.get_all_docs.return_value = (1, [doc])
+ def test_delete_all_mails(self):
+ doc = MagicMock(spec=SoledadDocument)
+ doc.content = {'type': 'head'}
+ self.soledad.get_all_docs.return_value = (1, [doc])
- delete_all_mails(self.args)
+ delete_all_mails(self.args)
- self.soledad.delete_doc.assert_called_once_with(doc)
+ self.soledad.delete_doc.assert_called_once_with(doc)
- def test_only_mail_documents_are_deleted(self):
- docs = self._create_docs_of_type(['head', 'cnt', 'flags', 'mbx', 'foo', None])
- self.soledad.get_all_docs.return_value = (1, docs)
+ def test_only_mail_documents_are_deleted(self):
+ docs = self._create_docs_of_type(['head', 'cnt', 'flags', 'mbx', 'foo', None])
+ self.soledad.get_all_docs.return_value = (1, docs)
- delete_all_mails(self.args)
+ delete_all_mails(self.args)
- for doc in docs:
- if doc.content['type'] in ['head', 'cnt', 'flags']:
- self.soledad.delete_doc.assert_any_call(doc)
- self.assertEqual(3, len(self.soledad.delete_doc.mock_calls))
+ for doc in docs:
+ if doc.content['type'] in ['head', 'cnt', 'flags']:
+ self.soledad.delete_doc.assert_any_call(doc)
+ self.assertEqual(3, len(self.soledad.delete_doc.mock_calls))
- def _create_docs_of_type(self, type_list):
- return [self._create_doc_type(t) for t in type_list]
+ def _create_docs_of_type(self, type_list):
+ return [self._create_doc_type(t) for t in type_list]
- def _create_doc_type(self, doc_type):
- doc = MagicMock(spec=SoledadDocument)
- doc.content = {'type': doc_type}
- return doc
+ def _create_doc_type(self, doc_type):
+ doc = MagicMock(spec=SoledadDocument)
+ doc.content = {'type': doc_type}
+ return doc
- def test_load_mails_empty_path_list(self):
- load_mails(self.args, [])
+ def test_load_mails_empty_path_list(self):
+ load_mails(self.args, [])
- self.assertFalse(self.mailbox.called)
+ self.assertFalse(self.mailbox.called)
- def test_load_mails_adds_mails(self):
- mail_root = join(dirname(__file__), '..', 'fixtures', 'mailset')
+ 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])
+ # then
+ def assert_mails_added(_):
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)
+ 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 _mail_content(self, mail_file):
- with open(mail_file, 'r') as fp:
- m = email.message_from_file(fp)
- return m.as_string()
+ 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:
+ m = email.message_from_file(fp)
+ return m.as_string()