Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
7ddf1f38
Commit
7ddf1f38
authored
Aug 07, 2015
by
Renzo Lucioni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strip whitespace from course names during migration
XCOM-552.
parent
e8c8c0be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
ecommerce/extensions/catalogue/management/commands/migrate_course.py
+10
-5
ecommerce/extensions/catalogue/tests/test_migrate_course.py
+22
-0
No files found.
ecommerce/extensions/catalogue/management/commands/migrate_course.py
View file @
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 availabl
e for {}.'
.
format
(
self
.
course
.
id
)
message
=
u'
Unable to retrieve course nam
e 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."""
...
...
ecommerce/extensions/catalogue/tests/test_migrate_course.py
View file @
7ddf1f38
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment