Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Sep 22, 2024
1 parent 2aa9872 commit 99715af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def get_page_content(self, language: Optional[str] = None) -> PageContent:
if not language:
language = self.current_lang

if self.page_content and self.page_content.language == language:
if isinstance(self.page_content, PageContent) and self.page_content.language == language:
# Already known - no need to query it again
return self.page_content
toolbar_obj = self.toolbar.get_object()
Expand Down
2 changes: 1 addition & 1 deletion djangocms_versioning/test_utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_toolbar(content_obj, user=None, **kwargs):
request = kwargs.get("request", RequestFactory().get("/"))
request.user = user
request.session = kwargs.get("session", {})
request.current_page = getattr(content_obj, "page", None)
request.current_page = kwargs.get("current_page", getattr(content_obj, "page", None))
request.toolbar = CMSToolbar(request)
# Set the toolbar class
if kwargs.get("toolbar_class", False):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from django.utils.text import slugify

from djangocms_versioning.cms_config import VersioningCMSConfig
from djangocms_versioning.cms_toolbars import VersioningPageToolbar
from djangocms_versioning.constants import ARCHIVED, DRAFT, PUBLISHED
from djangocms_versioning.helpers import version_list_url
from djangocms_versioning.test_utils.factories import (
BlogPostVersionFactory,
FancyPollFactory,
PageContentWithVersionFactory,
PageFactory,
PageUrlFactory,
PageVersionFactory,
PollVersionFactory,
Expand Down Expand Up @@ -615,3 +617,20 @@ def test_page_toolbar_wo_language_menu(self):

language_menu = request.toolbar.get_menu(LANGUAGE_MENU_IDENTIFIER, _("Language"))
self.assertIsNone(language_menu)

def test_toolbar_only_catches_page_content_objects(self):
"""Regression test to ensure that the toolbar only catches PageContent objects and not
other toolbar objects."""

version = PollVersionFactory() # Not a page content model
page = PageFactory() # Get a page, e.g. where an apphook is configured
request_toolbar = get_toolbar(
version.content, edit_mode=True, toolbar_class=VersioningPageToolbar, current_page=page
)

for toolbar in request_toolbar.toolbar.toolbars.values():
if hasattr(toolbar, "page_content"):
# Did page get detected? Otherwise, page_content never will be detected
self.assertIs(toolbar.page, page)
self.assertNotIsInstance(toolbar.page_content, version.content.__class__) # Regression
self.assertIsNone(toolbar.page_content) # Correct result

0 comments on commit 99715af

Please sign in to comment.