summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorAlexandre Pretto Nunes <anunes@thoughtworks.com>2014-10-23 13:57:03 -0200
committerAlexandre Pretto Nunes <anunes@thoughtworks.com>2014-10-23 13:57:15 -0200
commit7005b03934b2b666b56fb972cfad057a46d2fcbd (patch)
treee85076e03d3814f5b041cdbb1130299203084ce1 /service
parent1ae0823828e45b16b8788c78011346ef7316545e (diff)
Add tests for the mails controller
Diffstat (limited to 'service')
-rw-r--r--service/test/unit/controllers/mails_controller_test.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/service/test/unit/controllers/mails_controller_test.py b/service/test/unit/controllers/mails_controller_test.py
index ce2ce539..8807cc72 100644
--- a/service/test/unit/controllers/mails_controller_test.py
+++ b/service/test/unit/controllers/mails_controller_test.py
@@ -23,12 +23,12 @@ class TestMailsController(unittest.TestCase):
def setUp(self):
self.mail_service = mock()
- search_engine = mock()
+ self.search_engine = mock()
draft_service = mock()
self.mails_controller = MailsController(mail_service=self.mail_service,
draft_service=draft_service,
- search_engine=search_engine)
+ search_engine=self.search_engine)
self.input_mail = mock()
self.input_mail.json = {'header': {'from': 'a@a.a', 'to': 'b@b.b'},
@@ -57,6 +57,36 @@ class TestMailsController(unittest.TestCase):
self.assertEqual(result.status_code, 422)
self.assertEqual(result.data, '{"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(1)
+
+ verify(self.mail_service).mail(1)
+ self.assertEqual(response.data, '{"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)
+
+ verify(self.mail_service).mark_as_read(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.mails_controller.mark_mail_as_unread(1)
+
+ verify(self.mail_service).mark_as_unread(1)
+ verify(self.search_engine).index_mail(mail)
+
def _successfuly_send_mail(self, ident, mail):
sent_mail = mock()
sent_mail.as_dict = lambda: self.input_mail.json