Skip to content
Snippets Groups Projects
Commit 606f1caa authored by noraiz-anwar's avatar noraiz-anwar
Browse files

make system tolerant of ascii strings with unicode characters

parent 36c49977
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,7 @@ def parse_grade_xml_body(body):
"""
lti_spec_namespace = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"
namespaces = {'def': lti_spec_namespace}
data = body.strip().encode('utf-8')
data = body.strip()
try:
parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8') # pylint: disable=no-member
......
# -*- coding: utf-8 -*-
"""
Unit tests for lti_consumer.outcomes module
"""
......@@ -288,6 +289,45 @@ class TestParseGradeXmlBody(unittest.TestCase):
with self.assertRaises(LtiError):
__, __, __, __ = parse_grade_xml_body('<xml>')
def test_string_with_unicode_chars(self):
"""
Test that system is tolerant to data which has unicode chars in
strings which are not specified as unicode.
"""
request_body_template = textwrap.dedent("""
<?xml version="1.0" encoding="UTF-8"?>
<imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
<imsx_POXHeader>
<imsx_POXRequestHeaderInfo>
<imsx_version>V1.0</imsx_version>
<imsx_messageIdentifier>ţéšţ_message_id</imsx_messageIdentifier>
</imsx_POXRequestHeaderInfo>
</imsx_POXHeader>
<imsx_POXBody>
<ţéšţ_action>
<resultRecord>
<sourcedGUID>
<sourcedId>ţéšţ_sourced_id</sourcedId>
</sourcedGUID>
<result>
<resultScore>
<language>en-us</language>
<textString>1.0</textString>
</resultScore>
</result>
</resultRecord>
</ţéšţ_action>
</imsx_POXBody>
</imsx_POXEnvelopeRequest>
""")
msg_id, sourced_id, score, action = parse_grade_xml_body(request_body_template)
self.assertEqual(msg_id, u'ţéšţ_message_id')
self.assertEqual(sourced_id, u'ţéšţ_sourced_id')
self.assertEqual(score, 1.0)
self.assertEqual(action, u'ţéšţ_action')
class TestOutcomeService(TestLtiConsumerXBlock):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment