diff --git a/milestones/api.py b/milestones/api.py index bff7266d..327802e0 100644 --- a/milestones/api.py +++ b/milestones/api.py @@ -209,7 +209,7 @@ def get_course_milestones_fulfillment_paths(course_key, user): # Build the set of fulfillment paths for the outstanding milestones fulfillment_paths = {} for milestone in required_milestones: - dict_key = '{}.{}'.format(milestone['namespace'], milestone['name']) + dict_key = '{}.{}'.format(milestone['namespace'].encode('utf-8'), milestone['name'].encode('utf-8')) fulfillment_paths[dict_key] = {} milestone_courses = data.fetch_milestone_courses( milestone, diff --git a/milestones/tests/test_api.py b/milestones/tests/test_api.py index 9e3a5fb0..28c72d1c 100644 --- a/milestones/tests/test_api.py +++ b/milestones/tests/test_api.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # pylint: disable=invalid-name # pylint: disable=too-many-public-methods """ @@ -693,6 +694,43 @@ def test_remove_content_references(self): milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key) self.assertEqual(len(milestones), 0) + def test_milestones_fulfillment_paths_contains_special_characters(self): + """ + Unit Test: test_get_course_milestones_fulfillment_paths works correctly when milestone have some special + characters. + """ + namespace = unicode(self.test_course_key) + name = '�ťÉśt_Àübùr�' + local_milestone_1 = api.add_milestone({ + 'display_name': 'Local Milestone 1', + 'name': name, + 'namespace': namespace, + 'description': 'Local Milestone 1 Description' + }) + + # Specify the milestone requirements + api.add_course_milestone( + self.test_course_key, + self.relationship_types['REQUIRES'], + local_milestone_1 + ) + + # Specify the milestone fulfillments (via course and content) + api.add_course_milestone( + self.test_prerequisite_course_key, + self.relationship_types['FULFILLS'], + local_milestone_1 + ) + with self.assertNumQueries(4): + paths = api.get_course_milestones_fulfillment_paths( + self.test_course_key, + self.serialized_test_user + ) + + # Set up the key values we'll use to access/assert the response + milestone_key_1 = '{}.{}'.format(local_milestone_1['namespace'], local_milestone_1['name']) + self.assertEqual(len(paths[milestone_key_1]['courses']), 1) + def test_get_course_milestones_fulfillment_paths(self): # pylint: disable=too-many-statements """ Unit Test: test_get_course_milestones_fulfillment_paths