From dcc0c5e5768c59781f70075f6d8a1e13c08f8e87 Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Wed, 10 Apr 2019 15:30:19 +0200
Subject: [PATCH] python3: enforce text type on django's HttpResponse.content
 (#32450)

---
 tests/test_all.py | 7 ++++---
 tests/test_cas.py | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tests/test_all.py b/tests/test_all.py
index 89cbb557..c3e4d23c 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -12,6 +12,7 @@ from django.test.utils import override_settings
 from django.core.serializers.json import DjangoJSONEncoder
 from django.contrib.auth import get_user_model
 from django.contrib.contenttypes.models import ContentType
+from django.utils.encoding import force_text
 from django.utils.translation import ugettext as _
 from django.utils.six import text_type
 from django.utils.six.moves.urllib import parse as urlparse
@@ -497,7 +498,7 @@ class APITest(TestCase):
         activation_url = get_link_from_mail(mail.outbox[-1])
         response = client.get(activation_url)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
-        assert utils.make_url(return_url, params={'token': token}) in response.content
+        assert utils.make_url(return_url, params={'token': token}) in force_text(response.content)
         self.assertEqual(User.objects.count(), user_count + 1)
         response = client.get(reverse('auth_homepage'))
         self.assertContains(response, username)
@@ -624,7 +625,7 @@ class APITest(TestCase):
         activation_url = get_link_from_mail(activation_mail1)
         response = client.get(activation_url)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
-        assert utils.make_url(return_url, params={'token': token}) in response.content
+        assert utils.make_url(return_url, params={'token': token}) in force_text(response.content)
         self.assertEqual(User.objects.count(), user_count + 1)
         response = client.get(reverse('auth_homepage'))
         self.assertContains(response, username)
@@ -748,7 +749,7 @@ class APITest(TestCase):
         activation_url = get_link_from_mail(activation_mail1)
         response = client.get(activation_url)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
-        assert utils.make_url(return_url, params={'token': token}) in response.content
+        assert utils.make_url(return_url, params={'token': token}) in force_text(response.content)
         self.assertEqual(User.objects.count(), user_count + 1)
         response = client.get(reverse('auth_homepage'))
         self.assertContains(response, username)
diff --git a/tests/test_cas.py b/tests/test_cas.py
index 997393a0..dc059358 100644
--- a/tests/test_cas.py
+++ b/tests/test_cas.py
@@ -1,5 +1,6 @@
 from django.test.client import RequestFactory, Client
 from django.test.utils import override_settings
+from django.utils.encoding import force_text
 from django.utils.six.moves.urllib import parse as urlparse
 
 
@@ -69,7 +70,7 @@ class CasTests(Authentic2TestCase):
         client = Client()
         response = client.get('/idp/cas/login')
         self.assertEqual(response.status_code, 400)
-        self.assertIn('no service', response.content)
+        self.assertIn('no service', force_text(response.content))
         response = client.get('/idp/cas/login', {constants.SERVICE_PARAM: 'http://google.com/'})
         self.assertRedirectsComplex(response, 'http://google.com/')
         response = client.get('/idp/cas/login', {constants.SERVICE_PARAM: self.URL,
@@ -94,7 +95,7 @@ class CasTests(Authentic2TestCase):
         response = client.post(location, {'login-password-submit': '',
                                'username': self.LOGIN, 'password': self.PASSWORD}, follow=False)
         response = client.get(response.url)
-        self.assertIn('https://casclient.com/loser/', response.content)
+        self.assertIn('https://casclient.com/loser/', force_text(response.content))
 
     def test_role_access_control_granted(self):
         client = Client()
@@ -155,7 +156,7 @@ class CasTests(Authentic2TestCase):
             ticket_id, constants.SERVICE_PARAM: self.URL})
         self.assertEquals(response.status_code, 200)
         self.assertEquals(response['content-type'], 'text/plain')
-        self.assertEquals(response.content, 'yes\n%s\n' % self.LOGIN)
+        self.assertEquals(force_text(response.content), 'yes\n%s\n' % self.LOGIN)
         # Verify ticket has been deleted
         with self.assertRaises(Ticket.DoesNotExist):
             Ticket.objects.get()
-- 
2.20.1

