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
2cc017a5
Commit
2cc017a5
authored
Jul 22, 2015
by
Renzo Lucioni
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #218 from edx/renzo/migration-sans-publication
Avoid publishing Courses to the LMS during migration
parents
2b57cece
faae0f1f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
6 deletions
+40
-6
ecommerce/extensions/catalogue/management/commands/migrate_course.py
+7
-2
ecommerce/extensions/catalogue/tests/test_migrate_course.py
+33
-4
No files found.
ecommerce/extensions/catalogue/management/commands/migrate_course.py
View file @
2cc017a5
...
...
@@ -15,7 +15,12 @@ logger = logging.getLogger(__name__)
class
MigratedCourse
(
object
):
def
__init__
(
self
,
course_id
):
self
.
course
,
__
=
Course
.
objects
.
get_or_create
(
id
=
course_id
)
# Avoid use of get_or_create to prevent publication to the
# LMS when saving the newly instantiated Course.
try
:
self
.
course
=
Course
.
objects
.
get
(
id
=
course_id
)
except
Course
.
DoesNotExist
:
self
.
course
=
Course
(
id
=
course_id
)
def
load_from_lms
(
self
,
access_token
):
"""
...
...
@@ -25,7 +30,7 @@ class MigratedCourse(object):
"""
name
,
modes
=
self
.
_retrieve_data_from_lms
(
access_token
)
self
.
course
.
name
=
name
self
.
course
.
save
()
self
.
course
.
save
(
publish
=
False
)
self
.
_get_products
(
modes
)
def
_build_lms_url
(
self
,
path
):
...
...
ecommerce/extensions/catalogue/tests/test_migrate_course.py
View file @
2cc017a5
...
...
@@ -10,11 +10,14 @@ from django.conf import settings
from
django.core.management
import
call_command
from
django.test
import
TestCase
import
httpretty
import
mock
from
oscar.core.loading
import
get_model
import
pytz
from
waffle
import
Switch
from
ecommerce.core.constants
import
ISO_8601_FORMAT
from
ecommerce.courses.models
import
Course
from
ecommerce.courses.publishers
import
LMSPublisher
from
ecommerce.extensions.catalogue.management.commands.migrate_course
import
MigratedCourse
from
ecommerce.extensions.catalogue.tests.mixins
import
CourseCatalogTestMixin
from
ecommerce.extensions.catalogue.utils
import
generate_sku
...
...
@@ -102,6 +105,10 @@ class CourseMigrationTestMixin(CourseCatalogTestMixin):
class
MigratedCourseTests
(
CourseMigrationTestMixin
,
TestCase
):
def
setUp
(
self
):
super
(
MigratedCourseTests
,
self
)
.
setUp
()
Switch
.
objects
.
get_or_create
(
name
=
'publish_course_modes_to_lms'
,
active
=
True
)
def
_migrate_course_from_lms
(
self
):
""" Create a new MigratedCourse and simulate the loading of data from LMS. """
self
.
_mock_lms_api
()
...
...
@@ -112,8 +119,13 @@ class MigratedCourseTests(CourseMigrationTestMixin, TestCase):
@httpretty.activate
def
test_load_from_lms
(
self
):
""" Verify the method creates new objects based on data loaded from the LMS. """
migrated_course
=
self
.
_migrate_course_from_lms
()
course
=
migrated_course
.
course
with
mock
.
patch
.
object
(
LMSPublisher
,
'publish'
)
as
mock_publish
:
mock_publish
.
return_value
=
True
migrated_course
=
self
.
_migrate_course_from_lms
()
course
=
migrated_course
.
course
# Verify that the migrated course was not published back to the LMS
self
.
assertFalse
(
mock_publish
.
called
)
# Ensure LMS was called with the correct headers
for
request
in
httpretty
.
httpretty
.
latest_requests
:
...
...
@@ -132,6 +144,10 @@ class MigratedCourseTests(CourseMigrationTestMixin, TestCase):
class
CommandTests
(
CourseMigrationTestMixin
,
TestCase
):
def
setUp
(
self
):
super
(
CommandTests
,
self
)
.
setUp
()
Switch
.
objects
.
get_or_create
(
name
=
'publish_course_modes_to_lms'
,
active
=
True
)
@httpretty.activate
def
test_handle
(
self
):
""" Verify the management command retrieves data, but does not save it to the database. """
...
...
@@ -139,7 +155,13 @@ class CommandTests(CourseMigrationTestMixin, TestCase):
initial_stock_record_count
=
StockRecord
.
objects
.
count
()
self
.
_mock_lms_api
()
call_command
(
'migrate_course'
,
self
.
course_id
,
access_token
=
ACCESS_TOKEN
)
with
mock
.
patch
.
object
(
LMSPublisher
,
'publish'
)
as
mock_publish
:
mock_publish
.
return_value
=
True
call_command
(
'migrate_course'
,
self
.
course_id
,
access_token
=
ACCESS_TOKEN
)
# Verify that the migrated course was not published back to the LMS
self
.
assertFalse
(
mock_publish
.
called
)
# Ensure LMS was called with the correct headers
for
request
in
httpretty
.
httpretty
.
latest_requests
:
...
...
@@ -153,5 +175,12 @@ class CommandTests(CourseMigrationTestMixin, TestCase):
def
test_handle_with_commit
(
self
):
""" Verify the management command retrieves data, and saves it to the database. """
self
.
_mock_lms_api
()
call_command
(
'migrate_course'
,
self
.
course_id
,
access_token
=
ACCESS_TOKEN
,
commit
=
True
)
with
mock
.
patch
.
object
(
LMSPublisher
,
'publish'
)
as
mock_publish
:
mock_publish
.
return_value
=
True
call_command
(
'migrate_course'
,
self
.
course_id
,
access_token
=
ACCESS_TOKEN
,
commit
=
True
)
# Verify that the migrated course was not published back to the LMS
self
.
assertFalse
(
mock_publish
.
called
)
self
.
assert_course_migrated
()
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