summaryrefslogtreecommitdiff
path: root/service/test/unit/controllers
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-10-31 12:17:26 +0100
committerDuda Dornelles <ddornell@thoughtworks.com>2014-11-05 18:02:32 -0200
commit9ab17e2bbf61062ce8399ef1c51d2069a0cced31 (patch)
tree4079dcbd6f4fe5c485595491f4fb874e3898bc1c /service/test/unit/controllers
parent0bfc4824189807c7a8971093910ced527b4e6a29 (diff)
moving to twisted
Diffstat (limited to 'service/test/unit/controllers')
-rw-r--r--service/test/unit/controllers/mails_controller_test.py46
-rw-r--r--service/test/unit/controllers/sync_info_controller_test.py4
2 files changed, 30 insertions, 20 deletions
diff --git a/service/test/unit/controllers/mails_controller_test.py b/service/test/unit/controllers/mails_controller_test.py
index a64207e9..93748de9 100644
--- a/service/test/unit/controllers/mails_controller_test.py
+++ b/service/test/unit/controllers/mails_controller_test.py
@@ -13,16 +13,21 @@
#
# 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 klein.test_resource import requestMock
+from mock import MagicMock
from mockito import *
from pixelated.controllers.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,
@@ -42,20 +47,22 @@ class TestMailsController(unittest.TestCase):
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(self.input_mail)
+ result = self.mails_controller.send_mail(request)
- self.assertEqual(result.status_code, 200)
- self.assertEqual(result.data,
+ 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
- result = self.mails_controller.send_mail(self.input_mail)
+ request = requestMock('', body=json.dumps(self.input_mail.json))
+ result = self.mails_controller.send_mail(request)
- self.assertEqual(result.status_code, 422)
- self.assertEqual(result.data,
+ 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):
@@ -63,17 +70,17 @@ class TestMailsController(unittest.TestCase):
mail.as_dict = lambda: {'ident': 1, 'body': 'le mail body'}
when(self.mail_service).mail(1).thenReturn(mail)
- response = self.mails_controller.mail(1)
+ response = self.mails_controller.mail(self.dummy_request, 1)
verify(self.mail_service).mail(1)
- self.assertEqual(response.data, '{"body": "le mail body", "ident": 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.mails_controller.mark_mail_as_read(1)
+ self.mails_controller.mark_mail_as_read(None, 1)
verify(self.mail_service).mark_as_read(1)
verify(self.search_engine).index_mail(mail)
@@ -83,27 +90,28 @@ class TestMailsController(unittest.TestCase):
when(self.mail_service).mark_as_unread(1).thenReturn(mail)
when(self.search_engine).index_mail(mail).thenReturn(None)
- self.mails_controller.mark_mail_as_unread(1)
+ self.mails_controller.mark_mail_as_unread(None, 1)
verify(self.mail_service).mark_as_unread(1)
verify(self.search_engine).index_mail(mail)
- def test_delete_permanently_when_mail_in_trash(self):
+ def test_move_message_to_trash(self):
mail = mock()
- mail.mailbox_name = 'TRASH'
+ mail.mailbox_name = 'INBOX'
when(self.mail_service).mail(1).thenReturn(mail)
- self.mails_controller.delete_mail(1)
+ when(self.mail_service).delete_mail(1).thenReturn(mail)
- verify(self.mail_service).delete_permanent(1)
+ self.mails_controller.delete_mail(self.dummy_request, 1)
- def test_move_message_to_trash(self):
+ verify(self.search_engine).index_mail(mail)
+
+ def test_delete_permanently_when_mail_in_trash(self):
mail = mock()
- mail.mailbox_name = 'INBOX'
+ mail.mailbox_name = 'TRASH'
when(self.mail_service).mail(1).thenReturn(mail)
- when(self.mails_controller).delete_mail(1).thenReturn(mail)
- when(self.search_engine).index_mail(mail)
+ self.mails_controller.delete_mail(self.dummy_request, 1)
- verify(self.search_engine).index_mail(mail)
+ verify(self.mail_service).delete_permanent(1)
def _successfuly_send_mail(self, ident, mail):
sent_mail = mock()
diff --git a/service/test/unit/controllers/sync_info_controller_test.py b/service/test/unit/controllers/sync_info_controller_test.py
index d3bf1190..ce9a0dff 100644
--- a/service/test/unit/controllers/sync_info_controller_test.py
+++ b/service/test/unit/controllers/sync_info_controller_test.py
@@ -14,6 +14,7 @@
# 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 unittest
+from mock import MagicMock
from pixelated.controllers import SyncInfoController
from mockito import *
import json
@@ -22,6 +23,7 @@ import json
class SyncInfoControllerTest(unittest.TestCase):
def setUp(self):
+ self.dummy_request = MagicMock()
self.controller = SyncInfoController()
def _set_count(self, current, total):
@@ -30,7 +32,7 @@ class SyncInfoControllerTest(unittest.TestCase):
self.controller.set_sync_info(soledad_sync_data)
def get_sync_info(self):
- return json.loads(self.controller.sync_info().data)
+ return json.loads(self.controller.sync_info(self.dummy_request))
def test_is_not_syncing_if_total_is_equal_to_current(self):
self._set_count(total=0, current=0)