Commit 64012cf3 by Simon Chen

Publish to drupal regardless if the object on discovery is there or not

parent 1d10af69
......@@ -332,28 +332,23 @@ class CourseRunMarketingSitePublisher(BaseMarketingSitePublisher):
"""
logger.info('Publishing course run [%s] to marketing site...', obj.key)
if previous_obj:
if obj.status == previous_obj.status:
# let's check if it exists on the marketing site
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(
'The status of course run [%s] has not changed. It will NOT be published to the marketing site.',
obj.key)
else:
node_id = self.node_id(obj)
node_data = self.serialize_obj(obj)
self.edit_node(node_id, node_data)
elif not previous_obj and waffle.switch_is_active('auto_course_about_page_creation'):
# This is a brand new course_run object
# let's check if it exists on the marketing site
node_id = self.node_id(obj)
if node_id:
logger.info('Marketing site node [%s] already exists for course run [%s].', node_id, obj.key)
else:
elif waffle.switch_is_active('auto_course_about_page_creation'):
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)
self.update_node_alias(obj, node_id, previous_obj)
def serialize_obj(self, obj):
"""
......
......@@ -207,10 +207,12 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
self.obj = CourseRunFactory()
@mock.patch.object(CourseRunMarketingSitePublisher, 'node_id')
def test_publish_obj_create_disabled(self, mock_node_id):
@mock.patch.object(CourseRunMarketingSitePublisher, 'node_id', return_value=None)
@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)
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, 'node_id', return_value=None)
......@@ -227,22 +229,24 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
mock_create_node.assert_called_with('data')
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, 'node_id', return_value='node_id')
@mock.patch.object(CourseRunMarketingSitePublisher, 'create_node')
@mock.patch.object(CourseRunMarketingSitePublisher, 'create_node', return_value='node1')
@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,
mock_update_node_alias,
mock_create_node,
mock_serialize_obj,
mock_node_id,
*args
): # pylint: disable=unused-argument
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)
assert not mock_create_node.called
assert not mock_update_node_alias.called
mock_serialize_obj.assert_called_with(self.obj)
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, 'serialize_obj', return_value='data')
......
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