Skip to content

Commit c41840f

Browse files
chore: Added tests for GetAdminUrlForLanguage template tag (#8049)
* fix: setting partial admin_content_cache was responsible for rendering create forms inside the admin language tabs * Update pagemodel.py to also include latest versions in language tabs if they are unpublished or archived * fix: remove get_object on PageContentAdmin * chore: Introduce AdminCacheDict * chore: add tests for the GetAdminUrlForLanguage template tag * chore: don't assume primary keys in templatetag tests * chore: fix spelling problem * chore: restructure GetAdminUrlForLanguage tests, add one that tests partial cache presence * chore: merge GetAdminUrlForLanguage template tag tests into one * Update cms/tests/test_templatetags.py Co-authored-by: Fabian Braun <fsbraun@gmx.de> * Update cms/tests/test_templatetags.py Co-authored-by: Fabian Braun <fsbraun@gmx.de> --------- Co-authored-by: Fabian Braun <fsbraun@gmx.de>
1 parent db0a0c7 commit c41840f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

cms/tests/test_templatetags.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
PageUrl,
2828
Placeholder,
2929
)
30-
from cms.templatetags.cms_admin import GetPreviewUrl, get_page_display_name
30+
from cms.templatetags.cms_admin import GetAdminUrlForLanguage, GetPreviewUrl, get_page_display_name
3131
from cms.templatetags.cms_js_tags import json_filter
3232
from cms.templatetags.cms_tags import (
3333
_get_page_by_untyped_arg,
@@ -43,6 +43,28 @@
4343

4444

4545
class TemplatetagTests(CMSTestCase):
46+
def test_admin_pagecontent_language_tab_urls(self):
47+
# Same setup as in the templatetag test above
48+
page = create_page('AdminURLTestPage English Content', 'nav_playground.html', 'en')
49+
english_content = page.pagecontent_set(manager="admin_manager").first()
50+
german_content = create_page_content("de", "AdminURLTestPage German Content", page)
51+
52+
# Try to fill the cache with partial data (this should not be possible)
53+
page.get_content_obj(language='en') # should not affect admin template tag
54+
page.get_admin_content(language='en') # Should fill the whole cache
55+
56+
request = RequestFactory().get('/')
57+
request.current_page = page
58+
template = """
59+
{% load cms_tags cms_admin %}
60+
{% get_admin_url_for_language page_obj 'en' %}
61+
{% get_admin_url_for_language page_obj 'de' %}
62+
{% get_admin_url_for_language page_obj 'fr' %}
63+
"""
64+
output = self.render_template_obj(template, {'page_obj': page}, request)
65+
self.assertIn(f'/en/admin/cms/pagecontent/{english_content.pk}/change/', output)
66+
self.assertIn(f'/en/admin/cms/pagecontent/{german_content.pk}/change/', output)
67+
self.assertIn(f'/en/admin/cms/pagecontent/add/?cms_page={page.pk}&language=fr', output)
4668

4769
def test_get_preview_url(self):
4870
"""The get_preview_url template tag returns the content preview url for its language:

0 commit comments

Comments
 (0)