From 58ee29aeb7ff0822d954633eda14362d68960dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 18 Aug 2019 13:46:59 +0200 Subject: [PATCH] tests: update notifications to convert content before loading as json (#35425) --- tests/test_notification.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_notification.py b/tests/test_notification.py index ae5ea2cf..821876df 100644 --- a/tests/test_notification.py +++ b/tests/test_notification.py @@ -7,6 +7,7 @@ from datetime import timedelta as timedelta from django.contrib.auth.models import User from django.test.client import RequestFactory +from django.utils.encoding import force_text from django.utils.timezone import timedelta, now from django.core.urlresolvers import reverse @@ -147,7 +148,7 @@ def test_notification_ws(john_doe): resp = client.post(reverse('api-notification-add'), json.dumps(data), content_type='application/json') assert resp.status_code == 200 - result = json.loads(resp.content) + result = json.loads(force_text(resp.content)) assert result == {'data': {'id': check_id}, 'err': 0} assert Notification.objects.filter(user=john_doe).count() == count return Notification.objects.find(john_doe, check_id).get() @@ -196,18 +197,18 @@ def test_notification_ws(john_doe): resp = client.get(reverse('api-notification-count')) assert resp.status_code == 200 - assert json.loads(resp.content)['new'] == 3 - assert json.loads(resp.content)['total'] == 3 + assert json.loads(force_text(resp.content))['new'] == 3 + assert json.loads(force_text(resp.content))['total'] == 3 resp = client.get(reverse('api-notification-ack', kwargs={'notification_id': '1'})) resp = client.get(reverse('api-notification-count')) assert resp.status_code == 200 - assert json.loads(resp.content)['new'] == 2 - assert json.loads(resp.content)['total'] == 3 + assert json.loads(force_text(resp.content))['new'] == 2 + assert json.loads(force_text(resp.content))['total'] == 3 resp = client.get(reverse('api-notification-forget', kwargs={'notification_id': '1'})) resp = client.get(reverse('api-notification-count')) assert resp.status_code == 200 - assert json.loads(resp.content)['new'] == 2 - assert json.loads(resp.content)['total'] == 2 + assert json.loads(force_text(resp.content))['new'] == 2 + assert json.loads(force_text(resp.content))['total'] == 2 def test_notification_ws_badrequest(john_doe): @@ -216,7 +217,7 @@ def test_notification_ws_badrequest(john_doe): json.dumps(data) if data else None, content_type='application/json') assert resp.status_code == 400 - result = json.loads(resp.content) + result = json.loads(force_text(resp.content)) assert result['err'] == 1 assert message in list(result['err_desc'].values())[0][0] @@ -258,7 +259,7 @@ def test_notification_id_and_origin(john_doe): resp = client.post(reverse('api-notification-add'), json.dumps(data), content_type='application/json') - return json.loads(resp.content) + return json.loads(force_text(resp.content)) result = notify({'summary': 'foo', 'id': '1'}) assert result['err'] == 1