diff options
Diffstat (limited to 'service/test/integration')
-rw-r--r-- | service/test/integration/test_contacts.py | 1 | ||||
-rw-r--r-- | service/test/integration/test_delete_mail.py | 13 | ||||
-rw-r--r-- | service/test/integration/test_drafts.py | 30 | ||||
-rw-r--r-- | service/test/integration/test_feedback_service.py | 2 | ||||
-rw-r--r-- | service/test/integration/test_logout.py | 6 | ||||
-rw-r--r-- | service/test/integration/test_mark_as_read_unread.py | 29 | ||||
-rw-r--r-- | service/test/integration/test_multi_user_login.py | 8 | ||||
-rw-r--r-- | service/test/integration/test_retrieve_attachment.py | 4 | ||||
-rw-r--r-- | service/test/integration/test_static_files.py | 27 | ||||
-rw-r--r-- | service/test/integration/test_tags.py | 23 | ||||
-rw-r--r-- | service/test/integration/test_users_count.py | 5 |
11 files changed, 36 insertions, 112 deletions
diff --git a/service/test/integration/test_contacts.py b/service/test/integration/test_contacts.py index a890466f..946818fd 100644 --- a/service/test/integration/test_contacts.py +++ b/service/test/integration/test_contacts.py @@ -16,6 +16,7 @@ from test.support.integration import SoledadTestBase, MailBuilder from twisted.internet import defer import json +import pkg_resources class ContactsTest(SoledadTestBase): diff --git a/service/test/integration/test_delete_mail.py b/service/test/integration/test_delete_mail.py index 34ea5048..a912f9f0 100644 --- a/service/test/integration/test_delete_mail.py +++ b/service/test/integration/test_delete_mail.py @@ -15,7 +15,6 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from twisted.internet import defer from test.support.integration import SoledadTestBase, MailBuilder -from pixelated.resources import IPixelatedSession class DeleteMailTest(SoledadTestBase): @@ -28,8 +27,7 @@ class DeleteMailTest(SoledadTestBase): inbox_mails = yield self.app_test_client.get_mails_by_tag('inbox') self.assertEquals(1, len(inbox_mails)) - response, first_request = yield self.app_test_client.get('/', as_json=False) - yield self.app_test_client.delete_mail(mail.mail_id, session=first_request.getSession()) + yield self.app_test_client.delete_mail(mail.mail_id) inbox_mails = yield self.app_test_client.get_mails_by_tag('inbox') self.assertEquals(0, len(inbox_mails)) @@ -39,8 +37,7 @@ class DeleteMailTest(SoledadTestBase): @defer.inlineCallbacks def test_delete_mail_when_trashing_mail_from_trash_mailbox(self): mails = yield self.app_test_client.add_multiple_to_mailbox(1, 'trash') - response, first_request = yield self.app_test_client.get('/', as_json=False) - yield self.app_test_client.delete_mails([mails[0].ident], session=first_request.getSession()) + yield self.app_test_client.delete_mails([mails[0].ident]) trash_mails = yield self.app_test_client.get_mails_by_tag('trash') @@ -52,8 +49,7 @@ class DeleteMailTest(SoledadTestBase): mails = yield self.app_test_client.add_multiple_to_mailbox(5, 'inbox') mail_idents = [m.ident for m in mails] - response, first_request = yield self.app_test_client.get('/', as_json=False) - yield self.app_test_client.delete_mails(mail_idents, session=first_request.getSession()) + yield self.app_test_client.delete_mails(mail_idents) inbox = yield self.app_test_client.get_mails_by_tag('inbox') self.assertEquals(0, len(inbox)) @@ -63,8 +59,7 @@ class DeleteMailTest(SoledadTestBase): mails = yield self.app_test_client.add_multiple_to_mailbox(5, 'trash') mail_idents = [m.ident for m in mails] - response, first_request = yield self.app_test_client.get('/', as_json=False) - yield self.app_test_client.delete_mails(mail_idents, session=first_request.getSession()) + yield self.app_test_client.delete_mails(mail_idents) trash = yield self.app_test_client.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 index a9c7b3f7..657cfab1 100644 --- a/service/test/integration/test_drafts.py +++ b/service/test/integration/test_drafts.py @@ -17,7 +17,6 @@ from test.support.integration import SoledadTestBase, MailBuilder from mockito import unstub, when, any from twisted.internet import defer -from pixelated.resources import IPixelatedSession class DraftsTest(SoledadTestBase): @@ -27,20 +26,17 @@ class DraftsTest(SoledadTestBase): @defer.inlineCallbacks def test_post_sends_mail_and_deletes_previous_draft_if_it_exists(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - # act as if sending the mail by SMTP succeeded sendmail_deferred = defer.Deferred() when(self.app_test_client.mail_sender).sendmail(any()).thenReturn(sendmail_deferred) # creates one draft first_draft = MailBuilder().with_subject('First draft').build_json() - first_draft_ident = (yield self.app_test_client.put_mail(first_draft, session=session)[0])['ident'] + first_draft_ident = (yield self.app_test_client.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() - deferred_res = self.post_mail(second_draft, session) + deferred_res = self.post_mail(second_draft) sendmail_deferred.callback(None) # SMTP succeeded @@ -58,15 +54,12 @@ class DraftsTest(SoledadTestBase): @defer.inlineCallbacks def test_post_sends_mail_even_when_draft_does_not_exist(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - # act as if sending the mail by SMTP succeeded sendmail_deferred = defer.Deferred() when(self.app_test_client.mail_sender).sendmail(any()).thenReturn(sendmail_deferred) first_draft = MailBuilder().with_subject('First draft').build_json() - res = self.post_mail(first_draft, session) + res = self.post_mail(first_draft) sendmail_deferred.callback(True) yield res @@ -77,32 +70,25 @@ class DraftsTest(SoledadTestBase): self.assertEquals('First draft', sent_mails[0].subject) self.assertEquals(0, len(drafts)) - def post_mail(self, data, session): - csrf = IPixelatedSession(session).get_csrf_token() - deferred_res, req = self.app_test_client.post('/mails', data, csrf=csrf, session=session) + def post_mail(self, data): + deferred_res, req = self.app_test_client.post('/mails', data) return deferred_res @defer.inlineCallbacks def test_put_creates_a_draft_if_it_does_not_exist(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - mail = MailBuilder().with_subject('A new draft').build_json() - yield self.app_test_client.put_mail(mail, session=session)[0] + yield self.app_test_client.put_mail(mail)[0] mails = yield self.app_test_client.get_mails_by_tag('drafts') self.assertEquals('A new draft', mails[0].subject) @defer.inlineCallbacks def test_put_updates_draft_if_it_already_exists(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - draft = MailBuilder().with_subject('First draft').build_json() - draft_ident = (yield self.app_test_client.put_mail(draft, session=session)[0])['ident'] + draft_ident = (yield self.app_test_client.put_mail(draft)[0])['ident'] updated_draft = MailBuilder().with_subject('First draft edited').with_ident(draft_ident).build_json() - yield self.app_test_client.put_mail(updated_draft, session=session)[0] + yield self.app_test_client.put_mail(updated_draft)[0] drafts = yield self.app_test_client.get_mails_by_tag('drafts') diff --git a/service/test/integration/test_feedback_service.py b/service/test/integration/test_feedback_service.py index ff659396..c50c1883 100644 --- a/service/test/integration/test_feedback_service.py +++ b/service/test/integration/test_feedback_service.py @@ -1,4 +1,4 @@ -from twisted.trial import unittest +import unittest from httmock import urlmatch, HTTMock from mockito import when from twisted.internet import defer diff --git a/service/test/integration/test_logout.py b/service/test/integration/test_logout.py index 92c2afe5..c9d39d17 100644 --- a/service/test/integration/test_logout.py +++ b/service/test/integration/test_logout.py @@ -29,8 +29,7 @@ class MultiUserLogoutTest(MultiUserSoledadTestBase): @defer.inlineCallbacks def test_logout_deletes_services_stop_background_reactor_tasks_and_closes_soledad(self): - response, first_request = yield self.app_test_client.get('/login', as_json=False) - response, login_request = yield self.app_test_client.login(session=first_request.getSession()) + response, login_request = yield self.app_test_client.login() yield response yield self.wait_for_session_user_id_to_finish() @@ -38,8 +37,7 @@ class MultiUserLogoutTest(MultiUserSoledadTestBase): response, request = self.app_test_client.post( "/logout", json.dumps({'csrftoken': [login_request.getCookie('XSRF-TOKEN')]}), - ajax=False, - session=login_request.getSession(), + from_request=login_request, as_json=False) yield response diff --git a/service/test/integration/test_mark_as_read_unread.py b/service/test/integration/test_mark_as_read_unread.py index c01deefc..18c3ddc2 100644 --- a/service/test/integration/test_mark_as_read_unread.py +++ b/service/test/integration/test_mark_as_read_unread.py @@ -30,40 +30,32 @@ class MarkAsReadUnreadTest(SoledadTestBase): mails = yield self.app_test_client.get_mails_by_tag('inbox') self.assertNotIn('read', mails[0].status) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - yield self.app_test_client.mark_many_as_read([mail.ident], session) + yield self.app_test_client.mark_many_as_read([mail.ident]) mails = yield self.app_test_client.get_mails_by_tag('inbox') self.assertIn('read', mails[0].status) @defer.inlineCallbacks def test_mark_single_as_unread(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - input_mail = MailBuilder().build_input_mail() mail = yield self.app_test_client.add_mail_to_inbox(input_mail) - yield self.app_test_client.mark_many_as_read([mail.ident], session) + yield self.app_test_client.mark_many_as_read([mail.ident]) - yield self.app_test_client.mark_many_as_unread([mail.ident], session) + yield self.app_test_client.mark_many_as_unread([mail.ident]) result = (yield self.app_test_client.get_mails_by_tag('inbox'))[0] self.assertNotIn('read', result.status) @defer.inlineCallbacks def test_mark_many_mails_as_unread(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail() input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail() mail1 = yield self.app_test_client.add_mail_to_inbox(input_mail) mail2 = yield self.app_test_client.add_mail_to_inbox(input_mail2) - yield self.app_test_client.mark_many_as_read([mail1.ident, mail2.ident], session) + yield self.app_test_client.mark_many_as_read([mail1.ident, mail2.ident]) - yield self.app_test_client.mark_many_as_unread([mail1.ident, mail2.ident], session) + yield self.app_test_client.mark_many_as_unread([mail1.ident, mail2.ident]) mails = yield self.app_test_client.get_mails_by_tag('inbox') @@ -83,9 +75,7 @@ class MarkAsReadUnreadTest(SoledadTestBase): self.assertNotIn('read', mails[0].status) self.assertNotIn('read', mails[1].status) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - yield self.app_test_client.mark_many_as_read([mails[0].ident, mails[1].ident], session) + yield self.app_test_client.mark_many_as_read([mails[0].ident, mails[1].ident]) mails = yield self.app_test_client.get_mails_by_tag('inbox') @@ -94,15 +84,12 @@ class MarkAsReadUnreadTest(SoledadTestBase): @defer.inlineCallbacks def test_mark_mixed_status_as_read(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - input_mail = MailBuilder().with_subject('first').build_input_mail() input_mail2 = MailBuilder().with_subject('second').build_input_mail() yield self.app_test_client.add_mail_to_inbox(input_mail) mail2 = yield self.app_test_client.add_mail_to_inbox(input_mail2) - yield self.app_test_client.mark_many_as_read([mail2.ident], session) + yield self.app_test_client.mark_many_as_read([mail2.ident]) mails = yield self.app_test_client.get_mails_by_tag('inbox') @@ -111,7 +98,7 @@ class MarkAsReadUnreadTest(SoledadTestBase): self.assertEquals(1, len(unread_mails)) self.assertEquals(1, len(read_mails)) - yield self.app_test_client.mark_many_as_read([mails[0].ident, mails[1].ident], session) + yield self.app_test_client.mark_many_as_read([mails[0].ident, mails[1].ident]) mails = yield self.app_test_client.get_mails_by_tag('inbox') diff --git a/service/test/integration/test_multi_user_login.py b/service/test/integration/test_multi_user_login.py index 2008b320..fe456583 100644 --- a/service/test/integration/test_multi_user_login.py +++ b/service/test/integration/test_multi_user_login.py @@ -33,14 +33,13 @@ class MultiUserLoginTest(MultiUserSoledadTestBase): @defer.inlineCallbacks def test_logged_in_users_sees_resources(self): - response, first_request = yield self.app_test_client.get('/login', as_json=False) - response, login_request = yield self.app_test_client.login(session=first_request.getSession()) + response, login_request = yield self.app_test_client.login() yield response mail = load_mail_from_file('mbox00000000') mail_id = yield self._create_mail_in_soledad(mail) expected_mail_dict = {'body': u'Dignissimos ducimus veritatis. Est tenetur consequatur quia occaecati. Vel sit sit voluptas.\n\nEarum distinctio eos. Accusantium qui sint ut quia assumenda. Facere dignissimos inventore autem sit amet. Pariatur voluptatem sint est.\n\nUt recusandae praesentium aspernatur. Exercitationem amet placeat deserunt quae consequatur eum. Unde doloremque suscipit quia.\n\n', 'header': {u'date': u'Tue, 21 Apr 2015 08:43:27 +0000 (UTC)', u'to': [u'carmel@murazikortiz.name'], u'x-tw-pixelated-tags': u'nite, macro, trash', u'from': u'darby.senger@zemlak.biz', u'subject': u'Itaque consequatur repellendus provident sunt quia.'}, 'ident': mail_id, 'status': [], 'tags': [], 'textPlainBody': u'Dignissimos ducimus veritatis. Est tenetur consequatur quia occaecati. Vel sit sit voluptas.\n\nEarum distinctio eos. Accusantium qui sint ut quia assumenda. Facere dignissimos inventore autem sit amet. Pariatur voluptatem sint est.\n\nUt recusandae praesentium aspernatur. Exercitationem amet placeat deserunt quae consequatur eum. Unde doloremque suscipit quia.\n\n', 'mailbox': u'inbox', 'attachments': [], 'security_casing': {'imprints': [{'state': 'no_signature_information'}], 'locks': []}} - response, request = self.app_test_client.get("/mail/%s" % mail_id, session=login_request.getSession()) + response, request = self.app_test_client.get("/mail/%s" % mail_id, from_request=login_request) response = yield response self.assertEqual(200, request.code) @@ -49,8 +48,7 @@ class MultiUserLoginTest(MultiUserSoledadTestBase): @defer.inlineCallbacks def test_wrong_credentials_cannot_access_resources(self): - response, first_request = yield self.app_test_client.get('/login', as_json=False) - response, login_request = self.app_test_client.login('username', 'wrong_password', session=first_request.getSession()) + response, login_request = self.app_test_client.login('username', 'wrong_password') response_str = yield response self.assertEqual(401, login_request.responseCode) self.assertIn('Invalid username or password', login_request.written) diff --git a/service/test/integration/test_retrieve_attachment.py b/service/test/integration/test_retrieve_attachment.py index ac6e52e7..b46d40d5 100644 --- a/service/test/integration/test_retrieve_attachment.py +++ b/service/test/integration/test_retrieve_attachment.py @@ -86,9 +86,7 @@ class RetrieveAttachmentTest(SoledadTestBase): datagen, headers = multipart_encode([file]) post_data = "".join(datagen) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - _, req = yield self.app_test_client.post_attachment(post_data, headers, session) + _, req = yield self.app_test_client.post_attachment(post_data, headers) self.assertEqual(201, req.code) self.assertEqual('/attachment/B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A', req.responseHeaders.getRawHeaders('location')[0]) diff --git a/service/test/integration/test_static_files.py b/service/test/integration/test_static_files.py deleted file mode 100644 index e3fa8af5..00000000 --- a/service/test/integration/test_static_files.py +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright (c) 2016 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/>. - - -from twisted.internet.defer import inlineCallbacks -from test.support.integration import SoledadTestBase - - -class StaticFilesTest(SoledadTestBase): - - @inlineCallbacks - def test_should_find_static_file(self): - _, request = yield self.app_test_client.get('/static/js/main.js', as_json=False, ajax=False) - self.assertEqual(200, request.responseCode) diff --git a/service/test/integration/test_tags.py b/service/test/integration/test_tags.py index d107e320..555a7382 100644 --- a/service/test/integration/test_tags.py +++ b/service/test/integration/test_tags.py @@ -31,9 +31,7 @@ class TagsTest(SoledadTestBase): input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() mail = yield self.app_test_client.add_mail_to_inbox(input_mail) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - yield self.app_test_client.post_tags(mail.ident, self._tags_json(['IMPORTANT']), session) + yield self.app_test_client.post_tags(mail.ident, self._tags_json(['IMPORTANT'])) mails = yield self.app_test_client.get_mails_by_tag('inbox') self.assertEquals({'IMPORTANT'}, set(mails[0].tags)) @@ -43,18 +41,15 @@ class TagsTest(SoledadTestBase): @defer.inlineCallbacks def test_use_old_casing_when_same_tag_with_different_casing_is_posted(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() mail = yield self.app_test_client.add_mail_to_inbox(input_mail) - yield self.app_test_client.post_tags(mail.ident, self._tags_json(['ImPoRtAnT']), session) + yield self.app_test_client.post_tags(mail.ident, self._tags_json(['ImPoRtAnT'])) mails = yield self.app_test_client.get_mails_by_tag('ImPoRtAnT') self.assertEquals({'ImPoRtAnT'}, set(mails[0].tags)) another_input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() another_mail = yield self.app_test_client.add_mail_to_inbox(another_input_mail) - yield self.app_test_client.post_tags(another_mail.ident, self._tags_json(['IMPORTANT']), session) + yield self.app_test_client.post_tags(another_mail.ident, self._tags_json(['IMPORTANT'])) mails = yield self.app_test_client.get_mails_by_tag('IMPORTANT') self.assertEquals(0, len(mails)) mails = yield self.app_test_client.get_mails_by_tag('ImPoRtAnT') @@ -67,9 +62,7 @@ class TagsTest(SoledadTestBase): input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() mail = yield self.app_test_client.add_mail_to_inbox(input_mail) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - yield self.app_test_client.post_tags(mail.ident, self._tags_json(['ImPoRtAnT']), session) + yield self.app_test_client.post_tags(mail.ident, self._tags_json(['ImPoRtAnT'])) mails = yield self.app_test_client.get_mails_by_tag('important') self.assertEquals(0, len(mails)) @@ -85,9 +78,7 @@ class TagsTest(SoledadTestBase): input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() mail = yield self.app_test_client.add_mail_to_inbox(input_mail) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() - yield self.app_test_client.post_tags(mail.ident, self._tags_json(['tag1', ' ']), session) + yield self.app_test_client.post_tags(mail.ident, self._tags_json(['tag1', ' '])) mail = yield self.app_test_client.get_mail(mail.ident) @@ -98,10 +89,8 @@ class TagsTest(SoledadTestBase): input_mail = MailBuilder().with_subject('Mail with tags').build_input_mail() mail = yield self.app_test_client.add_mail_to_inbox(input_mail) - response, first_request = yield self.app_test_client.get('/', as_json=False) - session = first_request.getSession() for tag in SPECIAL_TAGS: - response = yield self.app_test_client.post_tags(mail.ident, self._tags_json([tag.name.upper()]), session) + response = yield self.app_test_client.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 = yield self.app_test_client.mail_store.get_mail(mail.ident) diff --git a/service/test/integration/test_users_count.py b/service/test/integration/test_users_count.py index a9813b2c..a03adacf 100644 --- a/service/test/integration/test_users_count.py +++ b/service/test/integration/test_users_count.py @@ -31,8 +31,7 @@ class UsersResourceTest(MultiUserSoledadTestBase): @defer.inlineCallbacks def test_online_users_count_uses_leap_auth_privileges(self): - response, first_request = yield self.app_test_client.get('/', as_json=False) - response, login_request = yield self.app_test_client.login(session=first_request.getSession()) + response, login_request = yield self.app_test_client.login() yield response yield self.wait_for_session_user_id_to_finish() @@ -41,7 +40,7 @@ class UsersResourceTest(MultiUserSoledadTestBase): response, request = self.app_test_client.get( "/users", json.dumps({'csrftoken': [login_request.getCookie('XSRF-TOKEN')]}), - session=login_request.getSession(), + from_request=login_request, as_json=False) yield response |