diff options
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/user_agent_test.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/service/test/user_agent_test.py b/service/test/user_agent_test.py index 2f1ed01d..d21f1733 100644 --- a/service/test/user_agent_test.py +++ b/service/test/user_agent_test.py @@ -58,6 +58,33 @@ class UserAgentTest(unittest.TestCase): verify(self.mail_service).send(1, self.input_mail) + def test_sending_mail_return_sent_mail_data_when_send_succeeds(self): + self.input_mail = self.draft() + self.input_mail.as_dict = lambda: {'header': {'from': 'a@a.a', 'to': 'b@b.b'}, + 'ident': 1, + 'tags': [], + 'status': [], + 'security_casing': {}, + 'body': 'email body'} + + result = self.app.post('/mails', data='{"ident":1}', content_type="application/json") + + self.assertEqual(result.status_code, 200) + self.assertEqual(result.data, '{"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.input_mail = self.draft() + + def send_that_throws_exception(id, mail): + raise Exception('email sending failed', 'more information of error') + + self.mail_service.send = send_that_throws_exception + + result = self.app.post('/mails', data='{"ident":1}', content_type="application/json") + + self.assertEqual(result.status_code, 500) + self.assertEqual(result.data, '{"message": "email sending failed\\nmore information of error"}') + def test_update_draft(self): self.input_mail = self.draft() |