diff --git a/djangocms_navigation/compat.py b/djangocms_navigation/compat.py new file mode 100644 index 000000000..f2c5cad01 --- /dev/null +++ b/djangocms_navigation/compat.py @@ -0,0 +1,6 @@ +import django + +from packaging.version import Version + + +DJANGO_4_2 = Version(django.get_version()) >= Version('4.2') diff --git a/tests/__init__.py b/tests/__init__.py index d91484b01..e69de29bb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +0,0 @@ -import django - -from cms.test_utils.testcases import CMSTestCase - - -if django.VERSION < (4, 2): # TODO: remove when dropping support for Django < 4.2 - CMSTestCase.assertQuerySetEqual = CMSTestCase.assertQuerysetEqual diff --git a/tests/test_admin.py b/tests/test_admin.py index b5341df91..f0a64ef5f 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -4,7 +4,6 @@ import sys from unittest.mock import patch -import django from django.contrib import admin from django.contrib.contenttypes.models import ContentType from django.contrib.messages import get_messages @@ -29,14 +28,15 @@ MenuItemAdmin, MenuItemChangeList, ) +from djangocms_navigation.compat import DJANGO_4_2 from djangocms_navigation.models import Menu, MenuContent, MenuItem from djangocms_navigation.test_utils import factories from .utils import UsefulAssertsMixin, disable_versioning_for_navigation -version = list(map(int, django.__version__.split('.'))) -GTE_DJ21 = version[0] >= 2 and version[1] >= 1 +if not DJANGO_4_2: + CMSTestCase.assertQuerySetEqual = CMSTestCase.assertQuerysetEqual class MenuItemChangelistTestCase(CMSTestCase): @@ -53,6 +53,7 @@ def _get_changelist_instance(self, menu_content): request.user = self.get_superuser() model_admin = self.site._registry[MenuItem] admin_field = "title" + search_help_text = model_admin.search_help_text args = [ request, # request @@ -69,8 +70,8 @@ def _get_changelist_instance(self, menu_content): model_admin, # model_admin admin_field, # sortable_by ] - if not GTE_DJ21: - args.pop() + if DJANGO_4_2: + args.add(search_help_text) return MenuItemChangeList(*args) diff --git a/tests/test_forms.py b/tests/test_forms.py index fdc30993b..a86334fab 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -5,6 +5,7 @@ from cms.test_utils.testcases import CMSTestCase from cms.utils.urlutils import admin_reverse +from djangocms_navigation.compat import DJANGO_4_2 from djangocms_navigation.constants import SELECT2_CONTENT_OBJECT_URL_NAME from djangocms_navigation.forms import ( ContentTypeObjectSelectWidget, @@ -16,6 +17,10 @@ from djangocms_navigation.test_utils.polls.models import PollContent +if not DJANGO_4_2: + CMSTestCase.assertQuerySetEqual = CMSTestCase.assertQuerysetEqual + + class MenuContentFormTestCase(CMSTestCase): def setUp(self): self.menu_root = factories.RootMenuItemFactory() diff --git a/tests/urls.py b/tests/urls.py index 7cebe10b6..0c670d269 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,9 +1,8 @@ from django.conf import settings -from django.conf.urls import re_path from django.conf.urls.i18n import i18n_patterns from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns -from django.urls import include +from django.urls import include, re_path from django.views.static import serve