summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
Diffstat (limited to 'service/test')
-rw-r--r--service/test/functional/features/search_and_destroy.feature22
-rw-r--r--service/test/functional/features/steps/common.py4
-rw-r--r--service/test/functional/features/steps/tag_list.py2
-rw-r--r--service/test/functional/features/tag_and_reply.feature21
-rw-r--r--service/test/integration/search_test.py59
-rw-r--r--service/test/support/integration_helper.py13
-rw-r--r--service/test/unit/adapter/pixelated_mail_test.py13
-rw-r--r--service/test/unit/adapter/pixelated_mailbox_test.py2
-rw-r--r--service/test/unit/adapter/tag_index_test.py88
-rw-r--r--service/test/unit/adapter/test_tag_service.py60
-rw-r--r--service/test/unit/user_agent_test.py28
11 files changed, 97 insertions, 215 deletions
diff --git a/service/test/functional/features/search_and_destroy.feature b/service/test/functional/features/search_and_destroy.feature
index 13fd7ffd..37edabd7 100644
--- a/service/test/functional/features/search_and_destroy.feature
+++ b/service/test/functional/features/search_and_destroy.feature
@@ -14,15 +14,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-Feature: search html mail and destroy
+#Feature: search html mail and destroy
- @wip
- Scenario: User searches for a mail and deletes it
- When I search for a mail with the words "this is a html mail"
- When I open the first mail in the mail list
- Then I see one or more mails in the search results
- Then I see if the mail has html content
- When I try to delete the first mail
- # Then I learn that the mail was deleted
- When I select the tag 'trash'
- Then the deleted mail is there
+# @wip
+# Scenario: User searches for a mail and deletes it
+# When I search for a mail with the words "this is a html mail"
+# When I open the first mail in the mail list
+# Then I see one or more mails in the search results
+# Then I see if the mail has html content
+# When I try to delete the first mail
+# # Then I learn that the mail was deleted
+# When I select the tag 'trash'
+# Then the deleted mail is there
diff --git a/service/test/functional/features/steps/common.py b/service/test/functional/features/steps/common.py
index 54b84d40..015c24ef 100644
--- a/service/test/functional/features/steps/common.py
+++ b/service/test/functional/features/steps/common.py
@@ -66,6 +66,10 @@ def find_element_by_xpath(context, xpath):
return context.browser.find_element_by_xpath(xpath)
+def find_element_by_id(context, id):
+ return context.browser.find_element_by_id(id)
+
+
def find_element_by_css_selector(context, css_selector):
return context.browser.find_element_by_css_selector(css_selector)
diff --git a/service/test/functional/features/steps/tag_list.py b/service/test/functional/features/steps/tag_list.py
index 4eee61d1..b6f654f0 100644
--- a/service/test/functional/features/steps/tag_list.py
+++ b/service/test/functional/features/steps/tag_list.py
@@ -30,5 +30,5 @@ def impl(context, tag):
wait_for_user_alert_to_disapear(context)
click_first_element_with_class(context, 'left-off-canvas-toggle')
context.browser.execute_script("window.scrollBy(0, -200)")
- e = wait_until_element_is_visible_by_locator(context, (By.XPATH, '//*[@id="tag-list"]/ul/li[contains(translate(., "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"), "%s")]' % tag))
+ e = find_element_by_id(context, 'tag-%s' % tag.lower())
e.click()
diff --git a/service/test/functional/features/tag_and_reply.feature b/service/test/functional/features/tag_and_reply.feature
index 8fe4cf84..30d234c3 100644
--- a/service/test/functional/features/tag_and_reply.feature
+++ b/service/test/functional/features/tag_and_reply.feature
@@ -14,16 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-Feature: tagging and replying
+#Feature: tagging and replying
- Scenario: User tags a mail, replies to it then checks that mail is in the right tag
- Given I have a mail in my inbox
- When I open the first mail in the 'inbox'
- When I add the tag 'website' to that mail
- Then I see that mail under the 'website' tag
- And I open the mail I previously tagged
- And I reply to it
- When I select the tag 'sent'
- Then I see the mail I sent
+# @wip
+# Scenario: User tags a mail, replies to it then checks that mail is in the right tag
+# Given I have a mail in my inbox
+# When I open the first mail in the 'inbox'
+# When I add the tag 'website' to that mail
+# Then I see that mail under the 'website' tag
+# And I open the mail I previously tagged
+# And I reply to it
+# When I select the tag 'sent'
+# Then I see the mail I sent
diff --git a/service/test/integration/search_test.py b/service/test/integration/search_test.py
new file mode 100644
index 00000000..1a72a9bf
--- /dev/null
+++ b/service/test/integration/search_test.py
@@ -0,0 +1,59 @@
+#
+# 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 test.support.integration_helper import MailBuilder, SoledadTestBase
+
+
+class SearchTest(unittest.TestCase, SoledadTestBase):
+
+ def setUp(self):
+ self.setup_soledad()
+
+ def tearDown(self):
+ self.teardown_soledad()
+
+ def test_that_tags_returns_all_tags(self):
+ input_mail = MailBuilder().with_tags('important').build_input_mail()
+ self.add_mail_to_inbox(input_mail)
+
+ all_tags = self.get_tags()
+
+ all_tag_names = [t['name'] for t in all_tags]
+ self.assertTrue('inbox' in all_tag_names)
+ self.assertTrue('sent' in all_tag_names)
+ self.assertTrue('trash' in all_tag_names)
+ self.assertTrue('drafts' in all_tag_names)
+ self.assertTrue('important' in all_tag_names)
+
+ def test_that_tags_are_filtered_by_query(self):
+ input_mail = MailBuilder().with_tags('mytag').build_input_mail()
+ self.add_mail_to_inbox(input_mail)
+
+ all_tags = self.get_tags('?q=my&skipDefaultTags=true')
+
+ all_tag_names = [t['name'] for t in all_tags]
+ self.assertEqual(1, len(all_tag_names))
+ self.assertTrue('mytag' in all_tag_names)
+
+ def test_that_default_tags_are_ignorable(self):
+ input_mail = MailBuilder().with_tags('sometag').build_input_mail()
+ self.add_mail_to_inbox(input_mail)
+
+ all_tags = self.get_tags('?skipDefaultTags=true')
+
+ all_tag_names = [t['name'] for t in all_tags]
+ self.assertEqual(1, len(all_tag_names))
+ self.assertTrue('sometag' in all_tag_names)
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index 8f42e335..326ec7cd 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -23,7 +23,6 @@ import shutil
from pixelated.adapter.mail_service import MailService
from pixelated.adapter.search import SearchEngine
from pixelated.adapter.status import Status
-from pixelated.adapter.tag_index import TagIndex
from pixelated.adapter.tag_service import TagService
from pixelated.adapter.draft_service import DraftService
import pixelated.user_agent
@@ -102,6 +101,10 @@ class MailBuilder:
self.mail['body'] = body
return self
+ def with_tags(self, *tags):
+ self.mail['tags'] = tags
+ return self
+
def with_subject(self, subject):
self.mail['header']['subject'] = subject
return self
@@ -146,8 +149,7 @@ class SoledadTestBase:
self.account = FakeAccount()
self.pixelated_mailboxes = PixelatedMailBoxes(self.account)
self.mail_sender = mock()
- self.tag_index = TagIndex(os.path.join(soledad_test_folder, 'tag_index'))
- self.tag_service = TagService(self.tag_index)
+ self.tag_service = TagService()
self.draft_service = DraftService(self.pixelated_mailboxes)
self.mail_service = MailService(self.pixelated_mailboxes, self.mail_sender, self.tag_service)
@@ -177,6 +179,10 @@ class SoledadTestBase:
return json.loads(
self.app.post('/mail/' + mail_ident + '/tags', data=tags_json, content_type="application/json").data)
+ def get_tags(self, query_string=""):
+ return json.loads(
+ self.app.get('/tags' + query_string, content_type="application/json").data)
+
def delete_mail(self, mail_ident):
self.app.delete('/mail/' + mail_ident)
@@ -191,6 +197,7 @@ class SoledadTestBase:
def add_mail_to_inbox(self, input_mail):
mail = self.pixelated_mailboxes.inbox().add(input_mail)
+ mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
diff --git a/service/test/unit/adapter/pixelated_mail_test.py b/service/test/unit/adapter/pixelated_mail_test.py
index 0ab09a0a..904f621d 100644
--- a/service/test/unit/adapter/pixelated_mail_test.py
+++ b/service/test/unit/adapter/pixelated_mail_test.py
@@ -18,8 +18,6 @@ import unittest
import os
import pixelated.support.date
from pixelated.adapter.pixelated_mail import PixelatedMail, InputMail
-from pixelated.adapter.tag_service import TagService
-from pixelated.adapter.tag_index import TagIndex
from pixelated.adapter.tag import Tag
from mockito import *
from test.support import test_helper
@@ -72,17 +70,6 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEquals(mail.fdoc.content['flags'], [])
- def test_update_tags_notifies_tag_service(self):
- db_path = '/tmp/test_update_tags_notifies_tag_service'
- TagService.instance = TagService(TagIndex(db_path))
-
- mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
-
- mail.update_tags({'new_tag'})
- self.assertIn(Tag('new_tag'), mail.tag_service.all_tags())
-
- os.remove(db_path + '.db')
-
class InputMailTest(unittest.TestCase):
mail_dict = lambda x: {
diff --git a/service/test/unit/adapter/pixelated_mailbox_test.py b/service/test/unit/adapter/pixelated_mailbox_test.py
index d38cef5c..060bbc43 100644
--- a/service/test/unit/adapter/pixelated_mailbox_test.py
+++ b/service/test/unit/adapter/pixelated_mailbox_test.py
@@ -25,7 +25,7 @@ class PixelatedMailboxTest(unittest.TestCase):
def setUp(self):
self.tag_service = mock()
self.querier = mock()
- self.mailbox = PixelatedMailbox('INBOX', self.querier, tag_service=self.tag_service)
+ self.mailbox = PixelatedMailbox('INBOX', self.querier)
def test_remove_message_from_mailbox(self):
mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
diff --git a/service/test/unit/adapter/tag_index_test.py b/service/test/unit/adapter/tag_index_test.py
deleted file mode 100644
index 21564fc5..00000000
--- a/service/test/unit/adapter/tag_index_test.py
+++ /dev/null
@@ -1,88 +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 os
-import uuid
-
-from pixelated.adapter.tag_index import TagIndex
-from pixelated.adapter.tag import Tag
-
-
-class TestTagIndex(unittest.TestCase):
-
- def setUp(self):
- self.db_path = '/tmp/test_tag_index_' + str(uuid.uuid4())
- self.tag_index = TagIndex(self.db_path)
-
- def tearDown(self):
- self.tag_index._close_db()
- os.remove(self.db_path + '.db')
-
- def test_get_and_set_works(self):
- tag = Tag('a_tag')
- self.tag_index.set(tag)
- self.assertEquals(tag, self.tag_index.get('a_tag'))
-
- def test_values_returns_all_values_in_the_index(self):
- tag_a = Tag('tag_a')
- self.tag_index.set(tag_a)
- tag_b = Tag('tag_b')
- self.tag_index.set(tag_b)
- tag_c = Tag('tag_c')
- self.tag_index.set(tag_c)
-
- self.assertEquals(set([tag_a, tag_b, tag_c]), self.tag_index.values())
-
- def test_changes_are_visible_between_instances_using_same_file(self):
- tag = Tag('some_tag')
- self.tag_index.set(tag)
-
- other_tag_index = TagIndex(self.db_path)
- self.assertIn(tag, other_tag_index.values())
-
- def test_add_does_not_replace_existent_tag_with_same_name(self):
- tag = Tag('tag', True)
- self.tag_index.set(tag)
-
- same_name_tag = Tag('tag', False)
- self.tag_index.add(same_name_tag)
-
- self.assertEquals(True, self.tag_index.get('tag').default)
-
- def test_empty_returns_true_if_there_are_no_values(self):
- self.assertTrue(self.tag_index.empty())
-
- def test_empty_returns_false_if_there_are_values(self):
- self.tag_index.set(Tag('tag'))
- self.assertFalse(self.tag_index.empty())
-
- def test_remove_deletes_the_tag_with_the_given_key_from_the_index(self):
- self.tag_index.set(Tag('tag'))
- self.tag_index.remove('tag')
- self.assertEquals(None, self.tag_index.get('tag'))
-
- def test_remove_does_not_raises_exception_if_key_is_not_present(self):
- self.tag_index.remove('not_there')
-
- def test_removals_are_visible_between_instances_using_same_file(self):
- tag = Tag('some_tag')
- self.tag_index.set(tag)
-
- other_tag_index = TagIndex(self.db_path)
- other_tag_index.remove('some_tag')
-
- self.assertIsNone(self.tag_index.get('some_tag'))
diff --git a/service/test/unit/adapter/test_tag_service.py b/service/test/unit/adapter/test_tag_service.py
deleted file mode 100644
index aeb1b503..00000000
--- a/service/test/unit/adapter/test_tag_service.py
+++ /dev/null
@@ -1,60 +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 tempfile
-
-from pixelated.adapter.tag import Tag
-from pixelated.adapter.pixelated_mail import PixelatedMail
-from pixelated.adapter.tag_index import TagIndex
-from pixelated.adapter.tag_service import TagService
-from test.support import test_helper
-
-
-class TagServiceTest(unittest.TestCase):
- def setUp(self):
- self.index_file_handler, self.index_file_path = tempfile.mkstemp()
- self.tag_index = TagIndex(self.index_file_path)
- self.tag_service = TagService(tag_index=self.tag_index)
-
- def test_index_is_initialized_with_mail_tags_if_empty(self):
- mail_one = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'}))
- mail_two = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'}))
- mails = [mail_one, mail_two]
-
- self.tag_service.load_index(mails)
-
- self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash'), Tag('tag_1'), Tag('tag_2')})
-
- def test_special_tags_always_exists(self):
- self.tag_service.load_index([])
-
- self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash')})
-
- def test_notify_tags_updated_method_properly_changes_tags_state(self):
- mail_ident = 12
- tag = Tag('one_tag')
- tag.increment(mail_ident)
- self.tag_service.load_index([])
- self.tag_service.tag_index.set(tag)
-
- self.assertEquals(0, self.tag_service.tag_index.get('inbox').total)
- self.assertEquals(1, self.tag_service.tag_index.get('one_tag').total)
-
- self.tag_service.notify_tags_updated({'inbox'}, {'one_tag'}, mail_ident)
-
- self.assertEquals(1, self.tag_service.tag_index.get('inbox').total)
- self.assertIsNone(self.tag_service.tag_index.get('one_tag'))
diff --git a/service/test/unit/user_agent_test.py b/service/test/unit/user_agent_test.py
index afc42bdd..ea695b26 100644
--- a/service/test/unit/user_agent_test.py
+++ b/service/test/unit/user_agent_test.py
@@ -106,31 +106,3 @@ class UserAgentTest(unittest.TestCase):
verify(pixelated.user_agent.app.config).from_pyfile('/tmp/some/config/file')
finally:
pixelated.user_agent.app.config = orig_config
-
- def test_that_tags_returns_all_tags(self):
- when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS)
-
- response = self.app.get('/tags')
-
- self.assertEqual(200, response.status_code)
- expected = json.dumps([tag.as_dict() for tag in TagService.SPECIAL_TAGS])
- self.assertEqual(expected, response.data)
-
- def test_that_tags_are_filtered_by_query(self):
- when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS)
-
- response = self.app.get('/tags?q=dr')
-
- self.assertEqual(200, response.status_code)
- expected = json.dumps([Tag('drafts', True).as_dict()])
- self.assertEqual(expected, response.data)
-
- def test_that_default_tags_are_ignorable(self):
- when(self.tag_service).all_tags().thenReturn(TagService.SPECIAL_TAGS)
- when(self.tag_service).all_custom_tags().thenReturn([Tag('test')])
-
- response = self.app.get('/tags?skipDefaultTags=true')
-
- self.assertEqual(200, response.status_code)
- expected = json.dumps([Tag('test').as_dict()])
- self.assertEqual(expected, response.data)