Skip to content

Commit 1ef2bc7

Browse files
authored
chore: Add test for editor note plugin (#281)
1 parent 35d4231 commit 1ef2bc7

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

djangocms_frontend/templatetags/frontend.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def is_inline_editing_active(context: template.Context) -> bool:
3939

4040

4141
def update_component_properties(context: template.Context, key: str, value: typing.Any, append: bool = False) -> None:
42-
""""Adds or appends the value to the property "key" of a component during delcaration"""
42+
""" "Adds or appends the value to the property "key" of a component during delcaration"""
4343
args, kwargs = context["_cms_components"]["cms_component"][0]
4444
if append:
4545
# Populate slots with plugin_type and verbose_name
@@ -318,11 +318,7 @@ def render_tag(self, context, instance, attribute, **kwargs):
318318

319319
if is_registering_component(context) and attribute:
320320
update_component_properties(context, "frontend_editable_fields", attribute, append=True)
321-
elif (
322-
is_inline_editing_active(context)
323-
and isinstance(instance, CMSPlugin)
324-
and instance.pk
325-
):
321+
elif is_inline_editing_active(context) and isinstance(instance, CMSPlugin) and instance.pk:
326322
# Only allow inline field to be rendered if inline editing is active and the instance is a CMSPlugin
327323
# DummyPlugins of the ``plugin`` tag are cannot be edited (they have no pk in their model class)
328324
kwargs["edit_fields"] = attribute

tests/fixtures.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def setUp(self):
2222
title="content",
2323
template="page.html",
2424
)
25-
self.publish(self.page, self.language)
2625
self.placeholder = self.get_placeholders(self.page).get(slot="content")
2726
self.request_url = (
2827
self.page.get_absolute_url(self.language) + "?toolbar_off=true"
@@ -80,7 +79,9 @@ def create_page(self, title, **kwargs):
8079
return create_page(title=title, **kwargs)
8180

8281
def get_placeholders(self, page):
83-
return page.get_placeholders(self.language)
82+
from cms.models import Placeholder, PageContent
83+
page_content = PageContent.admin_manager.latest_content().get(language=self.language, page=self.page)
84+
return Placeholder.objects.get_for_obj(page_content)
8485

8586
try:
8687
import djangocms_url_manager as __just_testing__

tests/utilities/test_plugins.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from unittest import skipIf
2+
from cms import __version__ as cms_version
13
from cms.api import add_plugin
24
from cms.test_utils.testcases import CMSTestCase
35
from cms.utils.urlutils import admin_reverse
46

7+
from djangocms_text.cms_plugins import TextPlugin
8+
59
from djangocms_frontend.contrib.utilities.cms_plugins import (
10+
EditorNotePlugin,
611
HeadingPlugin,
712
SpacingPlugin,
813
TOCPlugin,
@@ -117,3 +122,48 @@ def test_heading_inline_endpoint(self):
117122
heading.refresh_from_db()
118123
self.assertEqual(heading.heading, "My new heading") # New data
119124
self.assertEqual(heading.heading_id, "id1") # Other fields unchanged
125+
126+
def test_editor_note(self):
127+
editor_note = add_plugin(
128+
placeholder=self.placeholder,
129+
plugin_type=EditorNotePlugin.__name__,
130+
language=self.language,
131+
)
132+
add_plugin(
133+
placeholder=self.placeholder,
134+
plugin_type=TextPlugin.__name__,
135+
language=self.language,
136+
target=editor_note,
137+
body="<p>My private note</p>",
138+
)
139+
self.publish(self.page, self.language)
140+
141+
with self.login_user_context(self.superuser):
142+
response = self.client.get(self.request_url)
143+
self.assertEqual(response.status_code, 200)
144+
self.assertNotContains(response, 'My private note')
145+
146+
@skipIf(cms_version < "4", "django CMS 4+ required")
147+
def test_editor_note_with_cms4(self):
148+
from cms.toolbar.utils import get_object_edit_url
149+
150+
editor_note = add_plugin(
151+
placeholder=self.placeholder,
152+
plugin_type=EditorNotePlugin.__name__,
153+
language=self.language,
154+
)
155+
add_plugin(
156+
placeholder=self.placeholder,
157+
plugin_type=TextPlugin.__name__,
158+
language=self.language,
159+
target=editor_note,
160+
body="<p>My private note</p>",
161+
)
162+
163+
endpoint = get_object_edit_url(self.page.get_admin_content("en"))
164+
165+
with self.login_user_context(self.superuser):
166+
response = self.client.get(endpoint)
167+
print(response.content)
168+
self.assertEqual(response.status_code, 200)
169+
self.assertContains(response, 'My private note')

0 commit comments

Comments
 (0)