It looks like you’re working with Python 3 so you’ll need to turn response.content
into a UTF-8 encoded string before passing it to self.assertJSONEqual
:
class AddItemToCollectionTest(TestCase):
def test_success_when_not_added_before(self):
response = self.client.post('/add-item-to-collection')
self.assertEqual(response.status_code, 200)
self.assertJSONEqual(
str(response.content, encoding='utf8'),
{'status': 'success'}
)
If you want to simultaneously support both Python 2.7 and Python 3, use the six
compatibility library that django ships with:
from __future__ import unicode_literals
from django.utils import six
class AddItemToCollectionTest(TestCase):
def test_success_when_not_added_before(self):
response = self.client.post('/add-item-to-collection')
self.assertEqual(response.status_code, 200)
response_content = response.content
if six.PY3:
response_content = str(response_content, encoding='utf8')
self.assertJSONEqual(
response_content,
{'status': 'success'}
)