From a8274b633a62262e65c7d013e61a54541ce07bf8 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Thu, 22 Jan 2015 10:25:40 -0200 Subject: #224 renaming tests so they get caught by trial runner --- service/test/integration/contacts_test.py | 54 -------- service/test/integration/delete_mail_test.py | 65 ---------- service/test/integration/drafts_test.py | 84 ------------ .../test/integration/mark_as_read_unread_test.py | 104 --------------- .../test/integration/retrieve_attachment_test.py | 45 ------- service/test/integration/search_test.py | 144 --------------------- service/test/integration/soledad_querier_test.py | 88 ------------- service/test/integration/tags_test.py | 54 -------- service/test/integration/test_contacts.py | 54 ++++++++ service/test/integration/test_delete_mail.py | 65 ++++++++++ service/test/integration/test_drafts.py | 84 ++++++++++++ .../test/integration/test_mark_as_read_unread.py | 104 +++++++++++++++ .../test/integration/test_retrieve_attachment.py | 45 +++++++ service/test/integration/test_search.py | 144 +++++++++++++++++++++ service/test/integration/test_soledad_querier.py | 88 +++++++++++++ service/test/integration/test_tags.py | 54 ++++++++ 16 files changed, 638 insertions(+), 638 deletions(-) delete mode 100644 service/test/integration/contacts_test.py delete mode 100644 service/test/integration/delete_mail_test.py delete mode 100644 service/test/integration/drafts_test.py delete mode 100644 service/test/integration/mark_as_read_unread_test.py delete mode 100644 service/test/integration/retrieve_attachment_test.py delete mode 100644 service/test/integration/search_test.py delete mode 100644 service/test/integration/soledad_querier_test.py delete mode 100644 service/test/integration/tags_test.py create mode 100644 service/test/integration/test_contacts.py create mode 100644 service/test/integration/test_delete_mail.py create mode 100644 service/test/integration/test_drafts.py create mode 100644 service/test/integration/test_mark_as_read_unread.py create mode 100644 service/test/integration/test_retrieve_attachment.py create mode 100644 service/test/integration/test_search.py create mode 100644 service/test/integration/test_soledad_querier.py create mode 100644 service/test/integration/test_tags.py (limited to 'service/test/integration') diff --git a/service/test/integration/contacts_test.py b/service/test/integration/contacts_test.py deleted file mode 100644 index 925e5e02..00000000 --- a/service/test/integration/contacts_test.py +++ /dev/null @@ -1,54 +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 . -from nose.twistedtools import deferred -from test.support.integration import SoledadTestBase, MailBuilder - - -class ContactsTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) - def test_TO_CC_and_BCC_fields_are_being_searched(self): - input_mail = MailBuilder().with_tags(['important']).build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - d = self.get_contacts(query='recipient') - - def _assert(contacts): - self.assertTrue('recipient@to.com' in contacts) - self.assertTrue('recipient@cc.com' in contacts) - self.assertTrue('recipient@bcc.com' in contacts) - d.addCallback(_assert) - return d - - @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) - def test_trash_and_drafts_mailboxes_are_being_ignored(self): - self.client.add_multiple_to_mailbox(1, mailbox='INBOX', to='recipient@inbox.com') - self.client.add_multiple_to_mailbox(1, mailbox='DRAFTS', to='recipient@drafts.com') - self.client.add_multiple_to_mailbox(1, mailbox='SENT', to='recipient@sent.com') - self.client.add_multiple_to_mailbox(1, mailbox='TRASH', to='recipient@trash.com') - - d = self.get_contacts(query='recipient') - - def _assert(contacts): - self.assertTrue('recipient@inbox.com' in contacts) - self.assertTrue('recipient@sent.com' in contacts) - self.assertFalse('recipient@drafts.com' in contacts) - self.assertFalse('recipient@trash.com' in contacts) - d.addCallback(_assert) - return d diff --git a/service/test/integration/delete_mail_test.py b/service/test/integration/delete_mail_test.py deleted file mode 100644 index 5a3a97fb..00000000 --- a/service/test/integration/delete_mail_test.py +++ /dev/null @@ -1,65 +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 . - -from test.support.integration import * - - -class DeleteMailTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - def tearDown(self): - SoledadTestBase.tearDown(self) - - def test_move_mail_to_trash_when_deleting(self): - input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - inbox_mails = self.get_mails_by_tag('inbox') - self.assertEquals(1, len(inbox_mails)) - - self.delete_mail(input_mail.ident) - - inbox_mails = self.get_mails_by_tag('inbox') - self.assertEquals(0, len(inbox_mails)) - trash_mails = self.get_mails_by_tag('trash') - self.assertEquals(1, len(trash_mails)) - - def test_delete_mail_when_trashing_mail_from_trash_mailbox(self): - mails = self.client.add_multiple_to_mailbox(1, 'trash') - self.delete_mails([mails[0].ident]) - - trash_mails = self.get_mails_by_tag('trash') - - self.assertEqual(0, len(trash_mails)) - - def test_move_mail_to_trash_when_delete_multiple(self): - mails = self.client.add_multiple_to_mailbox(5, 'inbox') - mail_idents = [m.ident for m in mails] - - self.delete_mails(mail_idents) - - inbox = self.get_mails_by_tag('inbox') - self.assertEquals(0, len(inbox)) - - def test_delete_permanently_when_mails_are_in_trash(self): - mails = self.client.add_multiple_to_mailbox(5, 'trash') - self.delete_mails([m.ident for m in mails]) - - trash = self.get_mails_by_tag('trash') - - self.assertEquals(0, len(trash)) diff --git a/service/test/integration/drafts_test.py b/service/test/integration/drafts_test.py deleted file mode 100644 index d4fde099..00000000 --- a/service/test/integration/drafts_test.py +++ /dev/null @@ -1,84 +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 . - -from test.support.integration import * - - -class DraftsTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - def tearDown(self): - SoledadTestBase.tearDown(self) - - def test_post_sends_mail_and_deletes_previous_draft_if_it_exists(self): - # creates one draft - first_draft = MailBuilder().with_subject('First draft').build_json() - first_draft_ident = self.put_mail(first_draft)[0]['ident'] - - # sends an updated version of the draft - second_draft = MailBuilder().with_subject('Second draft').with_ident(first_draft_ident).build_json() - self.post_mail(second_draft) - - sent_mails = self.get_mails_by_tag('sent') - drafts = self.get_mails_by_tag('drafts') - - # make sure there is one email in the sent mailbox and it is the second draft - self.assertEquals(1, len(sent_mails)) - self.assertEquals('Second draft', sent_mails[0].subject) - - # make sure that there are no drafts in the draft mailbox - self.assertEquals(0, len(drafts)) - - def test_post_sends_mail_even_when_draft_does_not_exist(self): - first_draft = MailBuilder().with_subject('First draft').build_json() - self.post_mail(first_draft) - - sent_mails = self.get_mails_by_tag('sent') - drafts = self.get_mails_by_tag('drafts') - - self.assertEquals(1, len(sent_mails)) - self.assertEquals('First draft', sent_mails[0].subject) - self.assertEquals(0, len(drafts)) - - def test_put_creates_a_draft_if_it_does_not_exist(self): - mail = MailBuilder().with_subject('A new draft').build_json() - self.put_mail(mail) - mails = self.get_mails_by_tag('drafts') - - self.assertEquals('A new draft', mails[0].subject) - - def test_put_updates_draft_if_it_already_exists(self): - draft = MailBuilder().with_subject('First draft').build_json() - draft_ident = self.put_mail(draft)[0]['ident'] - - updated_draft = MailBuilder().with_subject('First draft edited').with_ident(draft_ident).build_json() - self.put_mail(updated_draft) - - drafts = self.get_mails_by_tag('drafts') - - self.assertEquals(1, len(drafts)) - self.assertEquals('First draft edited', drafts[0].subject) - - def test_respond_unprocessable_entity_if_draft_to_remove_doesnt_exist(self): - draft = MailBuilder().with_subject('First draft').build_json() - self.put_mail(draft) - - updated_draft = MailBuilder().with_subject('First draft edited').with_ident('NOTFOUND').build_json() - _, request = self.put_mail(updated_draft) - - self.assertEquals(422, request.code) diff --git a/service/test/integration/mark_as_read_unread_test.py b/service/test/integration/mark_as_read_unread_test.py deleted file mode 100644 index 86a48e62..00000000 --- a/service/test/integration/mark_as_read_unread_test.py +++ /dev/null @@ -1,104 +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 . - -from test.support.integration import * -from pixelated.adapter.model.status import Status - - -class MarkAsReadUnreadTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - def tearDown(self): - SoledadTestBase.tearDown(self) - - def test_mark_single_as_read(self): - input_mail = MailBuilder().build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - mails = self.get_mails_by_tag('inbox') - self.assertNotIn('read', mails[0].status) - - self.mark_many_as_read([input_mail.ident]) - - mails = self.get_mails_by_tag('inbox') - self.assertIn('read', mails[0].status) - - def test_mark_single_as_unread(self): - input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - self.mark_many_as_unread([input_mail.ident]) - mail = self.get_mails_by_tag('inbox')[0] - - self.assertNotIn('read', mail.status) - - def test_mark_many_mails_as_unread(self): - input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail() - input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail() - - self.client.add_mail_to_inbox(input_mail) - self.client.add_mail_to_inbox(input_mail2) - - self.mark_many_as_unread([input_mail.ident, input_mail2.ident]) - - mails = self.get_mails_by_tag('inbox') - - self.assertNotIn('read', mails[0].status) - self.assertNotIn('read', mails[1].status) - - def test_mark_many_mails_as_read(self): - input_mail = MailBuilder().build_input_mail() - input_mail2 = MailBuilder().build_input_mail() - - self.client.add_mail_to_inbox(input_mail) - self.client.add_mail_to_inbox(input_mail2) - - mails = self.get_mails_by_tag('inbox') - - self.assertNotIn('read', mails[0].status) - self.assertNotIn('read', mails[1].status) - - response = self.mark_many_as_read([input_mail.ident, input_mail2.ident]) - self.assertEquals(200, response.code) - - mails = self.get_mails_by_tag('inbox') - - self.assertIn('read', mails[0].status) - self.assertIn('read', mails[1].status) - - def test_mark_mixed_status_as_read(self): - input_mail = MailBuilder().build_input_mail() - input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail() - - self.client.add_mail_to_inbox(input_mail) - self.client.add_mail_to_inbox(input_mail2) - - mails = self.get_mails_by_tag('inbox') - - read_mails = filter(lambda x: 'read' in x.status, mails) - unread_mails = filter(lambda x: 'read' not in x.status, mails) - self.assertEquals(1, len(unread_mails)) - self.assertEquals(1, len(read_mails)) - - response = self.mark_many_as_read([input_mail.ident, input_mail2.ident]) - self.assertEquals(200, response.code) - - mails = self.get_mails_by_tag('inbox') - - self.assertIn('read', mails[0].status) - self.assertIn('read', mails[1].status) diff --git a/service/test/integration/retrieve_attachment_test.py b/service/test/integration/retrieve_attachment_test.py deleted file mode 100644 index d6ad9298..00000000 --- a/service/test/integration/retrieve_attachment_test.py +++ /dev/null @@ -1,45 +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 . - -from test.support.integration.soledad_test_base import SoledadTestBase - - -class RetrieveAttachmentTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - def tearDown(self): - SoledadTestBase.tearDown(self) - - def test_attachment_content_is_retrieved(self): - ident = 'F4E99C1CEC4D300A4223A96CCABBE0304BDBC31C550A5A03E207A5E4C3C71A22' - attachment_dict = {'content-disposition': 'attachment', - 'content-transfer-encoding': '', - 'type': 'cnt', - 'raw': 'cGVxdWVubyBhbmV4byA6RAo=', - 'phash': ident, - 'content-type': 'text/plain; charset=US-ASCII; name="attachment_pequeno.txt"'} - - self.client.add_document_to_soledad(attachment_dict) - - d = self.get_attachment(ident, 'base64') - - def _assert(attachment): - self.assertEquals('pequeno anexo :D\n', attachment) - d.addCallback(_assert) - - return d diff --git a/service/test/integration/search_test.py b/service/test/integration/search_test.py deleted file mode 100644 index 464830d2..00000000 --- a/service/test/integration/search_test.py +++ /dev/null @@ -1,144 +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 . - -from nose.twistedtools import deferred -from test.support.integration import * - - -class SearchTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) - def test_that_tags_returns_all_tags(self): - input_mail = MailBuilder().with_tags(['important']).build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - d = self.get_tags() - - def _assert(all_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) - d.addCallback(_assert) - return d - - @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) - def test_that_tags_are_filtered_by_query(self): - input_mail = MailBuilder().with_tags(['ateu', 'catoa', 'luat', 'zuado']).build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - d = self.get_tags(q=["at"], skipDefaultTags=["true"]) - - def _assert(all_tags): - all_tag_names = [t['name'] for t in all_tags] - self.assertEqual(3, len(all_tag_names)) - self.assertTrue('ateu' in all_tag_names) - self.assertTrue('catoa' in all_tag_names) - self.assertTrue('luat' in all_tag_names) - - d.addCallback(_assert) - return d - - @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) - def test_that_default_tags_are_ignorable(self): - input_mail = MailBuilder().with_tags(['sometag']).build_input_mail() - self.client.add_mail_to_inbox(input_mail) - - d = self.get_tags(skipDefaultTags=["true"]) - - def _assert(all_tags): - all_tag_names = [t['name'] for t in all_tags] - self.assertEqual(1, len(all_tag_names)) - self.assertTrue('sometag' in all_tag_names) - d.addCallback(_assert) - return d - - @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT_LONG) - def test_tags_count(self): - self.client.add_multiple_to_mailbox(num=10, mailbox='inbox', flags=['\\Recent']) - self.client.add_multiple_to_mailbox(num=5, mailbox='inbox', flags=['\\Seen']) - self.client.add_multiple_to_mailbox(num=3, mailbox='inbox', flags=['\\Recent'], tags=['important', 'later']) - self.client.add_multiple_to_mailbox(num=1, mailbox='inbox', flags=['\\Seen'], tags=['important']) - - d = self.get_tags() - - def _assert(tags_count): - self.assertEqual(self.get_count(tags_count, 'inbox')['total'], 19) - self.assertEqual(self.get_count(tags_count, 'inbox')['read'], 6) - self.assertEqual(self.get_count(tags_count, 'important')['total'], 4) - self.assertEqual(self.get_count(tags_count, 'important')['read'], 1) - d.addCallback(_assert) - return d - - def test_search_mails_different_window(self): - input_mail = MailBuilder().build_input_mail() - input_mail2 = MailBuilder().build_input_mail() - self.client.add_mail_to_inbox(input_mail) - self.client.add_mail_to_inbox(input_mail2) - - first_page = self.get_mails_by_tag('inbox', page=1, window=1) - - self.assertEqual(len(first_page), 1) - - def test_search_mails_with_multiple_pages(self): - input_mail = MailBuilder().build_input_mail() - input_mail2 = MailBuilder().build_input_mail() - self.client.add_mail_to_inbox(input_mail) - self.client.add_mail_to_inbox(input_mail2) - - first_page = self.get_mails_by_tag('inbox', page=1, window=1) - second_page = self.get_mails_by_tag('inbox', page=2, window=1) - - idents = [input_mail.ident, input_mail2.ident] - - self.assertIn(first_page[0].ident, idents) - self.assertIn(second_page[0].ident, idents) - - def test_page_zero_fetches_first_page(self): - input_mail = MailBuilder().build_input_mail() - self.client.add_mail_to_inbox(input_mail) - page = self.get_mails_by_tag('inbox', page=0, window=1) - self.assertEqual(page[0].ident, input_mail.ident) - - def get_count(self, tags_count, mailbox): - for tag in tags_count: - if tag['name'] == mailbox: - return tag['counts'] - - def test_order_by_date(self): - input_mail = MailBuilder().with_date('2014-10-15T15:15').build_input_mail() - input_mail2 = MailBuilder().with_date('2014-10-15T15:16').build_input_mail() - - self.client.add_mail_to_inbox(input_mail) - self.client.add_mail_to_inbox(input_mail2) - - results = self.get_mails_by_tag('inbox') - self.assertEqual(results[0].ident, input_mail2.ident) - self.assertEqual(results[1].ident, input_mail.ident) - - def test_search_base64_body(self): - body = u'bl\xe1' - input_mail = MailBuilder().with_body(body.encode('utf-8')).build_input_mail() - self.client.add_mail_to_inbox(input_mail) - results = self.search(body) - - self.assertGreater(len(results), 0, 'No results returned from search') - self.assertEquals(results[0].ident, input_mail.ident) diff --git a/service/test/integration/soledad_querier_test.py b/service/test/integration/soledad_querier_test.py deleted file mode 100644 index f8767630..00000000 --- a/service/test/integration/soledad_querier_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 . - -import copy -import time - -from test.support.integration import * -from leap.mail.imap.fields import WithMsgFields - - -class SoledadQuerierTest(SoledadTestBase, WithMsgFields): - - def setUp(self): - SoledadTestBase.setUp(self) - self.soledad = self.client.soledad - self.maxDiff = None - self.soledad_querier = self.client.soledad_querier - - def tearDown(self): - SoledadTestBase.tearDown(self) - - def _get_empty_mailbox(self): - return copy.deepcopy(self.EMPTY_MBOX) - - def _create_mailbox(self, mailbox_name): - new_mailbox = self._get_empty_mailbox() - new_mailbox['mbox'] = mailbox_name - new_mailbox['created'] = int(time.time() * 10E2) - return self.soledad.create_doc(new_mailbox) - - def _get_mailboxes_from_soledad(self, mailbox_name): - return [m for m in self.soledad.get_from_index('by-type', 'mbox') if m.content['mbox'] == mailbox_name] - - def test_remove_dup_mailboxes_keeps_the_one_with_the_highest_last_uid(self): - self.client.add_multiple_to_mailbox(3, 'INBOX') # by now we already have one inbox with 3 mails - self._create_mailbox('INBOX') # now we have a duplicate - - # make sure we have two - inboxes = self._get_mailboxes_from_soledad('INBOX') - self.assertEqual(2, len(inboxes)) - - self.soledad_querier.remove_duplicates() - - # make sure we only have one, and the one with the right lastuid - inboxes = self._get_mailboxes_from_soledad('INBOX') - self.assertEqual(1, len(inboxes)) - self.assertEqual(3, inboxes[0].content['lastuid']) - - def test_all_mails_skips_incomplete_mails(self): - # creating incomplete mail, we will only save the fdoc - fdoc, hdoc, bdoc = MailBuilder().build_input_mail().get_for_save(1, 'INBOX') - self.soledad.create_doc(fdoc) - - mails = self.soledad_querier.all_mails() - self.assertEqual(0, len(mails)) # mail is incomplete since it only has fdoc - - # adding the hdoc still doesn't complete the mail - self.soledad.create_doc(hdoc) - - mails = self.soledad_querier.all_mails() - self.assertEqual(0, len(mails)) - - # now the mail is complete - self.soledad.create_doc(bdoc) - - mails = self.soledad_querier.all_mails() - self.assertEqual(1, len(mails)) - - def test_get_mails_by_chash(self): - mails = self.client.add_multiple_to_mailbox(3, 'INBOX') - chashes = [mail.ident for mail in mails] - - fetched_mails = self.soledad_querier.mails(chashes) - - self.assertEquals([m.as_dict() for m in fetched_mails], [m.as_dict() for m in mails]) diff --git a/service/test/integration/tags_test.py b/service/test/integration/tags_test.py deleted file mode 100644 index 6072392c..00000000 --- a/service/test/integration/tags_test.py +++ /dev/null @@ -1,54 +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 . -import json - -from test.support.integration import * -from pixelated.adapter.services.tag_service import TagService - - -class TagsTest(SoledadTestBase): - - def setUp(self): - SoledadTestBase.setUp(self) - - def tearDown(self): - SoledadTestBase.tearDown(self) - - def _tags_json(self, tags): - return json.dumps({'newtags': tags}) - - def test_add_tag_to_an_inbox_mail_and_query(self): - mail = MailBuilder().with_subject('Mail with tags').build_input_mail() - self.client.add_mail_to_inbox(mail) - - self.post_tags(mail.ident, self._tags_json(['IMPORTANT'])) - - mails = self.get_mails_by_tag('inbox') - self.assertEquals({'important'}, set(mails[0].tags)) - - mails = self.get_mails_by_tag('important') - self.assertEquals('Mail with tags', mails[0].subject) - - def test_addition_of_reserved_tags_is_not_allowed(self): - mail = MailBuilder().with_subject('Mail with tags').build_input_mail() - self.client.add_mail_to_inbox(mail) - - for tag in TagService.SPECIAL_TAGS: - response = self.post_tags(mail.ident, self._tags_json([tag.name.upper()])) - self.assertEquals("None of the following words can be used as tags: %s" % tag.name, response) - - mail = self.client.mailboxes.inbox().mail(mail.ident) - self.assertNotIn('drafts', mail.tags) diff --git a/service/test/integration/test_contacts.py b/service/test/integration/test_contacts.py new file mode 100644 index 00000000..925e5e02 --- /dev/null +++ b/service/test/integration/test_contacts.py @@ -0,0 +1,54 @@ +# +# 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 . +from nose.twistedtools import deferred +from test.support.integration import SoledadTestBase, MailBuilder + + +class ContactsTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) + def test_TO_CC_and_BCC_fields_are_being_searched(self): + input_mail = MailBuilder().with_tags(['important']).build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + d = self.get_contacts(query='recipient') + + def _assert(contacts): + self.assertTrue('recipient@to.com' in contacts) + self.assertTrue('recipient@cc.com' in contacts) + self.assertTrue('recipient@bcc.com' in contacts) + d.addCallback(_assert) + return d + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) + def test_trash_and_drafts_mailboxes_are_being_ignored(self): + self.client.add_multiple_to_mailbox(1, mailbox='INBOX', to='recipient@inbox.com') + self.client.add_multiple_to_mailbox(1, mailbox='DRAFTS', to='recipient@drafts.com') + self.client.add_multiple_to_mailbox(1, mailbox='SENT', to='recipient@sent.com') + self.client.add_multiple_to_mailbox(1, mailbox='TRASH', to='recipient@trash.com') + + d = self.get_contacts(query='recipient') + + def _assert(contacts): + self.assertTrue('recipient@inbox.com' in contacts) + self.assertTrue('recipient@sent.com' in contacts) + self.assertFalse('recipient@drafts.com' in contacts) + self.assertFalse('recipient@trash.com' in contacts) + d.addCallback(_assert) + return d diff --git a/service/test/integration/test_delete_mail.py b/service/test/integration/test_delete_mail.py new file mode 100644 index 00000000..5a3a97fb --- /dev/null +++ b/service/test/integration/test_delete_mail.py @@ -0,0 +1,65 @@ +# +# 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 . + +from test.support.integration import * + + +class DeleteMailTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + def tearDown(self): + SoledadTestBase.tearDown(self) + + def test_move_mail_to_trash_when_deleting(self): + input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + inbox_mails = self.get_mails_by_tag('inbox') + self.assertEquals(1, len(inbox_mails)) + + self.delete_mail(input_mail.ident) + + inbox_mails = self.get_mails_by_tag('inbox') + self.assertEquals(0, len(inbox_mails)) + trash_mails = self.get_mails_by_tag('trash') + self.assertEquals(1, len(trash_mails)) + + def test_delete_mail_when_trashing_mail_from_trash_mailbox(self): + mails = self.client.add_multiple_to_mailbox(1, 'trash') + self.delete_mails([mails[0].ident]) + + trash_mails = self.get_mails_by_tag('trash') + + self.assertEqual(0, len(trash_mails)) + + def test_move_mail_to_trash_when_delete_multiple(self): + mails = self.client.add_multiple_to_mailbox(5, 'inbox') + mail_idents = [m.ident for m in mails] + + self.delete_mails(mail_idents) + + inbox = self.get_mails_by_tag('inbox') + self.assertEquals(0, len(inbox)) + + def test_delete_permanently_when_mails_are_in_trash(self): + mails = self.client.add_multiple_to_mailbox(5, 'trash') + self.delete_mails([m.ident for m in mails]) + + trash = self.get_mails_by_tag('trash') + + self.assertEquals(0, len(trash)) diff --git a/service/test/integration/test_drafts.py b/service/test/integration/test_drafts.py new file mode 100644 index 00000000..d4fde099 --- /dev/null +++ b/service/test/integration/test_drafts.py @@ -0,0 +1,84 @@ +# +# 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 . + +from test.support.integration import * + + +class DraftsTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + def tearDown(self): + SoledadTestBase.tearDown(self) + + def test_post_sends_mail_and_deletes_previous_draft_if_it_exists(self): + # creates one draft + first_draft = MailBuilder().with_subject('First draft').build_json() + first_draft_ident = self.put_mail(first_draft)[0]['ident'] + + # sends an updated version of the draft + second_draft = MailBuilder().with_subject('Second draft').with_ident(first_draft_ident).build_json() + self.post_mail(second_draft) + + sent_mails = self.get_mails_by_tag('sent') + drafts = self.get_mails_by_tag('drafts') + + # make sure there is one email in the sent mailbox and it is the second draft + self.assertEquals(1, len(sent_mails)) + self.assertEquals('Second draft', sent_mails[0].subject) + + # make sure that there are no drafts in the draft mailbox + self.assertEquals(0, len(drafts)) + + def test_post_sends_mail_even_when_draft_does_not_exist(self): + first_draft = MailBuilder().with_subject('First draft').build_json() + self.post_mail(first_draft) + + sent_mails = self.get_mails_by_tag('sent') + drafts = self.get_mails_by_tag('drafts') + + self.assertEquals(1, len(sent_mails)) + self.assertEquals('First draft', sent_mails[0].subject) + self.assertEquals(0, len(drafts)) + + def test_put_creates_a_draft_if_it_does_not_exist(self): + mail = MailBuilder().with_subject('A new draft').build_json() + self.put_mail(mail) + mails = self.get_mails_by_tag('drafts') + + self.assertEquals('A new draft', mails[0].subject) + + def test_put_updates_draft_if_it_already_exists(self): + draft = MailBuilder().with_subject('First draft').build_json() + draft_ident = self.put_mail(draft)[0]['ident'] + + updated_draft = MailBuilder().with_subject('First draft edited').with_ident(draft_ident).build_json() + self.put_mail(updated_draft) + + drafts = self.get_mails_by_tag('drafts') + + self.assertEquals(1, len(drafts)) + self.assertEquals('First draft edited', drafts[0].subject) + + def test_respond_unprocessable_entity_if_draft_to_remove_doesnt_exist(self): + draft = MailBuilder().with_subject('First draft').build_json() + self.put_mail(draft) + + updated_draft = MailBuilder().with_subject('First draft edited').with_ident('NOTFOUND').build_json() + _, request = self.put_mail(updated_draft) + + self.assertEquals(422, request.code) diff --git a/service/test/integration/test_mark_as_read_unread.py b/service/test/integration/test_mark_as_read_unread.py new file mode 100644 index 00000000..86a48e62 --- /dev/null +++ b/service/test/integration/test_mark_as_read_unread.py @@ -0,0 +1,104 @@ +# +# 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 . + +from test.support.integration import * +from pixelated.adapter.model.status import Status + + +class MarkAsReadUnreadTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + def tearDown(self): + SoledadTestBase.tearDown(self) + + def test_mark_single_as_read(self): + input_mail = MailBuilder().build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + mails = self.get_mails_by_tag('inbox') + self.assertNotIn('read', mails[0].status) + + self.mark_many_as_read([input_mail.ident]) + + mails = self.get_mails_by_tag('inbox') + self.assertIn('read', mails[0].status) + + def test_mark_single_as_unread(self): + input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + self.mark_many_as_unread([input_mail.ident]) + mail = self.get_mails_by_tag('inbox')[0] + + self.assertNotIn('read', mail.status) + + def test_mark_many_mails_as_unread(self): + input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail() + input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail() + + self.client.add_mail_to_inbox(input_mail) + self.client.add_mail_to_inbox(input_mail2) + + self.mark_many_as_unread([input_mail.ident, input_mail2.ident]) + + mails = self.get_mails_by_tag('inbox') + + self.assertNotIn('read', mails[0].status) + self.assertNotIn('read', mails[1].status) + + def test_mark_many_mails_as_read(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().build_input_mail() + + self.client.add_mail_to_inbox(input_mail) + self.client.add_mail_to_inbox(input_mail2) + + mails = self.get_mails_by_tag('inbox') + + self.assertNotIn('read', mails[0].status) + self.assertNotIn('read', mails[1].status) + + response = self.mark_many_as_read([input_mail.ident, input_mail2.ident]) + self.assertEquals(200, response.code) + + mails = self.get_mails_by_tag('inbox') + + self.assertIn('read', mails[0].status) + self.assertIn('read', mails[1].status) + + def test_mark_mixed_status_as_read(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail() + + self.client.add_mail_to_inbox(input_mail) + self.client.add_mail_to_inbox(input_mail2) + + mails = self.get_mails_by_tag('inbox') + + read_mails = filter(lambda x: 'read' in x.status, mails) + unread_mails = filter(lambda x: 'read' not in x.status, mails) + self.assertEquals(1, len(unread_mails)) + self.assertEquals(1, len(read_mails)) + + response = self.mark_many_as_read([input_mail.ident, input_mail2.ident]) + self.assertEquals(200, response.code) + + mails = self.get_mails_by_tag('inbox') + + self.assertIn('read', mails[0].status) + self.assertIn('read', mails[1].status) diff --git a/service/test/integration/test_retrieve_attachment.py b/service/test/integration/test_retrieve_attachment.py new file mode 100644 index 00000000..d6ad9298 --- /dev/null +++ b/service/test/integration/test_retrieve_attachment.py @@ -0,0 +1,45 @@ +# +# 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 . + +from test.support.integration.soledad_test_base import SoledadTestBase + + +class RetrieveAttachmentTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + def tearDown(self): + SoledadTestBase.tearDown(self) + + def test_attachment_content_is_retrieved(self): + ident = 'F4E99C1CEC4D300A4223A96CCABBE0304BDBC31C550A5A03E207A5E4C3C71A22' + attachment_dict = {'content-disposition': 'attachment', + 'content-transfer-encoding': '', + 'type': 'cnt', + 'raw': 'cGVxdWVubyBhbmV4byA6RAo=', + 'phash': ident, + 'content-type': 'text/plain; charset=US-ASCII; name="attachment_pequeno.txt"'} + + self.client.add_document_to_soledad(attachment_dict) + + d = self.get_attachment(ident, 'base64') + + def _assert(attachment): + self.assertEquals('pequeno anexo :D\n', attachment) + d.addCallback(_assert) + + return d diff --git a/service/test/integration/test_search.py b/service/test/integration/test_search.py new file mode 100644 index 00000000..464830d2 --- /dev/null +++ b/service/test/integration/test_search.py @@ -0,0 +1,144 @@ +# +# 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 . + +from nose.twistedtools import deferred +from test.support.integration import * + + +class SearchTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) + def test_that_tags_returns_all_tags(self): + input_mail = MailBuilder().with_tags(['important']).build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + d = self.get_tags() + + def _assert(all_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) + d.addCallback(_assert) + return d + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) + def test_that_tags_are_filtered_by_query(self): + input_mail = MailBuilder().with_tags(['ateu', 'catoa', 'luat', 'zuado']).build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + d = self.get_tags(q=["at"], skipDefaultTags=["true"]) + + def _assert(all_tags): + all_tag_names = [t['name'] for t in all_tags] + self.assertEqual(3, len(all_tag_names)) + self.assertTrue('ateu' in all_tag_names) + self.assertTrue('catoa' in all_tag_names) + self.assertTrue('luat' in all_tag_names) + + d.addCallback(_assert) + return d + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) + def test_that_default_tags_are_ignorable(self): + input_mail = MailBuilder().with_tags(['sometag']).build_input_mail() + self.client.add_mail_to_inbox(input_mail) + + d = self.get_tags(skipDefaultTags=["true"]) + + def _assert(all_tags): + all_tag_names = [t['name'] for t in all_tags] + self.assertEqual(1, len(all_tag_names)) + self.assertTrue('sometag' in all_tag_names) + d.addCallback(_assert) + return d + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT_LONG) + def test_tags_count(self): + self.client.add_multiple_to_mailbox(num=10, mailbox='inbox', flags=['\\Recent']) + self.client.add_multiple_to_mailbox(num=5, mailbox='inbox', flags=['\\Seen']) + self.client.add_multiple_to_mailbox(num=3, mailbox='inbox', flags=['\\Recent'], tags=['important', 'later']) + self.client.add_multiple_to_mailbox(num=1, mailbox='inbox', flags=['\\Seen'], tags=['important']) + + d = self.get_tags() + + def _assert(tags_count): + self.assertEqual(self.get_count(tags_count, 'inbox')['total'], 19) + self.assertEqual(self.get_count(tags_count, 'inbox')['read'], 6) + self.assertEqual(self.get_count(tags_count, 'important')['total'], 4) + self.assertEqual(self.get_count(tags_count, 'important')['read'], 1) + d.addCallback(_assert) + return d + + def test_search_mails_different_window(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().build_input_mail() + self.client.add_mail_to_inbox(input_mail) + self.client.add_mail_to_inbox(input_mail2) + + first_page = self.get_mails_by_tag('inbox', page=1, window=1) + + self.assertEqual(len(first_page), 1) + + def test_search_mails_with_multiple_pages(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().build_input_mail() + self.client.add_mail_to_inbox(input_mail) + self.client.add_mail_to_inbox(input_mail2) + + first_page = self.get_mails_by_tag('inbox', page=1, window=1) + second_page = self.get_mails_by_tag('inbox', page=2, window=1) + + idents = [input_mail.ident, input_mail2.ident] + + self.assertIn(first_page[0].ident, idents) + self.assertIn(second_page[0].ident, idents) + + def test_page_zero_fetches_first_page(self): + input_mail = MailBuilder().build_input_mail() + self.client.add_mail_to_inbox(input_mail) + page = self.get_mails_by_tag('inbox', page=0, window=1) + self.assertEqual(page[0].ident, input_mail.ident) + + def get_count(self, tags_count, mailbox): + for tag in tags_count: + if tag['name'] == mailbox: + return tag['counts'] + + def test_order_by_date(self): + input_mail = MailBuilder().with_date('2014-10-15T15:15').build_input_mail() + input_mail2 = MailBuilder().with_date('2014-10-15T15:16').build_input_mail() + + self.client.add_mail_to_inbox(input_mail) + self.client.add_mail_to_inbox(input_mail2) + + results = self.get_mails_by_tag('inbox') + self.assertEqual(results[0].ident, input_mail2.ident) + self.assertEqual(results[1].ident, input_mail.ident) + + def test_search_base64_body(self): + body = u'bl\xe1' + input_mail = MailBuilder().with_body(body.encode('utf-8')).build_input_mail() + self.client.add_mail_to_inbox(input_mail) + results = self.search(body) + + self.assertGreater(len(results), 0, 'No results returned from search') + self.assertEquals(results[0].ident, input_mail.ident) diff --git a/service/test/integration/test_soledad_querier.py b/service/test/integration/test_soledad_querier.py new file mode 100644 index 00000000..f8767630 --- /dev/null +++ b/service/test/integration/test_soledad_querier.py @@ -0,0 +1,88 @@ +# +# 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 . + +import copy +import time + +from test.support.integration import * +from leap.mail.imap.fields import WithMsgFields + + +class SoledadQuerierTest(SoledadTestBase, WithMsgFields): + + def setUp(self): + SoledadTestBase.setUp(self) + self.soledad = self.client.soledad + self.maxDiff = None + self.soledad_querier = self.client.soledad_querier + + def tearDown(self): + SoledadTestBase.tearDown(self) + + def _get_empty_mailbox(self): + return copy.deepcopy(self.EMPTY_MBOX) + + def _create_mailbox(self, mailbox_name): + new_mailbox = self._get_empty_mailbox() + new_mailbox['mbox'] = mailbox_name + new_mailbox['created'] = int(time.time() * 10E2) + return self.soledad.create_doc(new_mailbox) + + def _get_mailboxes_from_soledad(self, mailbox_name): + return [m for m in self.soledad.get_from_index('by-type', 'mbox') if m.content['mbox'] == mailbox_name] + + def test_remove_dup_mailboxes_keeps_the_one_with_the_highest_last_uid(self): + self.client.add_multiple_to_mailbox(3, 'INBOX') # by now we already have one inbox with 3 mails + self._create_mailbox('INBOX') # now we have a duplicate + + # make sure we have two + inboxes = self._get_mailboxes_from_soledad('INBOX') + self.assertEqual(2, len(inboxes)) + + self.soledad_querier.remove_duplicates() + + # make sure we only have one, and the one with the right lastuid + inboxes = self._get_mailboxes_from_soledad('INBOX') + self.assertEqual(1, len(inboxes)) + self.assertEqual(3, inboxes[0].content['lastuid']) + + def test_all_mails_skips_incomplete_mails(self): + # creating incomplete mail, we will only save the fdoc + fdoc, hdoc, bdoc = MailBuilder().build_input_mail().get_for_save(1, 'INBOX') + self.soledad.create_doc(fdoc) + + mails = self.soledad_querier.all_mails() + self.assertEqual(0, len(mails)) # mail is incomplete since it only has fdoc + + # adding the hdoc still doesn't complete the mail + self.soledad.create_doc(hdoc) + + mails = self.soledad_querier.all_mails() + self.assertEqual(0, len(mails)) + + # now the mail is complete + self.soledad.create_doc(bdoc) + + mails = self.soledad_querier.all_mails() + self.assertEqual(1, len(mails)) + + def test_get_mails_by_chash(self): + mails = self.client.add_multiple_to_mailbox(3, 'INBOX') + chashes = [mail.ident for mail in mails] + + fetched_mails = self.soledad_querier.mails(chashes) + + self.assertEquals([m.as_dict() for m in fetched_mails], [m.as_dict() for m in mails]) diff --git a/service/test/integration/test_tags.py b/service/test/integration/test_tags.py new file mode 100644 index 00000000..6072392c --- /dev/null +++ b/service/test/integration/test_tags.py @@ -0,0 +1,54 @@ +# +# 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 . +import json + +from test.support.integration import * +from pixelated.adapter.services.tag_service import TagService + + +class TagsTest(SoledadTestBase): + + def setUp(self): + SoledadTestBase.setUp(self) + + def tearDown(self): + SoledadTestBase.tearDown(self) + + def _tags_json(self, tags): + return json.dumps({'newtags': tags}) + + def test_add_tag_to_an_inbox_mail_and_query(self): + mail = MailBuilder().with_subject('Mail with tags').build_input_mail() + self.client.add_mail_to_inbox(mail) + + self.post_tags(mail.ident, self._tags_json(['IMPORTANT'])) + + mails = self.get_mails_by_tag('inbox') + self.assertEquals({'important'}, set(mails[0].tags)) + + mails = self.get_mails_by_tag('important') + self.assertEquals('Mail with tags', mails[0].subject) + + def test_addition_of_reserved_tags_is_not_allowed(self): + mail = MailBuilder().with_subject('Mail with tags').build_input_mail() + self.client.add_mail_to_inbox(mail) + + for tag in TagService.SPECIAL_TAGS: + response = self.post_tags(mail.ident, self._tags_json([tag.name.upper()])) + self.assertEquals("None of the following words can be used as tags: %s" % tag.name, response) + + mail = self.client.mailboxes.inbox().mail(mail.ident) + self.assertNotIn('drafts', mail.tags) -- cgit v1.2.3