Skip to content

Commit

Permalink
Merge pull request #308 from edx/schen/ECOM-5392-bug-fix
Browse files Browse the repository at this point in the history
ECOM-5392 Only publish to drupal for MicroMasters Program
  • Loading branch information
schenedx authored Sep 9, 2016
2 parents 431fcfa + 25474f3 commit cae32af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions course_discovery/apps/course_metadata/publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions course_discovery/apps/course_metadata/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions course_discovery/apps/course_metadata/tests/test_publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion course_discovery/apps/course_metadata/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down

0 comments on commit cae32af

Please sign in to comment.