Commit d0d449d2 by Chris Dodge

Add some more robustness in case a user's fullname has unicode characters in it

parent 1bb60c89
...@@ -341,10 +341,11 @@ class SoftwareSecureBackendProvider(ProctoringBackendProvider): ...@@ -341,10 +341,11 @@ class SoftwareSecureBackendProvider(ProctoringBackendProvider):
string = "" string = ""
for key in keys: for key in keys:
value = body_json[key] value = body_json[key]
if str(value) == 'True': if isinstance(value, bool):
value = 'true' if value:
if str(value) == 'False': value = 'true'
value = 'false' else:
value = 'false'
if isinstance(value, (list, tuple)): if isinstance(value, (list, tuple)):
for idx, arr in enumerate(value): for idx, arr in enumerate(value):
if isinstance(arr, dict): if isinstance(arr, dict):
...@@ -356,7 +357,7 @@ class SoftwareSecureBackendProvider(ProctoringBackendProvider): ...@@ -356,7 +357,7 @@ class SoftwareSecureBackendProvider(ProctoringBackendProvider):
else: else:
if value != "" and not value: if value != "" and not value:
value = "null" value = "null"
string += str(prefix) + str(key) + ":" + str(value).encode('utf-8') + '\n' string += str(prefix) + str(key) + ":" + unicode(value).encode('utf-8') + '\n'
return string return string
......
# coding=utf-8
""" """
Tests for the software_secure module Tests for the software_secure module
""" """
...@@ -140,13 +141,26 @@ class SoftwareSecureTests(TestCase): ...@@ -140,13 +141,26 @@ class SoftwareSecureTests(TestCase):
Tests to make sure we can parse a fullname which does not have any spaces in it Tests to make sure we can parse a fullname which does not have any spaces in it
""" """
def mock_profile_service(user_id): # pylint: disable=unused-argument set_runtime_service('credit', MockCreditService())
"""
Mocked out Profile callback endpoint exam_id = create_exam(
""" course_id='foo/bar/baz',
return {'name': 'Bono'} content_id='content',
exam_name='Sample Exam',
time_limit_mins=10,
is_proctored=True
)
with HTTMock(mock_response_content):
attempt_id = create_exam_attempt(exam_id, self.user.id, taking_as_proctored=True)
self.assertIsNotNone(attempt_id)
def test_unicode_attempt(self):
"""
Tests to make sure we can handle an attempt when a user's fullname has unicode characters in it
"""
set_runtime_service('profile', mock_profile_service) set_runtime_service('credit', MockCreditService(profile_fullname=u'अआईउऊऋऌ अआईउऊऋऌ'))
exam_id = create_exam( exam_id = create_exam(
course_id='foo/bar/baz', course_id='foo/bar/baz',
......
...@@ -17,13 +17,13 @@ class MockCreditService(object): ...@@ -17,13 +17,13 @@ class MockCreditService(object):
Simple mock of the Credit Service Simple mock of the Credit Service
""" """
def __init__(self, enrollment_mode='verified'): def __init__(self, enrollment_mode='verified', profile_fullname='Wolfgang von Strucker'):
""" """
Initializer Initializer
""" """
self.status = { self.status = {
'enrollment_mode': enrollment_mode, 'enrollment_mode': enrollment_mode,
'profile_fullname': 'Wolfgang von Strucker', 'profile_fullname': profile_fullname,
'credit_requirement_status': [] 'credit_requirement_status': []
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment