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): ...@@ -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):
""" """
......
...@@ -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')
......
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