diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 1551eaab29..266e693abc 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -10,7 +10,7 @@ from django.utils import timezone from wagtail.tests.models import SimplePage, EventPage, EventPageCarouselItem, StandardIndex, BusinessIndex, BusinessChild, BusinessSubIndex from wagtail.tests.utils import unittest, WagtailTestUtils from wagtail.wagtailcore.models import Page, PageRevision -from wagtail.wagtailcore.signals import page_published +from wagtail.wagtailcore.signals import page_published, page_unpublished from wagtail.wagtailusers.models import UserProfile @@ -796,6 +796,15 @@ class TestPageDelete(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 403) def test_page_delete_post(self): + # Connect a mock signal handler to page_unpublished signal + signal_fired = [False] + signal_page = [None] + def page_unpublished_handler(sender, instance, **kwargs): + signal_fired[0] = True + signal_page[0] = instance + page_unpublished.connect(page_unpublished_handler) + + # Post post_data = {'hello': 'world'} # For some reason, this test doesn't work without a bit of POST data response = self.client.post(reverse('wagtailadmin_pages_delete', args=(self.child_page.id, )), post_data) @@ -805,6 +814,11 @@ class TestPageDelete(TestCase, WagtailTestUtils): # Check that the page is gone self.assertEqual(Page.objects.filter(path__startswith=self.root_page.path, slug='hello-world').count(), 0) + # Check that the page_unpublished signal was fired + self.assertTrue(signal_fired[0]) + self.assertEqual(signal_page[0], self.child_page) + self.assertEqual(signal_page[0], signal_page[0].specific) + class TestPageSearch(TestCase, WagtailTestUtils): def setUp(self): @@ -954,6 +968,14 @@ class TestPageUnpublish(TestCase, WagtailTestUtils): """ This posts to the unpublish view and checks that the page was unpublished """ + # Connect a mock signal handler to page_unpublished signal + signal_fired = [False] + signal_page = [None] + def page_unpublished_handler(sender, instance, **kwargs): + signal_fired[0] = True + signal_page[0] = instance + page_unpublished.connect(page_unpublished_handler) + # Post to the unpublish page response = self.client.post(reverse('wagtailadmin_pages_unpublish', args=(self.page.id, )), { 'foo': "Must post something or the view won't see this as a POST request", @@ -965,6 +987,11 @@ class TestPageUnpublish(TestCase, WagtailTestUtils): # Check that the page was unpublished self.assertFalse(SimplePage.objects.get(id=self.page.id).live) + # Check that the page_unpublished signal was fired + self.assertTrue(signal_fired[0]) + self.assertEqual(signal_page[0], self.page) + self.assertEqual(signal_page[0], signal_page[0].specific) + class TestApproveRejectModeration(TestCase, WagtailTestUtils): def setUp(self):