Skip to content

Commit 45119ae

Browse files
authored
Merge pull request #35 from edx/noraiz/EDUCATOR-1218
make system tolerant of ascii strings with unicode characters
2 parents 36c4997 + 606f1ca commit 45119ae

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lti_consumer/outcomes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def parse_grade_xml_body(body):
4040
"""
4141
lti_spec_namespace = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"
4242
namespaces = {'def': lti_spec_namespace}
43-
data = body.strip().encode('utf-8')
43+
data = body.strip()
4444

4545
try:
4646
parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8') # pylint: disable=no-member

lti_consumer/tests/unit/test_outcomes.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Unit tests for lti_consumer.outcomes module
34
"""
@@ -288,6 +289,45 @@ def test_invalid_xml(self):
288289
with self.assertRaises(LtiError):
289290
__, __, __, __ = parse_grade_xml_body('<xml>')
290291

292+
def test_string_with_unicode_chars(self):
293+
"""
294+
Test that system is tolerant to data which has unicode chars in
295+
strings which are not specified as unicode.
296+
"""
297+
request_body_template = textwrap.dedent("""
298+
<?xml version="1.0" encoding="UTF-8"?>
299+
<imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
300+
<imsx_POXHeader>
301+
<imsx_POXRequestHeaderInfo>
302+
<imsx_version>V1.0</imsx_version>
303+
<imsx_messageIdentifier>ţéšţ_message_id</imsx_messageIdentifier>
304+
</imsx_POXRequestHeaderInfo>
305+
</imsx_POXHeader>
306+
<imsx_POXBody>
307+
<ţéšţ_action>
308+
<resultRecord>
309+
<sourcedGUID>
310+
<sourcedId>ţéšţ_sourced_id</sourcedId>
311+
</sourcedGUID>
312+
<result>
313+
<resultScore>
314+
<language>en-us</language>
315+
<textString>1.0</textString>
316+
</resultScore>
317+
</result>
318+
</resultRecord>
319+
</ţéšţ_action>
320+
</imsx_POXBody>
321+
</imsx_POXEnvelopeRequest>
322+
""")
323+
324+
msg_id, sourced_id, score, action = parse_grade_xml_body(request_body_template)
325+
326+
self.assertEqual(msg_id, u'ţéšţ_message_id')
327+
self.assertEqual(sourced_id, u'ţéšţ_sourced_id')
328+
self.assertEqual(score, 1.0)
329+
self.assertEqual(action, u'ţéšţ_action')
330+
291331

292332
class TestOutcomeService(TestLtiConsumerXBlock):
293333
"""

0 commit comments

Comments
 (0)