From e8944dcd48d79fe5ad51bef65501bda0001aca35 Mon Sep 17 00:00:00 2001 From: Conor Holden Date: Mon, 9 Dec 2024 16:29:23 +0100 Subject: [PATCH] :white_check_mark: fix tests --- djangocms_export_page/export/common.py | 4 ++-- testapp/models.py | 19 +++++++++++++++++ testapp/settings.py | 28 ++++++++++++++++++++++++++ {tests => testapp}/templates/test.html | 0 testapp/urls.py | 6 +++++- tests/test_models.py | 3 +-- tests/test_pages.py | 26 +++++++++++++++++------- 7 files changed, 74 insertions(+), 12 deletions(-) rename {tests => testapp}/templates/test.html (100%) diff --git a/djangocms_export_page/export/common.py b/djangocms_export_page/export/common.py index 9b50d11..c8fa174 100644 --- a/djangocms_export_page/export/common.py +++ b/djangocms_export_page/export/common.py @@ -102,7 +102,7 @@ def get_base_url(self): def get_page_url(self): return "{domain}{url}".format( - domain=self.get_base_url(), url=self.object.get_absolute_url() + domain=self.get_base_url(), url=self.object.get_absolute_url(self.language) ) def export(self): @@ -180,7 +180,7 @@ def get_placeholders(self): for ( declared_placeholder ) in self.object.get_declared_placeholders(): # to always get the correct order - placeholder = self.object.get_placeholders().get( + placeholder = self.object.get_placeholders(self.language).get( slot=declared_placeholder.slot ) name = self.get_section_name(placeholder) diff --git a/testapp/models.py b/testapp/models.py index 5df1087..dfb13c7 100644 --- a/testapp/models.py +++ b/testapp/models.py @@ -1,11 +1,30 @@ from django.db import models +from django.urls import NoReverseMatch, reverse + +from autoslug import AutoSlugField # Create your models here. class Blog(models.Model): title = models.CharField(max_length=100) content = models.TextField() + slug = AutoSlugField(populate_from="title", editable=True, blank=True) date_posted = models.DateTimeField(auto_now_add=True) def __str__(self): return self.title + + def get_absolute_url(self, *args, **kwargs): + try: + return reverse( + "blog:detail", + kwargs={ + "slug": self.slug, + }, + ) + except NoReverseMatch: + pass + return "" + + def get_title(self): + return self.title diff --git a/testapp/settings.py b/testapp/settings.py index 51781af..8cba2b7 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -20,6 +20,11 @@ "cms", "menus", "treebeard", + "filer", + "easy_thumbnails", + "djangocms_text_ckeditor", + "meta", + "djangocms_page_meta", "djangocms_export_page", "testapp", ] @@ -45,6 +50,8 @@ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "django.template.context_processors.i18n", + "sekizai.context_processors.sekizai", ], }, }, @@ -53,3 +60,24 @@ ROOT_URLCONF = "testapp.urls" SITE_ID = 1 + +LANGUAGE_CODE = "nl" +LANGUAGES = [ + ("nl", "Dutch"), + ("en", "English"), +] + +# (CMS) Page Meta settings +META_SITE_PROTOCOL = "https" +META_SITE_DOMAIN = "www.example.com" + +# CMS settings +CMS_CONFIRM_VERSION4 = True + +CMS_TEMPLATES = [("test.html", "Test page")] + +CMS_PLACEHOLDER_CONF = { + None: { + "plugins": ["TextPlugin"], + }, +} diff --git a/tests/templates/test.html b/testapp/templates/test.html similarity index 100% rename from tests/templates/test.html rename to testapp/templates/test.html diff --git a/testapp/urls.py b/testapp/urls.py index 083932c..bb2b8cf 100644 --- a/testapp/urls.py +++ b/testapp/urls.py @@ -1,6 +1,10 @@ +from django.conf.urls.i18n import i18n_patterns from django.contrib import admin -from django.urls import path +from django.urls import include, path, re_path urlpatterns = [ path("admin/", admin.site.urls), ] +urlpatterns += i18n_patterns( + re_path(r"^", include("cms.urls")), +) diff --git a/tests/test_models.py b/tests/test_models.py index 371790b..59c308e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,4 @@ -from django.test import RequestFactory, TestCase, override_settings +from django.test import RequestFactory, TestCase from djangocms_export_page.export.common import PageExport from djangocms_export_page.export.docx import DocxPageExport @@ -6,7 +6,6 @@ from .factories import BlogFactory -@override_settings(ROOT_URLCONF="annefrank.blog.tests.urls_tests") class ExportModelTests(TestCase): def setUp(self): self.object = BlogFactory() diff --git a/tests/test_pages.py b/tests/test_pages.py index ad8ad36..d1c5f7a 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -2,7 +2,7 @@ from django.test import RequestFactory, TestCase -from cms.api import add_plugin, create_page +from cms.api import add_plugin, create_page, create_page_content from meta.views import Meta from djangocms_export_page.export.common import Field, PageExport @@ -16,12 +16,14 @@ class ExportPageTests(TestCase): """ def setUp(self): - self.page = create_page("test", "test.html", "nl") - self.placeholder = self.page.placeholders.get(slot="test") + self.page = create_page("title nl", "test.html", "nl") self.language = "nl" + self.placeholder = self.page.get_placeholders(self.language).get( + slot="test", + ) self.request = RequestFactory().get("/nl/") - def test_expost_non_implemented(self): + def test_export_non_implemented(self): with self.assertRaises(NotImplementedError): PageExport(self.request, self.page, language=self.language).export() @@ -30,8 +32,18 @@ def test_base_url(self): self.assertEqual(export.base_url, "http://example.com") def test_page_url(self): + create_page_content( + "en", + "title en", + self.page, + ) + export = PageExport(self.request, self.page, language=self.language) - self.assertEqual(export.page_url, "http://example.com/nl/test/") + self.assertEqual(export.page_url, "http://example.com/nl/title-nl/") + + en_export = PageExport(self.request, self.page, language="en") + en_export = PageExport(self.request, self.page, language="en") + self.assertEqual(en_export.page_url, "http://example.com/en/title-en/") @patch("djangocms_export_page.export.common.get_page_meta") def test_meta_extra_custom_props(self, mock): @@ -50,14 +62,14 @@ def test_blank_page_export(self): self.assertEqual(type(export_file), bytes) def test_page_with_body_text(self): - add_plugin(self.placeholder, "BodyTextPlugin", "nl", body="Some text") + add_plugin(self.placeholder, "TextPlugin", "nl", body="Some text") export = DocxPageExport(self.request, self.page, language=self.language) self.assertEqual( export.get_data()[0].components[0].fields[0].value, "Some text" ) def test_page_with_control_char_in_text(self): - add_plugin(self.placeholder, "BodyTextPlugin", "nl", body="Some text \f") + add_plugin(self.placeholder, "TextPlugin", "nl", body="Some text \f") export = DocxPageExport(self.request, self.page, language=self.language) self.assertEqual( export.get_data()[0].components[0].fields[0].value, "Some text"