Use real Response object in DjrillBackendMockAPITestCase tests.

(Improves testing accuracy around API response encoding.)

* Add `six` as test dependency (six.BytesIO, six.b)
* Change MockResponse content to bytes (because HTTP responses
  are bytes, not strings)
This commit is contained in:
medmunds
2015-01-16 13:18:17 -08:00
parent 4754ef7650
commit 11961b57e5
4 changed files with 13 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
import json
from mock import patch
import requests
import six
from django.test import TestCase
@@ -11,15 +13,13 @@ from .utils import override_settings
class DjrillBackendMockAPITestCase(TestCase):
"""TestCase that uses Djrill EmailBackend with a mocked Mandrill API"""
class MockResponse:
class MockResponse(requests.Response):
"""requests.post return value mock sufficient for DjrillBackend"""
def __init__(self, status_code=200, content="{}", json=None):
def __init__(self, status_code=200, raw=six.b("{}"), encoding='utf-8'):
super(DjrillBackendMockAPITestCase.MockResponse, self).__init__()
self.status_code = status_code
self.content = content
self._json = json if json is not None else ['']
def json(self):
return self._json
self.encoding = encoding
self.raw = six.BytesIO(raw)
def setUp(self):
self.patch = patch('requests.post', autospec=True)