Commit 74eaaa9f by chrisndodge

Merge pull request #235 from edx/cdodge/fix-unicode-conversation

don't allow a blank exam name to be registered with SoftwareSecure ot…
parents bc7f5694 fe69b6a7
...@@ -379,8 +379,16 @@ class SoftwareSecureBackendProvider(ProctoringBackendProvider): ...@@ -379,8 +379,16 @@ class SoftwareSecureBackendProvider(ProctoringBackendProvider):
# remove all illegal characters from the exam name # remove all illegal characters from the exam name
exam_name = exam['exam_name'] exam_name = exam['exam_name']
exam_name = unicodedata.normalize('NFKD', exam_name).encode('ascii', 'ignore') exam_name = unicodedata.normalize('NFKD', exam_name).encode('ascii', 'ignore')
for character in SOFTWARE_SECURE_INVALID_CHARS: for character in SOFTWARE_SECURE_INVALID_CHARS:
exam_name = exam_name.replace(character, '_') exam_name = exam_name.replace(character, '_')
# if exam_name is blank because we can't normalize a potential unicode (like Chinese) exam name
# into something ascii-like, then we have use a default otherwise
# SoftwareSecure will fail on the exam registration API call
if not exam_name:
exam_name = 'Proctored Exam'
return { return {
"examCode": attempt_code, "examCode": attempt_code,
"organization": self.organization, "organization": self.organization,
......
...@@ -292,17 +292,37 @@ class SoftwareSecureTests(TestCase): ...@@ -292,17 +292,37 @@ class SoftwareSecureTests(TestCase):
result = get_backend_provider(emphemeral=True)._get_payload(exam, context) # pylint: disable=protected-access result = get_backend_provider(emphemeral=True)._get_payload(exam, context) # pylint: disable=protected-access
self.assertFalse(isinstance(result['examName'], unicode)) self.assertFalse(isinstance(result['examName'], unicode))
self.assertTrue(is_ascii(result['examName'])) self.assertTrue(is_ascii(result['examName']))
self.assertGreater(len(result['examName']), 0)
return result return result
exam_id = create_exam(
course_id='foo/bar/baz',
content_id='content with unicode characters',
exam_name=u'Klüft skräms inför på fédéral électoral große',
time_limit_mins=10,
is_proctored=True
)
with HTTMock(mock_response_content): with HTTMock(mock_response_content):
exam_id = create_exam(
course_id='foo/bar/baz',
content_id='content with unicode characters',
exam_name=u'Klüft skräms inför på fédéral électoral große',
time_limit_mins=10,
is_proctored=True
)
# patch the _get_payload method on the backend provider
with patch.object(get_backend_provider(), '_get_payload', assert_get_payload_mock_unicode_characters): # pylint: disable=protected-access
attempt_id = create_exam_attempt(
exam_id,
self.user.id,
taking_as_proctored=True
)
self.assertGreater(attempt_id, 0)
# now try with an eastern language (Chinese)
exam_id = create_exam(
course_id='foo/bar/baz',
content_id='content with chinese characters',
exam_name=u'到处群魔乱舞',
time_limit_mins=10,
is_proctored=True
)
# patch the _get_payload method on the backend provider # patch the _get_payload method on the backend provider
with patch.object(get_backend_provider(), '_get_payload', assert_get_payload_mock_unicode_characters): # pylint: disable=protected-access with patch.object(get_backend_provider(), '_get_payload', assert_get_payload_mock_unicode_characters): # pylint: disable=protected-access
attempt_id = create_exam_attempt( attempt_id = create_exam_attempt(
......
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