From f96e03bdaa26b3cdf6eb4aba1c322ff3a89e24ab Mon Sep 17 00:00:00 2001 From: Andy Chosak Date: Thu, 4 Jan 2024 10:06:07 -0500 Subject: [PATCH] Fix deprecation warning in Wagtail 5.2 Wagtail 5.2 changes the signature of the register_page_header_buttons and register_page_listing_more_buttons hooks, causing a deprecation warning. This commit alters the hook function signature to comply with both the old and new hook specifications. Fixes issue 72. --- wagtailsharing/tests/test_wagtail_hooks.py | 7 +++---- wagtailsharing/wagtail_hooks.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/wagtailsharing/tests/test_wagtail_hooks.py b/wagtailsharing/tests/test_wagtail_hooks.py index 4516043..b3a56de 100644 --- a/wagtailsharing/tests/test_wagtail_hooks.py +++ b/wagtailsharing/tests/test_wagtail_hooks.py @@ -1,4 +1,4 @@ -from unittest.mock import Mock, patch +from unittest.mock import patch from django.conf import settings from django.http import HttpResponse @@ -16,13 +16,12 @@ class TestAddSharingLink(TestCase): def setUp(self): self.page = TestPage(title="title", slug="slug") - self.page_perms = Mock() def test_no_link_no_button(self): with patch( "wagtailsharing.wagtail_hooks.get_sharing_url", return_value=None ): - links = add_sharing_link(self.page, self.page_perms) + links = add_sharing_link(self.page) self.assertFalse(list(links)) def test_link_makes_button(self): @@ -30,7 +29,7 @@ def test_link_makes_button(self): with patch( "wagtailsharing.wagtail_hooks.get_sharing_url", return_value=url ): - links = add_sharing_link(self.page, self.page_perms) + links = add_sharing_link(self.page) button = next(links) self.assertEqual(button.url, url) self.assertIn( diff --git a/wagtailsharing/wagtail_hooks.py b/wagtailsharing/wagtail_hooks.py index 5461e16..fd032e9 100644 --- a/wagtailsharing/wagtail_hooks.py +++ b/wagtailsharing/wagtail_hooks.py @@ -27,7 +27,7 @@ class SharingSiteViewSet(SnippetViewSet): @hooks.register("register_page_header_buttons") @hooks.register("register_page_listing_more_buttons") -def add_sharing_link(page, page_perms, is_parent=False, next_url=None): +def add_sharing_link(page, **kwargs): sharing_url = get_sharing_url(page) if sharing_url: