Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
64012cf3
Commit
64012cf3
authored
Oct 06, 2017
by
Simon Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Publish to drupal regardless if the object on discovery is there or not
parent
1d10af69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
25 deletions
+24
-25
course_discovery/apps/course_metadata/publishers.py
+11
-16
course_discovery/apps/course_metadata/tests/test_publishers.py
+13
-9
No files found.
course_discovery/apps/course_metadata/publishers.py
View file @
64012cf3
...
@@ -332,28 +332,23 @@ class CourseRunMarketingSitePublisher(BaseMarketingSitePublisher):
...
@@ -332,28 +332,23 @@ class CourseRunMarketingSitePublisher(BaseMarketingSitePublisher):
"""
"""
logger
.
info
(
'Publishing course run [
%
s] to marketing site...'
,
obj
.
key
)
logger
.
info
(
'Publishing course run [
%
s] to marketing site...'
,
obj
.
key
)
if
previous_obj
:
# let's check if it exists on the marketing site
if
obj
.
status
==
previous_obj
.
status
:
node_id
=
self
.
node_id
(
obj
)
if
node_id
:
# The node exists on marketing site
if
previous_obj
and
obj
.
status
==
previous_obj
.
status
:
logger
.
info
(
logger
.
info
(
'The status of course run [
%
s] has not changed. It will NOT be published to the marketing site.'
,
'The status of course run [
%
s] has not changed. It will NOT be published to the marketing site.'
,
obj
.
key
)
obj
.
key
)
else
:
else
:
node_id
=
self
.
node_id
(
obj
)
node_data
=
self
.
serialize_obj
(
obj
)
node_data
=
self
.
serialize_obj
(
obj
)
self
.
edit_node
(
node_id
,
node_data
)
self
.
edit_node
(
node_id
,
node_data
)
elif
waffle
.
switch_is_active
(
'auto_course_about_page_creation'
):
elif
not
previous_obj
and
waffle
.
switch_is_active
(
'auto_course_about_page_creation'
):
node_data
=
self
.
serialize_obj
(
obj
)
# This is a brand new course_run object
node_id
=
self
.
create_node
(
node_data
)
# let's check if it exists on the marketing site
logger
.
info
(
'Created new marketing site node [
%
s] for course run [
%
s].'
,
node_id
,
obj
.
key
)
node_id
=
self
.
node_id
(
obj
)
self
.
update_node_alias
(
obj
,
node_id
,
previous_obj
)
if
node_id
:
logger
.
info
(
'Marketing site node [
%
s] already exists for course run [
%
s].'
,
node_id
,
obj
.
key
)
else
:
node_data
=
self
.
serialize_obj
(
obj
)
node_id
=
self
.
create_node
(
node_data
)
logger
.
info
(
'Created new marketing site node [
%
s] for course run [
%
s].'
,
node_id
,
obj
.
key
)
self
.
update_node_alias
(
obj
,
node_id
,
None
)
def
serialize_obj
(
self
,
obj
):
def
serialize_obj
(
self
,
obj
):
"""
"""
...
...
course_discovery/apps/course_metadata/tests/test_publishers.py
View file @
64012cf3
...
@@ -207,10 +207,12 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
...
@@ -207,10 +207,12 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
self
.
obj
=
CourseRunFactory
()
self
.
obj
=
CourseRunFactory
()
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
None
)
def
test_publish_obj_create_disabled
(
self
,
mock_node_id
):
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'create_node'
)
def
test_publish_obj_create_disabled
(
self
,
mock_create_node
,
mock_node_id
):
self
.
publisher
.
publish_obj
(
self
.
obj
)
self
.
publisher
.
publish_obj
(
self
.
obj
)
assert
not
mock_node_id
.
called
mock_node_id
.
assert_called_with
(
self
.
obj
)
assert
not
mock_create_node
.
called
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'serialize_obj'
,
return_value
=
'data'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'serialize_obj'
,
return_value
=
'data'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
None
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
None
)
...
@@ -227,22 +229,24 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
...
@@ -227,22 +229,24 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
mock_create_node
.
assert_called_with
(
'data'
)
mock_create_node
.
assert_called_with
(
'data'
)
mock_update_node_alias
.
assert_called_with
(
self
.
obj
,
'node_id'
,
None
)
mock_update_node_alias
.
assert_called_with
(
self
.
obj
,
'node_id'
,
None
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
None
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'serialize_obj'
,
return_value
=
'data'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'serialize_obj'
,
return_value
=
'data'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
'node_id'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'create_node'
,
return_value
=
'node1'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'create_node'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'update_node_alias'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'update_node_alias'
)
def
test_publish_obj_
not_create_if_exists
(
def
test_publish_obj_
create_if_exists_on_discovery
(
self
,
self
,
mock_update_node_alias
,
mock_update_node_alias
,
mock_create_node
,
mock_create_node
,
mock_serialize_obj
,
mock_node_id
,
mock_node_id
,
*
args
*
args
):
# pylint: disable=unused-argument
):
# pylint: disable=unused-argument
toggle_switch
(
'auto_course_about_page_creation'
,
True
)
toggle_switch
(
'auto_course_about_page_creation'
,
True
)
self
.
publisher
.
publish_obj
(
self
.
obj
)
self
.
publisher
.
publish_obj
(
self
.
obj
,
previous_obj
=
self
.
obj
)
mock_node_id
.
assert_called_with
(
self
.
obj
)
mock_node_id
.
assert_called_with
(
self
.
obj
)
assert
not
mock_create_node
.
called
mock_serialize_obj
.
assert_called_with
(
self
.
obj
)
assert
not
mock_update_node_alias
.
called
mock_create_node
.
assert_called_with
(
'data'
)
mock_update_node_alias
.
assert_called_with
(
self
.
obj
,
'node1'
,
self
.
obj
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
'node_id'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'node_id'
,
return_value
=
'node_id'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'serialize_obj'
,
return_value
=
'data'
)
@mock.patch.object
(
CourseRunMarketingSitePublisher
,
'serialize_obj'
,
return_value
=
'data'
)
...
...
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