Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vipulnarang95 committed Mar 13, 2024
1 parent 8d56c6d commit 571df7e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
6 changes: 6 additions & 0 deletions djangocms_navigation/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import django

from packaging.version import Version


DJANGO_4_2 = Version(django.get_version()) >= Version('4.2')
7 changes: 0 additions & 7 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down

0 comments on commit 571df7e

Please sign in to comment.