diff options
author | mnandri <mnandri@eunglick.corporate.thoughtworks.com> | 2015-12-16 18:26:31 +0100 |
---|---|---|
committer | mnandri <mnandri@eunglick.corporate.thoughtworks.com> | 2015-12-18 11:22:34 +0100 |
commit | 39fa6e68fc2afaafc0e8440d212b464d2e20c326 (patch) | |
tree | 03d090f7178a2d93a9c33cd072b0ff33fd9bd545 /service/test/unit | |
parent | 338498cef1cd4f2b9ae49bc54bd496de0e5472a0 (diff) |
fixing unit test -- again WIP
Diffstat (limited to 'service/test/unit')
-rw-r--r-- | service/test/unit/resources/test_attachments_resource.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/service/test/unit/resources/test_attachments_resource.py b/service/test/unit/resources/test_attachments_resource.py index c377324b..837f5324 100644 --- a/service/test/unit/resources/test_attachments_resource.py +++ b/service/test/unit/resources/test_attachments_resource.py @@ -1,7 +1,7 @@ import json import unittest -from mockito import mock, when, verify +from mock import patch, MagicMock from twisted.internet import defer from twisted.web.test.requesthelper import DummyRequest @@ -12,24 +12,23 @@ from test.unit.resources import DummySite class AttachmentsResourceTest(unittest.TestCase): def setUp(self): - self.mail_service = mock() + self.mail_service = MagicMock() self.mails_resource = AttachmentsResource(self.mail_service) self.mails_resource.isLeaf = True self.web = DummySite(self.mails_resource) - def test_post_new_attachment(self): + @patch('twisted.internet.defer.maybeDeferred') + @patch('cgi.FieldStorage') + def test_post_new_attachment(self, mock_fields, mock_maybe_deferred): request = DummyRequest(['/attachment']) request.method = 'POST' - attachment = 'some fake file' - request.args = {'attachment': [attachment,]} + request.content = 'mocked' attachment_id = 'B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A' - - when(self.mail_service).attachment_id(attachment).thenReturn(defer.succeed(attachment_id)) + mock_maybe_deferred.return_value = defer.succeed(attachment_id) d = self.web.get(request) def assert_response(_): - verify(self.mail_service).attachment_id(attachment) self.assertEqual(201, request.code) self.assertEqual('/attachment/%s' % attachment_id, request.headers['Location']) self.assertEqual({'attachment_id': attachment_id}, json.loads(request.written[0])) @@ -37,21 +36,20 @@ class AttachmentsResourceTest(unittest.TestCase): d.addCallback(assert_response) return d - def test_post_attachment_fails(self): + @patch('twisted.internet.defer.maybeDeferred') + @patch('cgi.FieldStorage') + def test_post_attachment_fails(self, mock_fields, mock_maybe_deferred): + mock_maybe_deferred.return_value = defer.fail(Exception) request = DummyRequest(['/attachment']) request.method = 'POST' - attachment = 'some fake file' - request.args = {'attachment': [attachment,]} - - when(self.mail_service).attachment_id(attachment).thenReturn(defer.fail(Exception)) + request.content = 'mocked' d = self.web.get(request) def assert_response(_): self.assertEqual(500, request.code) self.assertFalse('Location' in request.headers) - verify(self.mail_service).attachment_id(attachment) self.assertEqual({"message": "Something went wrong. Attachement not saved."}, json.loads(request.written[0])) d.addCallback(assert_response) - return d
\ No newline at end of file + return d |