Skip to content

Commit

Permalink
Fix deprecation warning in Wagtail 5.2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chosak committed Jan 4, 2024
1 parent 705f5a5 commit f96e03b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions wagtailsharing/tests/test_wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,21 +16,20 @@
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):
url = "http://test.domain/slug/"
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(
Expand Down
2 changes: 1 addition & 1 deletion wagtailsharing/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f96e03b

Please sign in to comment.