-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from edx/schen/ECOM-5402
ECOM-5402 Delete the drupal node when program is hard deleted
- Loading branch information
Showing
7 changed files
with
170 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.db.models.signals import pre_delete | ||
from django.dispatch import receiver | ||
import waffle | ||
|
||
from course_discovery.apps.course_metadata.models import Program | ||
from course_discovery.apps.course_metadata.publishers import MarketingSitePublisher | ||
|
||
|
||
@receiver(pre_delete, sender=Program) | ||
def delete_program(sender, instance, **kwargs): # pylint: disable=unused-argument | ||
if waffle.switch_is_active('publish_program_to_marketing_site') and \ | ||
instance.partner.has_marketing_site: | ||
publisher = MarketingSitePublisher() | ||
publisher.delete_program(instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
course_discovery/apps/course_metadata/tests/test_signals.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# pylint: disable=no-member | ||
from unittest.mock import patch | ||
|
||
from django.test import TestCase | ||
|
||
from course_discovery.apps.course_metadata.tests import factories, toggle_switch | ||
|
||
|
||
MARKETING_SITE_PUBLISHERS_MODULE = 'course_discovery.apps.course_metadata.publishers.MarketingSitePublisher' | ||
|
||
|
||
@patch(MARKETING_SITE_PUBLISHERS_MODULE + '.delete_program') | ||
class SignalsTest(TestCase): | ||
def setUp(self): | ||
super(SignalsTest, self).setUp() | ||
self.program = factories.ProgramFactory() | ||
|
||
def test_delete_program_signal_no_publish(self, delete_program_mock): | ||
toggle_switch('publish_program_to_marketing_site', False) | ||
self.program.delete() | ||
self.assertFalse(delete_program_mock.called) | ||
|
||
def test_delete_program_signal_with_publish(self, delete_program_mock): | ||
toggle_switch('publish_program_to_marketing_site', True) | ||
self.program.delete() | ||
delete_program_mock.assert_called_once_with(self.program) |