Fix python3 compatibility in SafeCookieData and elsewhere

This commit is contained in:
Dave St.Germain
2019-08-19 10:24:15 -04:00
parent 269a57445d
commit 5febcce20c
6 changed files with 20 additions and 14 deletions

View File

@@ -184,7 +184,7 @@ class TestRefundSignal(TestCase):
self.assertFalse(mock_send_notification.called)
last_request = httpretty.last_request()
self.assertDictEqual(json.loads(last_request.body), {'action': 'approve_payment_only'})
self.assertDictEqual(json.loads(last_request.body.decode('utf8')), {'action': 'approve_payment_only'})
@mock.patch('lms.djangoapps.commerce.utils._send_refund_notification')
def test_notification_no_refund(self, mock_send_notification):
@@ -305,8 +305,9 @@ class TestRefundSignal(TestCase):
# Verify the headers
expected = {
'content-type': JSON,
'Authorization': 'Basic ' + base64.b64encode(
'{user}/token:{pwd}'.format(user=ZENDESK_USER, pwd=ZENDESK_API_KEY))
'Authorization': 'Basic {}'.format(base64.b64encode(
'{user}/token:{pwd}'.format(user=ZENDESK_USER, pwd=ZENDESK_API_KEY).encode('utf8')).decode('utf8')
)
}
self.assertDictContainsSubset(expected, last_request.headers)
@@ -322,4 +323,4 @@ class TestRefundSignal(TestCase):
'tags': ['LMS'] + tags
}
}
self.assertDictEqual(json.loads(last_request.body), expected)
self.assertDictEqual(json.loads(last_request.body.decode('utf8')), expected)

View File

@@ -3,6 +3,7 @@ Signal handlers for course goals.
"""
from __future__ import absolute_import
import six
from django.db import models
from django.dispatch import receiver

View File

@@ -8,7 +8,7 @@ of a student over a period of time. Right now, the only models are the abstract
`SoftwareSecurePhotoVerification`. The hope is to keep as much of the
photo verification process as generic as possible.
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import functools
import json
@@ -47,7 +47,7 @@ log = logging.getLogger(__name__)
def generateUUID(): # pylint: disable=invalid-name
""" Utility function; generates UUIDs """
return str(uuid.uuid4())
return six.text_type(uuid.uuid4())
class VerificationException(Exception):

View File

@@ -2,7 +2,7 @@
Tests for the fake software secure response.
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
from django.test import TestCase
from mock import patch
@@ -79,5 +79,6 @@ class SoftwareSecureFakeViewEnabledTest(SoftwareSecureFakeViewTest):
)
self.assertEqual(response.status_code, 200)
self.assertIn('EdX-ID', response.content)
self.assertIn('results_callback', response.content)
content = response.content.decode('utf8')
self.assertIn('EdX-ID', content)
self.assertIn('results_callback', content)