Commit c2197732 by Diana Huang

Fix test_import and unicode issues.

Handle unicode in get_course_index
parent 638a1aae
...@@ -99,7 +99,7 @@ class ErrorDescriptor(ErrorFields, XModuleDescriptor): ...@@ -99,7 +99,7 @@ class ErrorDescriptor(ErrorFields, XModuleDescriptor):
# real metadata stays in the content, but add a display name # real metadata stays in the content, but add a display name
field_data = DictFieldData({ field_data = DictFieldData({
'error_msg': str(error_msg), 'error_msg': unicode(error_msg),
'contents': contents, 'contents': contents,
'location': location, 'location': location,
'category': 'error' 'category': 'error'
......
...@@ -80,7 +80,7 @@ class MongoConnection(object): ...@@ -80,7 +80,7 @@ class MongoConnection(object):
""" """
Get the course_index from the persistence mechanism whose id is the given key Get the course_index from the persistence mechanism whose id is the given key
""" """
case_regex = r"(?i)^{}$" if ignore_case else r"{}" case_regex = ur"(?i)^{}$" if ignore_case else ur"{}"
return self.course_index.find_one( return self.course_index.find_one(
son.SON([ son.SON([
(key_attr, re.compile(case_regex.format(getattr(key, key_attr)))) (key_attr, re.compile(case_regex.format(getattr(key, key_attr))))
......
...@@ -438,7 +438,7 @@ class ImportTestCase(BaseCourseTestCase): ...@@ -438,7 +438,7 @@ class ImportTestCase(BaseCourseTestCase):
print("course errors:") print("course errors:")
# Expect to find an error/exception about characters in "®esources" # Expect to find an error/exception about characters in "®esources"
expect = "UnicodeEncodeError" expect = "InvalidKeyError"
errors = [ errors = [
(msg.encode("utf-8"), err.encode("utf-8")) (msg.encode("utf-8"), err.encode("utf-8"))
for msg, err for msg, err
......
...@@ -605,7 +605,7 @@ def policy_key(location): ...@@ -605,7 +605,7 @@ def policy_key(location):
Get the key for a location in a policy file. (Since the policy file is Get the key for a location in a policy file. (Since the policy file is
specific to a course, it doesn't need the full location url). specific to a course, it doesn't need the full location url).
""" """
return '{cat}/{name}'.format(cat=location.category, name=location.name) return u'{cat}/{name}'.format(cat=location.category, name=location.name)
Template = namedtuple("Template", "metadata data children") Template = namedtuple("Template", "metadata data children")
......
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