Commit 59ae0bed by Simon Chen

Add a waffle switch so we can dynamically control the auto creation of course…

Add a waffle switch so we can dynamically control the auto creation of course about page on marketing site
parent 96eac3b5
from django.db import migrations
def create_switch(apps, schema_editor):
Switch = apps.get_model('waffle', 'Switch')
Switch.objects.get_or_create(name='auto_course_about_page_creation', defaults={'active': False})
def delete_switch(apps, schema_editor):
Switch = apps.get_model('waffle', 'Switch')
Switch.objects.filter(name='auto_course_about_page_creation').delete()
class Migration(migrations.Migration):
dependencies = [
('course_metadata', '0057_auto_20170915_1528'),
('waffle', '0001_initial'),
]
operations = [
migrations.RunPython(create_switch, delete_switch),
]
import json import json
from urllib.parse import urljoin from urllib.parse import urljoin
import waffle
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from django.utils.text import slugify from django.utils.text import slugify
...@@ -331,7 +332,7 @@ class CourseRunMarketingSitePublisher(BaseMarketingSitePublisher): ...@@ -331,7 +332,7 @@ class CourseRunMarketingSitePublisher(BaseMarketingSitePublisher):
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 not previous_obj: elif not previous_obj and waffle.switch_is_active('auto_course_about_page_creation'):
# This is a brand new course_run object # This is a brand new course_run object
# let's check if it exists on the marketing site # let's check if it exists on the marketing site
node_id = self.node_id(obj) node_id = self.node_id(obj)
......
...@@ -20,6 +20,7 @@ from course_discovery.apps.course_metadata.publishers import ( ...@@ -20,6 +20,7 @@ from course_discovery.apps.course_metadata.publishers import (
CourseRunMarketingSitePublisher, CourseRunMarketingSitePublisher,
ProgramMarketingSitePublisher ProgramMarketingSitePublisher
) )
from course_discovery.apps.course_metadata.tests import toggle_switch
from course_discovery.apps.course_metadata.tests.factories import CourseRunFactory, ProgramFactory from course_discovery.apps.course_metadata.tests.factories import CourseRunFactory, ProgramFactory
from course_discovery.apps.course_metadata.tests.mixins import MarketingSitePublisherTestMixin from course_discovery.apps.course_metadata.tests.mixins import MarketingSitePublisherTestMixin
...@@ -206,6 +207,11 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin): ...@@ -206,6 +207,11 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
self.obj = CourseRunFactory() self.obj = CourseRunFactory()
@mock.patch.object(CourseRunMarketingSitePublisher, 'node_id')
def test_publish_obj_create_disabled(self, mock_node_id):
self.publisher.publish_obj(self.obj)
assert not mock_node_id.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)
@mock.patch.object(CourseRunMarketingSitePublisher, 'create_node', return_value='node_id') @mock.patch.object(CourseRunMarketingSitePublisher, 'create_node', return_value='node_id')
...@@ -216,6 +222,7 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin): ...@@ -216,6 +222,7 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
mock_create_node, mock_create_node,
*args *args
): # pylint: disable=unused-argument ): # pylint: disable=unused-argument
toggle_switch('auto_course_about_page_creation', True)
self.publisher.publish_obj(self.obj) self.publisher.publish_obj(self.obj)
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)
...@@ -231,6 +238,7 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin): ...@@ -231,6 +238,7 @@ class CourseRunMarketingSitePublisherTests(MarketingSitePublisherTestMixin):
mock_node_id, mock_node_id,
*args *args
): # pylint: disable=unused-argument ): # pylint: disable=unused-argument
toggle_switch('auto_course_about_page_creation', True)
self.publisher.publish_obj(self.obj) self.publisher.publish_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 assert not mock_create_node.called
......
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