Skip to content

Commit

Permalink
don't allow a blank exam name to be registered with SoftwareSecure ot…
Browse files Browse the repository at this point in the history
…herwise the API call will fail
  • Loading branch information
Chris Dodge committed Nov 23, 2015
1 parent ab676cb commit fe69b6a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
8 changes: 8 additions & 0 deletions edx_proctoring/backends/software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,16 @@ def _get_payload(self, exam, context):
# remove all illegal characters from the exam name
exam_name = exam['exam_name']
exam_name = unicodedata.normalize('NFKD', exam_name).encode('ascii', 'ignore')

for character in SOFTWARE_SECURE_INVALID_CHARS:
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 {
"examCode": attempt_code,
"organization": self.organization,
Expand Down
36 changes: 28 additions & 8 deletions edx_proctoring/backends/tests/test_software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,37 @@ def assert_get_payload_mock_unicode_characters(exam, context):
result = get_backend_provider(emphemeral=True)._get_payload(exam, context) # pylint: disable=protected-access
self.assertFalse(isinstance(result['examName'], unicode))
self.assertTrue(is_ascii(result['examName']))
self.assertGreater(len(result['examName']), 0)
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):

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
with patch.object(get_backend_provider(), '_get_payload', assert_get_payload_mock_unicode_characters): # pylint: disable=protected-access
attempt_id = create_exam_attempt(
Expand Down

0 comments on commit fe69b6a

Please sign in to comment.