From 25474f389b5f3c1e97ef18b18f0979468eb83000 Mon Sep 17 00:00:00 2001 From: Simon Chen Date: Fri, 9 Sep 2016 10:04:11 -0400 Subject: [PATCH] ECOM-5392 only publish to drupal for MicroMasters Program --- .../apps/course_metadata/publishers.py | 4 ++++ .../apps/course_metadata/tests/test_models.py | 22 ++++++++++++++----- .../course_metadata/tests/test_publishers.py | 11 ++++++++-- .../course_metadata/tests/test_signals.py | 3 ++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/course_discovery/apps/course_metadata/publishers.py b/course_discovery/apps/course_metadata/publishers.py index 001eaae8b8..f2b87431c6 100644 --- a/course_discovery/apps/course_metadata/publishers.py +++ b/course_discovery/apps/course_metadata/publishers.py @@ -98,6 +98,10 @@ def _get_api_client(self, program): partner=program.partner.short_code) raise ProgramPublisherException(msg) + if program.type.name != 'MicroMasters': + # Currently, we should not publish any programs that are not MicroMasters types to Marketing Site + return + if self.data_before and \ all(self.data_before[key] == getattr(program, key) for key in ['title', 'status', 'type']): # We don't need to publish to marketing site because diff --git a/course_discovery/apps/course_metadata/tests/test_models.py b/course_discovery/apps/course_metadata/tests/test_models.py index f3b3093c5b..72755d0093 100644 --- a/course_discovery/apps/course_metadata/tests/test_models.py +++ b/course_discovery/apps/course_metadata/tests/test_models.py @@ -17,7 +17,7 @@ from course_discovery.apps.course_metadata.models import ( AbstractMediaModel, AbstractNamedModel, AbstractValueModel, CorporateEndorsement, Program, Course, CourseRun, Endorsement, - FAQ, SeatType + FAQ, SeatType, ProgramType, ) from course_discovery.apps.course_metadata.tests import factories, toggle_switch from course_discovery.apps.course_metadata.tests.factories import CourseRunFactory, ImageFactory @@ -407,7 +407,7 @@ def test_save_and_publish_success(self): self.program.partner.marketing_site_url_root = self.api_root self.program.partner.marketing_site_api_username = self.username self.program.partner.marketing_site_api_password = self.password - self.program.save() + self.program.type = ProgramType.objects.get(name='MicroMasters') self.mock_api_client(200) self.mock_node_retrieval(self.program.uuid) self.mock_node_edit(200) @@ -416,10 +416,23 @@ def test_save_and_publish_success(self): self.program.save() self.assert_responses_call_count(6) + @responses.activate + def test_xseries_program_save(self): + """ + Make sure if the Program instance is of type XSeries, we do not publish to Marketing Site + """ + self.program.partner.marketing_site_url_root = self.api_root + self.program.partner.marketing_site_api_username = self.username + self.program.partner.marketing_site_api_password = self.password + self.program.type = ProgramType.objects.get(name='XSeries') + toggle_switch('publish_program_to_marketing_site', True) + self.program.title = FuzzyText().fuzz() + self.program.save() + self.assert_responses_call_count(0) + @responses.activate def test_save_and_no_marketing_site(self): self.program.partner.marketing_site_url_root = None - self.program.save() toggle_switch('publish_program_to_marketing_site', True) self.program.title = FuzzyText().fuzz() self.program.save() @@ -430,7 +443,7 @@ def test_delete_and_publish_success(self): self.program.partner.marketing_site_url_root = self.api_root self.program.partner.marketing_site_api_username = self.username self.program.partner.marketing_site_api_password = self.password - self.program.save() + self.program.type = ProgramType.objects.get(name='MicroMasters') self.mock_api_client(200) self.mock_node_retrieval(self.program.uuid) self.mock_node_delete(204) @@ -441,7 +454,6 @@ def test_delete_and_publish_success(self): @responses.activate def test_delete_and_no_marketing_site(self): self.program.partner.marketing_site_url_root = None - self.program.save() toggle_switch('publish_program_to_marketing_site', True) self.program.delete() self.assert_responses_call_count(0) diff --git a/course_discovery/apps/course_metadata/tests/test_publishers.py b/course_discovery/apps/course_metadata/tests/test_publishers.py index 7802f0af90..d56ac027dc 100644 --- a/course_discovery/apps/course_metadata/tests/test_publishers.py +++ b/course_discovery/apps/course_metadata/tests/test_publishers.py @@ -10,7 +10,7 @@ MarketingSiteAPIClientTestMixin, MarketingSitePublisherTestMixin, ) -from course_discovery.apps.course_metadata.models import Program +from course_discovery.apps.course_metadata.models import Program, ProgramType class MarketingSiteAPIClientTests(MarketingSiteAPIClientTestMixin): @@ -96,6 +96,7 @@ def setUp(self): self.program.partner.marketing_site_url_root = self.api_root self.program.partner.marketing_site_api_username = self.username self.program.partner.marketing_site_api_password = self.password + self.program.type = ProgramType.objects.get(name='MicroMasters') self.program.save() # pylint: disable=no-member self.api_client = MarketingSiteAPIClient( self.username, @@ -216,11 +217,17 @@ def test_publish_unmodified_program(self): publisher.publish_program(self.program) self.assert_responses_call_count(0) + @responses.activate + def test_publish_xseries_program(self): + self.program.type = ProgramType.objects.get(name='XSeries') + publisher = MarketingSitePublisher() + publisher.publish_program(self.program) + self.assert_responses_call_count(0) + @responses.activate def test_publish_program_no_credential(self): self.program.partner.marketing_site_api_password = None self.program.partner.marketing_site_api_username = None - self.program.save() # pylint: disable=no-member publisher = MarketingSitePublisher() with self.assertRaises(ProgramPublisherException): publisher.publish_program(self.program) diff --git a/course_discovery/apps/course_metadata/tests/test_signals.py b/course_discovery/apps/course_metadata/tests/test_signals.py index 334b24e865..b154e4b2cd 100644 --- a/course_discovery/apps/course_metadata/tests/test_signals.py +++ b/course_discovery/apps/course_metadata/tests/test_signals.py @@ -3,6 +3,7 @@ from django.test import TestCase +from course_discovery.apps.course_metadata.models import ProgramType from course_discovery.apps.course_metadata.tests import factories, toggle_switch @@ -13,7 +14,7 @@ class SignalsTest(TestCase): def setUp(self): super(SignalsTest, self).setUp() - self.program = factories.ProgramFactory() + self.program = factories.ProgramFactory(type=ProgramType.objects.get(name='MicroMasters')) def test_delete_program_signal_no_publish(self, delete_program_mock): toggle_switch('publish_program_to_marketing_site', False)