@@ -46,7 +46,7 @@ class ApiAccessRequestViewTests(TestCase):
|
||||
"""
|
||||
Assert API response on `API Access Request` endpoint.
|
||||
"""
|
||||
json_content = json.loads(api_response.content)
|
||||
json_content = json.loads(api_response.content.decode('utf-8'))
|
||||
self.assertEqual(api_response.status_code, 200)
|
||||
self.assertEqual(json_content['count'], expected_results_count)
|
||||
|
||||
|
||||
@@ -73,17 +73,18 @@ def perform_request(method, url, data_or_params=None, raw=False,
|
||||
)
|
||||
|
||||
metric_tags.append(u'status_code:{}'.format(response.status_code))
|
||||
if response.status_code > 200:
|
||||
status_code = int(response.status_code)
|
||||
if status_code > 200:
|
||||
metric_tags.append(u'result:failure')
|
||||
else:
|
||||
metric_tags.append(u'result:success')
|
||||
|
||||
if 200 < response.status_code < 500:
|
||||
if 200 < status_code < 500:
|
||||
raise CommentClientRequestError(response.text, response.status_code)
|
||||
# Heroku returns a 503 when an application is in maintenance mode
|
||||
elif response.status_code == 503:
|
||||
elif status_code == 503:
|
||||
raise CommentClientMaintenanceError(response.text)
|
||||
elif response.status_code == 500:
|
||||
elif status_code == 500:
|
||||
raise CommentClient500Error(response.text)
|
||||
else:
|
||||
if raw:
|
||||
|
||||
@@ -547,8 +547,12 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
|
||||
|
||||
def test_enrollment_already_enrolled(self):
|
||||
response = self.assert_enrollment_status()
|
||||
response_json = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
repeat_response = self.assert_enrollment_status(expected_status=status.HTTP_200_OK)
|
||||
self.assertEqual(json.loads(response.content.decode('utf-8')), json.loads(repeat_response.content))
|
||||
repeat_json = json.loads(repeat_response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(response_json, repeat_json)
|
||||
|
||||
def test_get_enrollment_with_invalid_key(self):
|
||||
resp = self.client.post(
|
||||
@@ -562,7 +566,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
|
||||
format='json'
|
||||
)
|
||||
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn("No course ", resp.content)
|
||||
self.assertIn("No course ", resp.content.decode('utf-8'))
|
||||
|
||||
def test_enrollment_throttle_for_user(self):
|
||||
"""Make sure a user requests do not exceed the maximum number of requests"""
|
||||
@@ -655,7 +659,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
|
||||
),
|
||||
{'include_expired': True},
|
||||
)
|
||||
v_data = json.loads(v_response.content)
|
||||
v_data = json.loads(v_response.content.decode('utf-8'))
|
||||
|
||||
# Ensure that both course modes are returned
|
||||
self.assertEqual(len(v_data['course_modes']), 2)
|
||||
@@ -664,7 +668,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
|
||||
h_response = self.client.get(
|
||||
reverse('courseenrollmentdetails', kwargs={"course_id": six.text_type(self.course.id)}),
|
||||
)
|
||||
h_data = json.loads(h_response.content)
|
||||
h_data = json.loads(h_response.content.decode('utf-8'))
|
||||
|
||||
# Ensure that only one course mode is returned and that it is honor
|
||||
self.assertEqual(len(h_data['course_modes']), 1)
|
||||
|
||||
@@ -109,7 +109,8 @@ class AwardProgramCertificateTestCase(TestCase):
|
||||
}
|
||||
]
|
||||
}
|
||||
self.assertEqual(json.loads(httpretty.last_request().body), expected_body)
|
||||
last_request_body = httpretty.last_request().body.decode('utf-8')
|
||||
self.assertEqual(json.loads(last_request_body), expected_body)
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
@@ -471,7 +472,8 @@ class PostCourseCertificateTestCase(TestCase):
|
||||
'value': visible_date.strftime('%Y-%m-%dT%H:%M:%SZ') # text representation of date
|
||||
}]
|
||||
}
|
||||
self.assertEqual(json.loads(httpretty.last_request().body), expected_body)
|
||||
last_request_body = httpretty.last_request().body.decode('utf-8')
|
||||
self.assertEqual(json.loads(last_request_body), expected_body)
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
|
||||
@@ -12,6 +12,7 @@ from pytz import UTC
|
||||
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from student.tests.factories import UserFactory
|
||||
from six import text_type
|
||||
|
||||
from ..image_helpers import get_profile_image_urls_for_user
|
||||
|
||||
@@ -73,7 +74,8 @@ class ProfileImageUrlTestCase(TestCase):
|
||||
"""
|
||||
self.user.profile.profile_image_uploaded_at = TEST_PROFILE_IMAGE_UPLOAD_DT
|
||||
self.user.profile.save()
|
||||
expected_name = hashlib.md5('secret' + self.user.username).hexdigest()
|
||||
expected_name = hashlib.md5(
|
||||
'secret' + text_type(self.user.username).encode('utf-8')).hexdigest()
|
||||
actual_urls = get_profile_image_urls_for_user(self.user)
|
||||
self.verify_urls(actual_urls, expected_name, is_default=False)
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ class UserAPITestCase(APITestCase):
|
||||
template = '{root}/{filename}_{{size}}.{extension}'
|
||||
if has_profile_image:
|
||||
url_root = 'http://example-storage.com/profile-images'
|
||||
filename = hashlib.md5('secret' + self.user.username).hexdigest()
|
||||
filename = hashlib.md5('secret' + self.user.username.encode('utf-8')).hexdigest()
|
||||
file_extension = 'jpg'
|
||||
template += '?v={}'.format(TEST_PROFILE_IMAGE_UPLOADED_AT.strftime("%s"))
|
||||
else:
|
||||
|
||||
@@ -33,6 +33,7 @@ from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import connections
|
||||
from django.utils import timezone
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
import six
|
||||
from six import text_type
|
||||
from six.moves import range
|
||||
|
||||
@@ -251,14 +252,18 @@ class Command(BaseCommand):
|
||||
else:
|
||||
pref_set_datetime = self.DEFAULT_DATETIME_STR
|
||||
|
||||
if not full_name:
|
||||
full_name = ""
|
||||
|
||||
# Only encode to utf-8 in python2 because python3's csv writer can handle unicode.
|
||||
writer.writerow({
|
||||
"user_id": user_id,
|
||||
"username": username.encode('utf-8'),
|
||||
"email": email.encode('utf-8'),
|
||||
"username": username.encode('utf-8') if six.PY2 else username,
|
||||
"email": email.encode('utf-8') if six.PY2 else email,
|
||||
# There should not be a case where users are without full_names. We only need this safe check because
|
||||
# of ECOM-1995.
|
||||
"full_name": full_name.encode('utf-8') if full_name else '',
|
||||
"course_id": course_id.encode('utf-8'),
|
||||
"full_name": full_name.encode('utf-8') if six.PY2 else full_name,
|
||||
"course_id": course_id.encode('utf-8') if six.PY2 else course_id,
|
||||
"is_opted_in_for_email": is_opted_in if is_opted_in else "True",
|
||||
"preference_set_datetime": pref_set_datetime,
|
||||
})
|
||||
|
||||
@@ -9,6 +9,7 @@ import tempfile
|
||||
from collections import defaultdict
|
||||
|
||||
import ddt
|
||||
import six
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
@@ -213,7 +214,15 @@ class EmailOptInListTest(ModuleStoreTestCase):
|
||||
|
||||
# Execute the command, but exclude the second course from the list
|
||||
output = self._run_command(self.TEST_ORG, chunk_size=2)
|
||||
course_ids = [row['course_id'].strip().decode('utf-8') for row in output]
|
||||
course_ids = []
|
||||
for row in output:
|
||||
course_id = row['course_id'].strip()
|
||||
# Python3 takes care of the decoding in the csv object
|
||||
# but python 2 doesn't
|
||||
if six.PY2:
|
||||
course_id = course_id.decode('utf-8')
|
||||
course_ids.append(course_id)
|
||||
|
||||
for course in self.courses:
|
||||
assert text_type(course.id) in course_ids
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class TestXblockUtils(SharedModuleStoreTestCase):
|
||||
frag=fragment,
|
||||
context={"wrap_xblock_data": {"custom-attribute": "custom-value"}},
|
||||
usage_id_serializer=lambda usage_id: quote_slashes(six.text_type(usage_id)),
|
||||
request_token=uuid.uuid1().get_hex()
|
||||
request_token=uuid.uuid1().hex
|
||||
)
|
||||
self.assertIsInstance(test_wrap_output, Fragment)
|
||||
self.assertIn('xblock-baseview', test_wrap_output.content)
|
||||
|
||||
Reference in New Issue
Block a user