summaryrefslogtreecommitdiff
path: root/service/test/unit
diff options
context:
space:
mode:
authorDuda Dornelles <dudassdorneles@gmail.com>2015-01-21 19:48:50 -0200
committerPixpoa pairing <pixpoapairing@pixelated-project.org>2015-01-21 19:48:50 -0200
commit70e6d825d6b3e6804d42f931f30a18445650f9b2 (patch)
tree3708c88d252c30b08600895211d2f1938facfaca /service/test/unit
parent17617d102c0aa6a73cba51f1b6e425ec45384316 (diff)
#240 Adapted tests after change to twisted web
Diffstat (limited to 'service/test/unit')
-rw-r--r--service/test/unit/controllers/mails_controller_test.py126
-rw-r--r--service/test/unit/resources/__init__.py (renamed from service/test/unit/controllers/__init__.py)0
-rw-r--r--service/test/unit/resources/sync_info_controller_test.py (renamed from service/test/unit/controllers/sync_info_controller_test.py)11
3 files changed, 6 insertions, 131 deletions
diff --git a/service/test/unit/controllers/mails_controller_test.py b/service/test/unit/controllers/mails_controller_test.py
deleted file mode 100644
index 7e5d0e7d..00000000
--- a/service/test/unit/controllers/mails_controller_test.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#
-# Copyright (c) 2014 ThoughtWorks, Inc.
-#
-# Pixelated is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pixelated is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-import json
-import unittest
-from io import BytesIO
-
-from klein.test_resource import requestMock
-from mock import MagicMock
-from mockito import *
-from pixelated.resources.mails_controller import MailsController
-
-
-class TestMailsController(unittest.TestCase):
-
- def setUp(self):
- self.mail_service = mock()
- self.search_engine = mock()
- self.dummy_request = MagicMock(spec=['code', 'responseHeaders'])
- draft_service = mock()
-
- self.mails_controller = MailsController(mail_service=self.mail_service,
- draft_service=draft_service,
- search_engine=self.search_engine)
-
- self.input_mail = mock()
- self.input_mail.json = {'header': {'from': 'a@a.a', 'to': 'b@b.b'},
- 'ident': 1,
- 'tags': [],
- 'status': [],
- 'security_casing': {},
- 'body': 'email body'}
-
- def tearDown(self):
- unstub()
-
- def test_sending_mail_return_sent_mail_data_when_send_succeeds(self):
- self.mail_service.send = self._successfuly_send_mail
- request = requestMock('', body=json.dumps(self.input_mail.json))
-
- result = self.mails_controller.send_mail(request)
-
- self.assertEqual(request.code, 200)
- self.assertEqual(result,
- '{"status": [], "body": "email body", "ident": 1, "tags": [], "header": {"to": "b@b.b", "from": "a@a.a"}, "security_casing": {}}')
-
- def test_sending_mail_return_error_message_when_send_fails(self):
- self.mail_service.send = self._send_that_throws_exception
-
- request = requestMock('', body=json.dumps(self.input_mail.json))
- result = self.mails_controller.send_mail(request)
-
- self.assertEqual(request.code, 422)
- self.assertEqual(result,
- '{"message": "email sending failed\\nmore information of error\\n123\\nthere was a code before this"}')
-
- def test_fetching_mail_gets_mail_from_mail_service(self):
- mail = mock()
- mail.as_dict = lambda: {'ident': 1, 'body': 'le mail body'}
- when(self.mail_service).mail(1).thenReturn(mail)
-
- response = self.mails_controller.mail(self.dummy_request, 1)
-
- verify(self.mail_service).mail(1)
- self.assertEqual(response, '{"body": "le mail body", "ident": 1}')
-
- def test_marking_mail_as_read_set_mail_as_read_on_the_service(self):
- mail = mock()
- when(self.mail_service).mark_as_read("1").thenReturn(mail)
- when(self.search_engine).index_mail(mail).thenReturn(None)
- self.dummy_request.content = BytesIO('{"idents":["1"]}')
-
- self.mails_controller.mark_many_mail_read(self.dummy_request)
-
- verify(self.mail_service).mark_as_read(u'1')
- verify(self.search_engine).index_mail(mail)
-
- def test_marking_mail_as_unread_set_mail_as_unread_on_the_service(self):
- mail = mock()
- when(self.mail_service).mark_as_unread("1").thenReturn(mail)
- when(self.search_engine).index_mail(mail).thenReturn(None)
- self.dummy_request.content = BytesIO('{"idents":["1"]}')
-
- self.mails_controller.mark_many_mail_unread(self.dummy_request)
-
- verify(self.mail_service).mark_as_unread(u'1')
- verify(self.search_engine).index_mail(mail)
-
- def test_move_message_to_trash(self):
- mail = mock()
- mail.mailbox_name = 'INBOX'
- when(self.mail_service).mail(1).thenReturn(mail)
- when(self.mail_service).delete_mail(1).thenReturn(mail)
-
- self.mails_controller.delete_mail(self.dummy_request, 1)
-
- verify(self.search_engine).index_mail(mail)
-
- def test_delete_permanently_when_mail_in_trash(self):
- mail = mock()
- mail.mailbox_name = 'TRASH'
- when(self.mail_service).mail(1).thenReturn(mail)
- self.mails_controller.delete_mail(self.dummy_request, 1)
-
- verify(self.mail_service).delete_permanent(1)
-
- def _successfuly_send_mail(self, ident, mail):
- sent_mail = mock()
- sent_mail.as_dict = lambda: self.input_mail.json
-
- return sent_mail
-
- def _send_that_throws_exception(self, ident, mail):
- raise Exception('email sending failed', 'more information of error', 123, 'there was a code before this')
diff --git a/service/test/unit/controllers/__init__.py b/service/test/unit/resources/__init__.py
index e69de29b..e69de29b 100644
--- a/service/test/unit/controllers/__init__.py
+++ b/service/test/unit/resources/__init__.py
diff --git a/service/test/unit/controllers/sync_info_controller_test.py b/service/test/unit/resources/sync_info_controller_test.py
index 1fb38822..c24c7181 100644
--- a/service/test/unit/controllers/sync_info_controller_test.py
+++ b/service/test/unit/resources/sync_info_controller_test.py
@@ -16,16 +16,16 @@
import unittest
import json
-from mock import MagicMock
-from pixelated.resources import SyncInfoController
+from test.support.test_helper import request_mock
+from pixelated.resources.sync_info_resource import SyncInfoResource
from mockito import *
class SyncInfoControllerTest(unittest.TestCase):
def setUp(self):
- self.dummy_request = MagicMock()
- self.controller = SyncInfoController()
+ self.dummy_request = request_mock()
+ self.controller = SyncInfoResource()
def _set_count(self, current, total):
soledad_sync_data = mock()
@@ -33,7 +33,8 @@ class SyncInfoControllerTest(unittest.TestCase):
self.controller.set_sync_info(soledad_sync_data)
def get_sync_info(self):
- return json.loads(self.controller.sync_info(self.dummy_request))
+ self.controller.render_GET(self.dummy_request)
+ return json.loads(self.dummy_request.written[0])
def test_is_not_syncing_if_total_is_equal_to_current(self):
self._set_count(total=0, current=0)