summaryrefslogtreecommitdiff
path: root/service/test/unit/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'service/test/unit/controllers')
-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