def test_bulk_move_triggers_signals(self): # Connect a mock signal handler to pre_page_move and post_page_move signals pre_moved_handler = mock.MagicMock() post_moved_handler = mock.MagicMock() pre_page_move.connect(pre_moved_handler) post_page_move.connect(post_moved_handler) # Post to view confirm move page try: self.client.post(self.url, {'chooser': self.section_b.id}) finally: # Disconnect mock handler to prevent cross-test pollution pre_page_move.disconnect(pre_moved_handler) post_page_move.disconnect(post_moved_handler) # Check that the pre_page_move signals were fired self.assertTrue(pre_moved_handler.mock_calls[0].called_with( sender=self.test_page_b.specific_class, instance=self.test_page_b, parent_page_before=self.section_c, parent_page_after=self.section_b, url_path_before='/home/section-c/hello-world-b/', url_path_after='/home/section-b/hello-world-b/', )) self.assertTrue(pre_moved_handler.mock_calls[1].called_with( sender=self.test_page_b_1.specific_class, instance=self.test_page_b_1, parent_page_before=self.section_c, parent_page_after=self.section_b, url_path_before='/home/section-c/hello-world-b-1/', url_path_after='/home/section-b/hello-world-b-1/', )) # Check that the post_page_move signals were fired self.assertTrue(post_moved_handler.mock_calls[0].called_with( sender=self.test_page_b.specific_class, instance=self.test_page_b, parent_page_before=self.section_c, parent_page_after=self.section_b, url_path_before='/home/section-c/hello-world-b/', url_path_after='/home/section-b/hello-world-b/', )) self.assertTrue(post_moved_handler.mock_calls[1].called_with( sender=self.test_page_b_1.specific_class, instance=self.test_page_b_1, parent_page_before=self.section_c, parent_page_after=self.section_b, url_path_before='/home/section-c/hello-world-b-1/', url_path_after='/home/section-b/hello-world-b-1/', ))
def test_move_triggers_signals(self): # Connect a mock signal handler to pre_page_move and post_page_move signals pre_moved_handler = mock.MagicMock() post_moved_handler = mock.MagicMock() pre_page_move.connect(pre_moved_handler) post_page_move.connect(post_moved_handler) # Post to view to move page try: self.client.post( reverse( "wagtailadmin_pages:move_confirm", args=(self.test_page_a.id, self.section_b.id), )) finally: # Disconnect mock handler to prevent cross-test pollution pre_page_move.disconnect(pre_moved_handler) post_page_move.disconnect(post_moved_handler) # Check that the pre_page_move signal was fired self.assertEqual(pre_moved_handler.call_count, 1) self.assertTrue( pre_moved_handler.called_with( sender=self.test_page_a.specific_class, instance=self.test_page_a, parent_page_before=self.section_a, parent_page_after=self.section_b, url_path_before="/home/section-a/hello-world/", url_path_after="/home/section-b/hello-world/", )) # Check that the post_page_move signal was fired self.assertEqual(post_moved_handler.call_count, 1) self.assertTrue( post_moved_handler.called_with( sender=self.test_page_a.specific_class, instance=self.test_page_a, parent_page_before=self.section_a, parent_page_after=self.section_b, url_path_before="/home/section-a/hello-world/", url_path_after="/home/section-b/hello-world/", ))
def setup(self): # Wagtail Specific Events page_published.connect(self.handle_save) page_unpublished.connect(self.handle_delete) pre_page_move.connect(self.handle_delete) post_page_move.connect(self.handle_save)