Commit c5af4521 by Renzo Lucioni

Merge pull request #262 from edx/renzo/strip-names

Strip whitespace from course names during migration
parents e8c8c0be 7ddf1f38
...@@ -59,16 +59,16 @@ class MigratedCourse(object): ...@@ -59,16 +59,16 @@ class MigratedCourse(object):
data = response.json() data = response.json()
logger.debug(data) logger.debug(data)
course_name = data['name'] course_name = data.get('name')
if course_name is None: if course_name is None:
message = u'Aborting migration. No name is available for {}.'.format(self.course.id) message = u'Unable to retrieve course name for {}.'.format(self.course.id)
logger.error(message) logger.error(message)
raise Exception(message) raise Exception(message)
course_verification_deadline = data['verification_deadline'] course_verification_deadline = data['verification_deadline']
course_verification_deadline = parse(course_verification_deadline) if course_verification_deadline else None course_verification_deadline = parse(course_verification_deadline) if course_verification_deadline else None
return course_name, course_verification_deadline return course_name.strip(), course_verification_deadline
def _query_course_structure_api(self, access_token): def _query_course_structure_api(self, access_token):
"""Get course name from the Course Structure API.""" """Get course name from the Course Structure API."""
...@@ -89,12 +89,17 @@ class MigratedCourse(object): ...@@ -89,12 +89,17 @@ class MigratedCourse(object):
data = response.json() data = response.json()
logger.debug(data) logger.debug(data)
course_name = data['name'] course_name = data.get('name')
if course_name is None:
message = u'Aborting migration. No name is available for {}.'.format(self.course.id)
logger.error(message)
raise Exception(message)
# A course without entries in the LMS CourseModes table must be an honor course, meaning # A course without entries in the LMS CourseModes table must be an honor course, meaning
# it has no verification deadline. # it has no verification deadline.
course_verification_deadline = None course_verification_deadline = None
return course_name, course_verification_deadline return course_name.strip(), course_verification_deadline
def _query_enrollment_api(self, headers): def _query_enrollment_api(self, headers):
"""Get modes and pricing from Enrollment API.""" """Get modes and pricing from Enrollment API."""
......
...@@ -217,6 +217,28 @@ class MigratedCourseTests(CourseMigrationTestMixin, TestCase): ...@@ -217,6 +217,28 @@ class MigratedCourseTests(CourseMigrationTestMixin, TestCase):
mode = mode_for_seat(seat) mode = mode_for_seat(seat)
self.assert_stock_record_valid(seat.stockrecords.first(), seat, Decimal(self.prices[mode])) self.assert_stock_record_valid(seat.stockrecords.first(), seat, Decimal(self.prices[mode]))
@httpretty.activate
def test_whitespace_stripped(self):
"""Verify that whitespace in course names is stripped during migration."""
self._mock_lms_apis()
body = {
# Wrap the course name with whitespace
'name': ' {} '.format(self.course_name),
'verification_deadline': EXPIRES_STRING,
}
httpretty.register_uri(httpretty.GET, self.commerce_api_url, body=json.dumps(body), content_type=JSON)
migrated_course = MigratedCourse(self.course_id)
migrated_course.load_from_lms(ACCESS_TOKEN)
course = migrated_course.course
# Verify that whitespace has been stripped from the course name.
self.assertEqual(course.name, self.course_name)
parent_seat = course.parent_seat_product
self.assertEqual(parent_seat.title, 'Seat in {}'.format(self.course_name))
@override_settings(EDX_API_KEY=EDX_API_KEY) @override_settings(EDX_API_KEY=EDX_API_KEY)
class CommandTests(CourseMigrationTestMixin, TestCase): class CommandTests(CourseMigrationTestMixin, TestCase):
......
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