summaryrefslogtreecommitdiff
path: root/service/test/integration
diff options
context:
space:
mode:
Diffstat (limited to 'service/test/integration')
-rw-r--r--service/test/integration/test_contacts.py1
-rw-r--r--service/test/integration/test_delete_mail.py13
-rw-r--r--service/test/integration/test_drafts.py30
-rw-r--r--service/test/integration/test_feedback_service.py2
-rw-r--r--service/test/integration/test_logout.py6
-rw-r--r--service/test/integration/test_mark_as_read_unread.py29
-rw-r--r--service/test/integration/test_multi_user_login.py8
-rw-r--r--service/test/integration/test_retrieve_attachment.py4
-rw-r--r--service/test/integration/test_static_files.py27
-rw-r--r--service/test/integration/test_tags.py23
-rw-r--r--service/test/integration/test_users_count.py5
11 files changed, 112 insertions, 36 deletions
diff --git a/service/test/integration/test_contacts.py b/service/test/integration/test_contacts.py
index 946818fd..a890466f 100644
--- a/service/test/integration/test_contacts.py
+++ b/service/test/integration/test_contacts.py
@@ -16,7 +16,6 @@
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 a912f9f0..34ea5048 100644
--- a/service/test/integration/test_delete_mail.py
+++ b/service/test/integration/test_delete_mail.py
@@ -15,6 +15,7 @@
# 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):
@@ -27,7 +28,8 @@ class DeleteMailTest(SoledadTestBase):
inbox_mails = yield self.app_test_client.get_mails_by_tag('inbox')
self.assertEquals(1, len(inbox_mails))
- yield self.app_test_client.delete_mail(mail.mail_id)
+ 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())
inbox_mails = yield self.app_test_client.get_mails_by_tag('inbox')
self.assertEquals(0, len(inbox_mails))
@@ -37,7 +39,8 @@ 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')
- yield self.app_test_client.delete_mails([mails[0].ident])
+ 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())
trash_mails = yield self.app_test_client.get_mails_by_tag('trash')
@@ -49,7 +52,8 @@ class DeleteMailTest(SoledadTestBase):
mails = yield self.app_test_client.add_multiple_to_mailbox(5, 'inbox')
mail_idents = [m.ident for m in mails]
- yield self.app_test_client.delete_mails(mail_idents)
+ 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())
inbox = yield self.app_test_client.get_mails_by_tag('inbox')
self.assertEquals(0, len(inbox))
@@ -59,7 +63,8 @@ class DeleteMailTest(SoledadTestBase):
mails = yield self.app_test_client.add_multiple_to_mailbox(5, 'trash')
mail_idents = [m.ident for m in mails]
- yield self.app_test_client.delete_mails(mail_idents)
+ 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())
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 657cfab1..a9c7b3f7 100644
--- a/service/test/integration/test_drafts.py
+++ b/service/test/integration/test_drafts.py
@@ -17,6 +17,7 @@
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):
@@ -26,17 +27,20 @@ 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)[0])['ident']
+ first_draft_ident = (yield self.app_test_client.put_mail(first_draft, session=session)[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)
+ deferred_res = self.post_mail(second_draft, session)
sendmail_deferred.callback(None) # SMTP succeeded
@@ -54,12 +58,15 @@ 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)
+ res = self.post_mail(first_draft, session)
sendmail_deferred.callback(True)
yield res
@@ -70,25 +77,32 @@ class DraftsTest(SoledadTestBase):
self.assertEquals('First draft', sent_mails[0].subject)
self.assertEquals(0, len(drafts))
- def post_mail(self, data):
- deferred_res, req = self.app_test_client.post('/mails', data)
+ 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)
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)[0]
+ yield self.app_test_client.put_mail(mail, session=session)[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)[0])['ident']
+ draft_ident = (yield self.app_test_client.put_mail(draft, session=session)[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)[0]
+ yield self.app_test_client.put_mail(updated_draft, session=session)[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 c50c1883..ff659396 100644
--- a/service/test/integration/test_feedback_service.py
+++ b/service/test/integration/test_feedback_service.py
@@ -1,4 +1,4 @@
-import unittest
+from twisted.trial 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 c9d39d17..92c2afe5 100644
--- a/service/test/integration/test_logout.py
+++ b/service/test/integration/test_logout.py
@@ -29,7 +29,8 @@ class MultiUserLogoutTest(MultiUserSoledadTestBase):
@defer.inlineCallbacks
def test_logout_deletes_services_stop_background_reactor_tasks_and_closes_soledad(self):
- response, login_request = yield self.app_test_client.login()
+ 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())
yield response
yield self.wait_for_session_user_id_to_finish()
@@ -37,7 +38,8 @@ class MultiUserLogoutTest(MultiUserSoledadTestBase):
response, request = self.app_test_client.post(
"/logout",
json.dumps({'csrftoken': [login_request.getCookie('XSRF-TOKEN')]}),
- from_request=login_request,
+ ajax=False,
+ session=login_request.getSession(),
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 18c3ddc2..c01deefc 100644
--- a/service/test/integration/test_mark_as_read_unread.py
+++ b/service/test/integration/test_mark_as_read_unread.py
@@ -30,32 +30,40 @@ class MarkAsReadUnreadTest(SoledadTestBase):
mails = yield self.app_test_client.get_mails_by_tag('inbox')
self.assertNotIn('read', mails[0].status)
- yield self.app_test_client.mark_many_as_read([mail.ident])
+ 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)
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])
+ yield self.app_test_client.mark_many_as_read([mail.ident], session)
- yield self.app_test_client.mark_many_as_unread([mail.ident])
+ yield self.app_test_client.mark_many_as_unread([mail.ident], session)
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])
+ yield self.app_test_client.mark_many_as_read([mail1.ident, mail2.ident], session)
- yield self.app_test_client.mark_many_as_unread([mail1.ident, mail2.ident])
+ yield self.app_test_client.mark_many_as_unread([mail1.ident, mail2.ident], session)
mails = yield self.app_test_client.get_mails_by_tag('inbox')
@@ -75,7 +83,9 @@ class MarkAsReadUnreadTest(SoledadTestBase):
self.assertNotIn('read', mails[0].status)
self.assertNotIn('read', mails[1].status)
- yield self.app_test_client.mark_many_as_read([mails[0].ident, mails[1].ident])
+ 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)
mails = yield self.app_test_client.get_mails_by_tag('inbox')
@@ -84,12 +94,15 @@ 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])
+ yield self.app_test_client.mark_many_as_read([mail2.ident], session)
mails = yield self.app_test_client.get_mails_by_tag('inbox')
@@ -98,7 +111,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])
+ yield self.app_test_client.mark_many_as_read([mails[0].ident, mails[1].ident], session)
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 fe456583..2008b320 100644
--- a/service/test/integration/test_multi_user_login.py
+++ b/service/test/integration/test_multi_user_login.py
@@ -33,13 +33,14 @@ class MultiUserLoginTest(MultiUserSoledadTestBase):
@defer.inlineCallbacks
def test_logged_in_users_sees_resources(self):
- response, login_request = yield self.app_test_client.login()
+ 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())
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, from_request=login_request)
+ response, request = self.app_test_client.get("/mail/%s" % mail_id, session=login_request.getSession())
response = yield response
self.assertEqual(200, request.code)
@@ -48,7 +49,8 @@ class MultiUserLoginTest(MultiUserSoledadTestBase):
@defer.inlineCallbacks
def test_wrong_credentials_cannot_access_resources(self):
- response, login_request = self.app_test_client.login('username', 'wrong_password')
+ 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_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 b46d40d5..ac6e52e7 100644
--- a/service/test/integration/test_retrieve_attachment.py
+++ b/service/test/integration/test_retrieve_attachment.py
@@ -86,7 +86,9 @@ class RetrieveAttachmentTest(SoledadTestBase):
datagen, headers = multipart_encode([file])
post_data = "".join(datagen)
- _, req = yield self.app_test_client.post_attachment(post_data, headers)
+ 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)
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
new file mode 100644
index 00000000..e3fa8af5
--- /dev/null
+++ b/service/test/integration/test_static_files.py
@@ -0,0 +1,27 @@
+#
+# 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 555a7382..d107e320 100644
--- a/service/test/integration/test_tags.py
+++ b/service/test/integration/test_tags.py
@@ -31,7 +31,9 @@ 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)
- yield self.app_test_client.post_tags(mail.ident, self._tags_json(['IMPORTANT']))
+ 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)
mails = yield self.app_test_client.get_mails_by_tag('inbox')
self.assertEquals({'IMPORTANT'}, set(mails[0].tags))
@@ -41,15 +43,18 @@ 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']))
+ yield self.app_test_client.post_tags(mail.ident, self._tags_json(['ImPoRtAnT']), session)
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']))
+ yield self.app_test_client.post_tags(another_mail.ident, self._tags_json(['IMPORTANT']), session)
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')
@@ -62,7 +67,9 @@ 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)
- yield self.app_test_client.post_tags(mail.ident, self._tags_json(['ImPoRtAnT']))
+ 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)
mails = yield self.app_test_client.get_mails_by_tag('important')
self.assertEquals(0, len(mails))
@@ -78,7 +85,9 @@ 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)
- yield self.app_test_client.post_tags(mail.ident, self._tags_json(['tag1', ' ']))
+ 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)
mail = yield self.app_test_client.get_mail(mail.ident)
@@ -89,8 +98,10 @@ 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()]))
+ response = yield self.app_test_client.post_tags(mail.ident, self._tags_json([tag.name.upper()]), session)
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 a03adacf..a9813b2c 100644
--- a/service/test/integration/test_users_count.py
+++ b/service/test/integration/test_users_count.py
@@ -31,7 +31,8 @@ class UsersResourceTest(MultiUserSoledadTestBase):
@defer.inlineCallbacks
def test_online_users_count_uses_leap_auth_privileges(self):
- response, login_request = yield self.app_test_client.login()
+ 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())
yield response
yield self.wait_for_session_user_id_to_finish()
@@ -40,7 +41,7 @@ class UsersResourceTest(MultiUserSoledadTestBase):
response, request = self.app_test_client.get(
"/users",
json.dumps({'csrftoken': [login_request.getCookie('XSRF-TOKEN')]}),
- from_request=login_request,
+ session=login_request.getSession(),
as_json=False)
yield response