Skip to content

Commit 2386bf9

Browse files
committed
Fix added and improved the versioning tests
1 parent 079ac8e commit 2386bf9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
=========
44

5+
Unreleased
6+
==================
7+
* fix: Error when rendering a Draft Snippet plugin on a Published page
8+
* feat: djangocms-versioning support added, including model restructure and configuration
9+
* feat: django-cms v4.0.x support added
10+
511

612
3.0.0 (2020-09-02)
713
==================

djangocms_snippet/cms_plugins.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class SnippetPlugin(CMSPluginBase):
2424

2525
def render(self, context, instance, placeholder):
2626
snippet = instance.snippet_grouper.snippet(show_editable=show_draft_content(context["request"]))
27+
28+
# Handle the potential for no snippet to be found i.e. Draft
29+
if not snippet:
30+
return context
31+
2732
try:
2833
if snippet.template:
2934
context = context.flatten()

tests/test_plugins.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def test_correct_versioning_state_published_snippet_and_page(self):
196196
response = self.client.get(request_url)
197197

198198
self.assertContains(response, "<p>live content</p>")
199+
self.assertNotIn("draft content", str(response.content))
199200

200201
def test_correct_versioning_state_draft_snippet_and_page(self):
201202
"""
@@ -222,6 +223,7 @@ def test_correct_versioning_state_draft_snippet_and_page(self):
222223
response = self.client.get(request_url)
223224

224225
self.assertContains(response, "<p>draft content</p>")
226+
self.assertNotIn("live content", str(response.content))
225227

226228
def test_draft_snippet_and_page_live_url_rendering(self):
227229
"""
@@ -252,7 +254,9 @@ def test_draft_snippet_and_page_live_url_rendering(self):
252254
with self.login_user_context(self.superuser):
253255
response = self.client.get(request_url)
254256

255-
self.assertContains(response, "<p>Draft snippet</p>")
257+
self.assertEqual(response.status_code, 200)
258+
self.assertNotIn("Draft snippet", str(response.content))
259+
self.assertNotIn("Published snippet", str(response.content))
256260

257261
def test_published_snippet_and_page_live_url_rendering(self):
258262
"""
@@ -285,3 +289,4 @@ def test_published_snippet_and_page_live_url_rendering(self):
285289
response = self.client.get(request_url)
286290

287291
self.assertContains(response, "<p>Published snippet</p>")
292+
self.assertNotIn("Draft snippet", str(response.content))

0 commit comments

Comments
 (0)