summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
Diffstat (limited to 'service/test')
-rw-r--r--service/test/functional/features/forward_trash_archive.feature2
-rw-r--r--service/test/functional/features/steps/tag_list.py4
-rw-r--r--service/test/unit/config/test_register.py20
-rw-r--r--service/test/unit/fixtures/mailset/mbox0000000012
-rw-r--r--service/test/unit/fixtures/mailset/mbox0000000112
-rw-r--r--service/test/unit/maintenance/__init__.py15
-rw-r--r--service/test/unit/maintenance/test_commands.py92
-rw-r--r--service/test/unit/resources/test_sync_info_controller.py53
8 files changed, 154 insertions, 56 deletions
diff --git a/service/test/functional/features/forward_trash_archive.feature b/service/test/functional/features/forward_trash_archive.feature
index 6e959c32..1d373b88 100644
--- a/service/test/functional/features/forward_trash_archive.feature
+++ b/service/test/functional/features/forward_trash_archive.feature
@@ -31,4 +31,4 @@ Feature: forward and deletion
When I choose to trash
# Then I see that mail under the 'trash' tag
When I select the tag 'trash'
- And I open the first mail in the mail list \ No newline at end of file
+ And I open the first mail in the mail list
diff --git a/service/test/functional/features/steps/tag_list.py b/service/test/functional/features/steps/tag_list.py
index b3e09c22..443c5173 100644
--- a/service/test/functional/features/steps/tag_list.py
+++ b/service/test/functional/features/steps/tag_list.py
@@ -21,13 +21,13 @@ def click_first_element_with_class(context, classname):
elements[0].click()
-def is_side_nax_expanded(context):
+def is_side_nav_expanded(context):
e = context.browser.find_elements_by_class_name('content')[0].get_attribute('class').count(u'move-right') == 1
return e
def expand_side_nav(context):
- if is_side_nax_expanded(context):
+ if is_side_nav_expanded(context):
return
toggle = context.browser.find_elements_by_class_name('side-nav-toggle')[0]
diff --git a/service/test/unit/config/test_register.py b/service/test/unit/config/test_register.py
new file mode 100644
index 00000000..7db2b000
--- /dev/null
+++ b/service/test/unit/config/test_register.py
@@ -0,0 +1,20 @@
+import unittest
+
+from pixelated.config.register import validate_username
+
+
+class TestRegister(unittest.TestCase):
+
+ def test_username_raises_error_when_it_contains_uppercase_letters(self):
+ with self.assertRaises(ValueError):
+ validate_username('INVALIDUSERNAME')
+
+ def test_username_raises_error_when_it_contains_special_characters(self):
+ with self.assertRaises(ValueError):
+ validate_username('invalid@username')
+
+ def test_username_pass_when_valid(self):
+ try:
+ validate_username('a.valid_username-123')
+ except:
+ self.fail('Valid username should not raise an exception')
diff --git a/service/test/unit/fixtures/mailset/mbox00000000 b/service/test/unit/fixtures/mailset/mbox00000000
new file mode 100644
index 00000000..3d01c203
--- /dev/null
+++ b/service/test/unit/fixtures/mailset/mbox00000000
@@ -0,0 +1,12 @@
+From darby.senger@zemlak.biz
+Subject: Itaque consequatur repellendus provident sunt quia.
+To: carmel@murazikortiz.name
+X-TW-Pixelated-Tags: nite, macro, trash
+Date: Tue, 21 Apr 2015 08:43:27 +0000 (UTC)
+
+Dignissimos ducimus veritatis. Est tenetur consequatur quia occaecati. Vel sit sit voluptas.
+
+Earum distinctio eos. Accusantium qui sint ut quia assumenda. Facere dignissimos inventore autem sit amet. Pariatur voluptatem sint est.
+
+Ut recusandae praesentium aspernatur. Exercitationem amet placeat deserunt quae consequatur eum. Unde doloremque suscipit quia.
+
diff --git a/service/test/unit/fixtures/mailset/mbox00000001 b/service/test/unit/fixtures/mailset/mbox00000001
new file mode 100644
index 00000000..fc76bba2
--- /dev/null
+++ b/service/test/unit/fixtures/mailset/mbox00000001
@@ -0,0 +1,12 @@
+From madeline.littel@sanfordruel.com
+Subject: Error illum dignissimos autem eos aspernatur.
+To: phyllis@stiedemann.net
+X-TW-Pixelated-Tags: instadaily, inspiration
+Date: Tue, 21 Apr 2015 08:43:27 +0000 (UTC)
+
+Et inventore placeat aut. Sint eveniet labore perferendis nulla. Maiores rerum sunt perferendis. Voluptate iure hic et ut blanditiis ad veritatis. Labore occaecati rerum.
+
+Sit fugiat aliquam voluptates ipsum non. Dolor quo sapiente. Itaque sed odit velit. Qui et aspernatur et fugiat voluptas eum est. Et expedita eos rerum nisi ut eum vero.
+
+Ab et est cumque. Qui nostrum perferendis. Labore est tempora porro est quia deleniti consequatur. Fugit quis ipsa.
+
diff --git a/service/test/unit/maintenance/__init__.py b/service/test/unit/maintenance/__init__.py
new file mode 100644
index 00000000..2756a319
--- /dev/null
+++ b/service/test/unit/maintenance/__init__.py
@@ -0,0 +1,15 @@
+#
+# 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/>.
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py
new file mode 100644
index 00000000..f23655d8
--- /dev/null
+++ b/service/test/unit/maintenance/test_commands.py
@@ -0,0 +1,92 @@
+#
+# 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
+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.soledad.client import Soledad
+from leap.soledad.common.document import SoledadDocument
+from mock import MagicMock, ANY
+from os.path import join, dirname
+
+
+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.args = (self.leap_session, self.soledad)
+
+ def test_delete_all_mails_supports_empty_doclist(self):
+ self.soledad.get_all_docs.return_value = (1, [])
+
+ delete_all_mails(self.args)
+
+ 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])
+
+ delete_all_mails(self.args)
+
+ 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)
+
+ 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))
+
+ 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 test_load_mails_empty_path_list(self):
+ load_mails(self.args, [])
+
+ self.assertFalse(self.mailbox.called)
+
+ def test_load_mails_adds_mails(self):
+ mail_root = join(dirname(__file__), '..', 'fixtures', 'mailset')
+
+ foo = 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)
+
+ def _mail_content(self, mail_file):
+ with open(mail_file, 'r') as fp:
+ m = email.message_from_file(fp)
+ return m.as_string()
diff --git a/service/test/unit/resources/test_sync_info_controller.py b/service/test/unit/resources/test_sync_info_controller.py
deleted file mode 100644
index 1285237b..00000000
--- a/service/test/unit/resources/test_sync_info_controller.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# 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
-import json
-
-from test.support.test_helper import request_mock
-from pixelated.resources.sync_info_resource import SyncInfoResource
-from mockito import mock
-
-
-class SyncInfoResourceTest(unittest.TestCase):
-
- def setUp(self):
- self.dummy_request = request_mock()
- self.controller = SyncInfoResource()
-
- def _set_count(self, current, total):
- soledad_sync_data = mock()
- soledad_sync_data.content = "%s/%s" % (current, total)
- self.controller.set_sync_info(soledad_sync_data)
-
- def get_sync_info(self):
- return json.loads(self.controller.render_GET(self.dummy_request))
-
- def test_is_not_syncing_if_total_is_equal_to_current(self):
- self._set_count(total=0, current=0)
-
- sync_info = self.get_sync_info()
-
- self.assertFalse(sync_info['is_syncing'])
-
- def test_is_syncing_if_total_is_not_equal_to_current_and_adds_count(self):
- self._set_count(total=10, current=5)
-
- sync_info = self.get_sync_info()
-
- self.assertTrue(sync_info['is_syncing'])
- self.assertEquals(5, sync_info['count']['current'])
- self.assertEquals(10, sync_info['count']['total'])
- self.assertEquals(0.5, sync_info['count']['progress'])