Skip to content

Commit

Permalink
Fix 'assert called with' assertions
Browse files Browse the repository at this point in the history
As per python/cpython#100690 , these assertions were a no-op and Python 3.12 guards against this.
  • Loading branch information
gasman committed Oct 4, 2023
1 parent 67de5e9 commit 5838aab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
38 changes: 20 additions & 18 deletions wagtail/admin/tests/pages/test_move_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,32 @@ def test_move_triggers_signals(self):
pre_page_move.disconnect(pre_moved_handler)
post_page_move.disconnect(post_moved_handler)

# parent_page_before returns the non-specific page type, and that's OK
nonspecific_section_a = Page.objects.get(pk=self.section_a.pk)

# 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/",
)
pre_moved_handler.assert_called_with(
signal=mock.ANY,
sender=self.test_page_a.specific_class,
instance=self.test_page_a,
parent_page_before=nonspecific_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/",
)
post_moved_handler.assert_called_with(
signal=mock.ANY,
sender=self.test_page_a.specific_class,
# during the move operation, we reloaded the page as a non-specific instance
instance=Page.objects.get(pk=self.test_page_a.pk),
parent_page_before=nonspecific_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 test_before_move_page_hook(self):
Expand Down
11 changes: 5 additions & 6 deletions wagtail/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ def test_signal_emitted_on_slug_change(self):

# Check the signal was fired
self.assertEqual(handler.call_count, 1)
self.assertTrue(
handler.called_with(
sender=SimplePage,
instance=self.test_page,
instance_before=old_page,
)
handler.assert_called_with(
signal=mock.ANY,
sender=SimplePage,
instance=self.test_page,
instance_before=old_page,
)

def test_signal_not_emitted_on_title_change(self):
Expand Down

0 comments on commit 5838aab

Please sign in to comment.