Skip to content

chore: Add test for editor note plugin #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions djangocms_frontend/templatetags/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def is_inline_editing_active(context: template.Context) -> bool:


def update_component_properties(context: template.Context, key: str, value: typing.Any, append: bool = False) -> None:
""""Adds or appends the value to the property "key" of a component during delcaration"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (typo): Docstring has an extra quote and a typo

Please remove the extra quote at the start and correct the spelling of 'declaration' in the docstring.

Suggested change
""""Adds or appends the value to the property "key" of a component during delcaration"""
"""Adds or appends the value to the property "key" of a component during declaration"""

""" "Adds or appends the value to the property "key" of a component during delcaration"""
args, kwargs = context["_cms_components"]["cms_component"][0]
if append:
# Populate slots with plugin_type and verbose_name
Expand Down Expand Up @@ -318,11 +318,7 @@ def render_tag(self, context, instance, attribute, **kwargs):

if is_registering_component(context) and attribute:
update_component_properties(context, "frontend_editable_fields", attribute, append=True)
elif (
is_inline_editing_active(context)
and isinstance(instance, CMSPlugin)
and instance.pk
):
elif is_inline_editing_active(context) and isinstance(instance, CMSPlugin) and instance.pk:
# Only allow inline field to be rendered if inline editing is active and the instance is a CMSPlugin
# DummyPlugins of the ``plugin`` tag are cannot be edited (they have no pk in their model class)
kwargs["edit_fields"] = attribute
Expand Down
5 changes: 3 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def setUp(self):
title="content",
template="page.html",
)
self.publish(self.page, self.language)
self.placeholder = self.get_placeholders(self.page).get(slot="content")
self.request_url = (
self.page.get_absolute_url(self.language) + "?toolbar_off=true"
Expand Down Expand Up @@ -80,7 +79,9 @@ def create_page(self, title, **kwargs):
return create_page(title=title, **kwargs)

def get_placeholders(self, page):
return page.get_placeholders(self.language)
from cms.models import Placeholder, PageContent
page_content = PageContent.admin_manager.latest_content().get(language=self.language, page=self.page)
return Placeholder.objects.get_for_obj(page_content)

try:
import djangocms_url_manager as __just_testing__
Expand Down
50 changes: 50 additions & 0 deletions tests/utilities/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from unittest import skipIf
from cms import __version__ as cms_version
from cms.api import add_plugin
from cms.test_utils.testcases import CMSTestCase
from cms.utils.urlutils import admin_reverse

from djangocms_text.cms_plugins import TextPlugin

from djangocms_frontend.contrib.utilities.cms_plugins import (
EditorNotePlugin,
HeadingPlugin,
SpacingPlugin,
TOCPlugin,
Expand Down Expand Up @@ -117,3 +122,48 @@ def test_heading_inline_endpoint(self):
heading.refresh_from_db()
self.assertEqual(heading.heading, "My new heading") # New data
self.assertEqual(heading.heading_id, "id1") # Other fields unchanged

def test_editor_note(self):
editor_note = add_plugin(
placeholder=self.placeholder,
plugin_type=EditorNotePlugin.__name__,
language=self.language,
)
add_plugin(
placeholder=self.placeholder,
plugin_type=TextPlugin.__name__,
language=self.language,
target=editor_note,
body="<p>My private note</p>",
)
self.publish(self.page, self.language)

with self.login_user_context(self.superuser):
response = self.client.get(self.request_url)
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, 'My private note')

@skipIf(cms_version < "4", "django CMS 4+ required")
def test_editor_note_with_cms4(self):
from cms.toolbar.utils import get_object_edit_url

editor_note = add_plugin(
placeholder=self.placeholder,
plugin_type=EditorNotePlugin.__name__,
language=self.language,
)
add_plugin(
placeholder=self.placeholder,
plugin_type=TextPlugin.__name__,
language=self.language,
target=editor_note,
body="<p>My private note</p>",
)

endpoint = get_object_edit_url(self.page.get_admin_content("en"))

with self.login_user_context(self.superuser):
response = self.client.get(endpoint)
print(response.content)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'My private note')
Loading