mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user