From 0bad14f4b0e6dd5128660d94a436463cbe7dc720 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Thu, 9 Oct 2014 12:03:31 +0200 Subject: Changing tests folder structure --- service/integration/__init__.py | 174 ------------------------------- service/integration/delete_mail_test.py | 40 ------- service/integration/drafts_test.py | 62 ----------- service/integration/mark_as_read_test.py | 38 ------- service/integration/tags_test.py | 52 --------- 5 files changed, 366 deletions(-) delete mode 100644 service/integration/__init__.py delete mode 100644 service/integration/delete_mail_test.py delete mode 100644 service/integration/drafts_test.py delete mode 100644 service/integration/mark_as_read_test.py delete mode 100644 service/integration/tags_test.py (limited to 'service/integration') diff --git a/service/integration/__init__.py b/service/integration/__init__.py deleted file mode 100644 index 7691447d..00000000 --- a/service/integration/__init__.py +++ /dev/null @@ -1,174 +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 leap.soledad.client import Soledad -from mockito import mock -import os -from mock import Mock -import shutil -from pixelated.adapter.mail_service import MailService -from pixelated.adapter.tag_index import TagIndex -from pixelated.adapter.tag_service import TagService -import pixelated.user_agent -from pixelated.adapter.pixelated_mail import PixelatedMail, InputMail -from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes -from pixelated.adapter.soledad_querier import SoledadQuerier - -soledad_test_folder = "soledad-test" - - -class FakeAccount: - def __init__(self): - self.mailboxes = ['INBOX', 'DRAFTS', 'SENT', 'TRASH'] - - -def initialize_soledad(tempdir): - uuid = "foobar-uuid" - passphrase = u"verysecretpassphrase" - secret_path = os.path.join(tempdir, "secret.gpg") - local_db_path = os.path.join(tempdir, "soledad.u1db") - server_url = "http://provider" - cert_file = "" - - class MockSharedDB(object): - - get_doc = Mock(return_value=None) - put_doc = Mock() - lock = Mock(return_value=('atoken', 300)) - unlock = Mock(return_value=True) - - def __call__(self): - return self - - Soledad._shared_db = MockSharedDB() - - _soledad = Soledad( - uuid, - passphrase, - secret_path, - local_db_path, - server_url, - cert_file) - - from leap.mail.imap.fields import fields - for name, expression in fields.INDEXES.items(): - _soledad.create_index(name, *expression) - - return _soledad - - -class MailBuilder: - def __init__(self): - self.mail = { - 'header': { - 'to': ['recipient@to.com'], - 'cc': ['recipient@cc.com'], - 'bcc': ['recipient@bcc.com'], - 'subject': 'Hi! This the subject' - }, - 'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n" - } - - def with_body(self, body): - self.mail['body'] = body - return self - - def with_subject(self, subject): - self.mail['header']['subject'] = subject - return self - - def with_ident(self, ident): - self.mail['ident'] = ident - return self - - def build_json(self): - return json.dumps(self.mail) - - def build_input_mail(self): - return InputMail.from_dict(self.mail) - - -class SoledadTestBase: - - def teardown_soledad(self): - self.soledad.close() - shutil.rmtree(soledad_test_folder) - - def setup_soledad(self): - self.soledad = initialize_soledad(tempdir=soledad_test_folder) - self.mail_address = "test@pixelated.org" - - SoledadQuerier.instance = None - SoledadQuerier.get_instance(soledad=self.soledad) - PixelatedMail.from_email_address = self.mail_address - - self.app = pixelated.user_agent.app.test_client() - self.account = FakeAccount() - self.mail_sender = mock() - self.tag_index = TagIndex(os.path.join(soledad_test_folder, 'tag_index')) - self.tag_service = TagService(self.tag_index) - self.pixelated_mailboxes = PixelatedMailBoxes(self.account) - self.mail_service = MailService(self.pixelated_mailboxes, self.mail_sender, self.tag_service) - - pixelated.user_agent.mail_service = self.mail_service - - def get_mails_by_tag(self, tag): - response = json.loads(self.app.get("/mails?q=tag:" + tag).data) - return [ResponseMail(m) for m in response['mails']] - - def post_mail(self, data): - response = json.loads(self.app.post('/mails', data=data, content_type="application/json").data) - return ResponseMail(response) - - def put_mail(self, data): - response = json.loads(self.app.put('/mails', data=data, content_type="application/json").data) - return response['ident'] - - def post_tags(self, mail_ident, tags_json): - return json.loads(self.app.post('/mail/' + mail_ident + '/tags', data=tags_json, content_type="application/json").data) - - def delete_mail(self, mail_ident): - self.app.delete('/mail/' + mail_ident) - - def mark_as_read(self, mail_ident): - self.app.post('/mail/' + mail_ident + '/read', content_type="application/json") - - -class ResponseMail: - - def __init__(self, mail_dict): - self.mail_dict = mail_dict - - @property - def subject(self): - return self.headers['subject'] - - @property - def headers(self): - return self.mail_dict['header'] - - @property - def ident(self): - return self.mail_dict['ident'] - - @property - def tags(self): - return self.mail_dict['tags'] - - @property - def status(self): - return self.mail_dict['status'] \ No newline at end of file diff --git a/service/integration/delete_mail_test.py b/service/integration/delete_mail_test.py deleted file mode 100644 index e7e08c31..00000000 --- a/service/integration/delete_mail_test.py +++ /dev/null @@ -1,40 +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 unittest -from integration import MailBuilder, SoledadTestBase - - -class DeleteMailTest(unittest.TestCase, SoledadTestBase): - - def setUp(self): - self.setup_soledad() - - def tearDown(self): - self.teardown_soledad() - - def test_move_mail_to_trash_when_deleting(self): - mail = MailBuilder().with_subject('Mail with tags').build_input_mail() - self.pixelated_mailboxes.inbox().add(mail) - - inbox_mails = self.get_mails_by_tag('inbox') - self.assertEquals(1, len(inbox_mails)) - - self.delete_mail(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)) diff --git a/service/integration/drafts_test.py b/service/integration/drafts_test.py deleted file mode 100644 index 64581768..00000000 --- a/service/integration/drafts_test.py +++ /dev/null @@ -1,62 +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 unittest -from integration import MailBuilder, SoledadTestBase - - -class DraftsTest(unittest.TestCase, SoledadTestBase): - - def setUp(self): - self.setup_soledad() - - def tearDown(self): - self.teardown_soledad() - - def test_post_creates_a_draft_when_data_has_no_ident(self): - mail = MailBuilder().with_subject('A new draft').build_json() - - self.post_mail(mail) - mails = self.get_mails_by_tag('drafts') - - self.assertEquals('A new draft', mails[0].subject) - - def test_post_sends_mail_and_deletes_previous_draft_when_data_has_ident(self): - first_draft = MailBuilder().with_subject('First draft').build_json() - first_draft_response = self.post_mail(first_draft) - first_draft_ident = first_draft_response.ident - - 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') - - self.assertEquals(1, len(sent_mails)) - self.assertEquals('Second draft', sent_mails[0].subject) - self.assertEquals(0, len(drafts)) - - def test_update_draft(self): - draft = MailBuilder().with_subject('First draft').build_json() - create_draft_response = self.post_mail(draft) - draft_ident = create_draft_response.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) diff --git a/service/integration/mark_as_read_test.py b/service/integration/mark_as_read_test.py deleted file mode 100644 index 60084efa..00000000 --- a/service/integration/mark_as_read_test.py +++ /dev/null @@ -1,38 +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 unittest -from integration import MailBuilder, SoledadTestBase - - -class MarkAsReadTest(unittest.TestCase, SoledadTestBase): - - def setUp(self): - self.setup_soledad() - - def tearDown(self): - self.teardown_soledad() - - def test_mark_as_read(self): - input_mail = MailBuilder().build_input_mail() - self.pixelated_mailboxes.inbox().add(input_mail) - - mails = self.get_mails_by_tag('inbox') - self.assertFalse('read' in mails[0].status) - - self.mark_as_read(input_mail.ident) - - mails = self.get_mails_by_tag('inbox') - self.assertTrue('read' in mails[0].status) diff --git a/service/integration/tags_test.py b/service/integration/tags_test.py deleted file mode 100644 index b313caec..00000000 --- a/service/integration/tags_test.py +++ /dev/null @@ -1,52 +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 -import unittest -from integration import MailBuilder, SoledadTestBase - - -class TagsTest(unittest.TestCase, SoledadTestBase): - - def setUp(self): - self.setup_soledad() - - def tearDown(self): - self.teardown_soledad() - - 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.pixelated_mailboxes.inbox().add(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.pixelated_mailboxes.inbox().add(mail) - - response = self.post_tags(mail.ident, self._tags_json(['DRAFTS'])) - self.assertEquals("None of the following words can be used as tags: drafts", response) - - mail = self.pixelated_mailboxes.inbox().mail(mail.ident) - self.assertNotIn('drafts', mail.tags) -- cgit v1.2.3