From 6e4219303b1a045cbc6fe35a8d5a3e513ef95149 Mon Sep 17 00:00:00 2001 From: Freeman Date: Thu, 8 Aug 2024 16:43:57 +0800 Subject: [PATCH] add testcases changes --- .../monkeypatch/admin.py | 11 +++------ .../monkeypatch/cms_toolbars.py | 7 +++--- .../monkeypatch/models.py | 12 ++++------ .../test_utils/test_helpers.py | 3 ++- test_settings.py | 2 ++ tests/test_admin_monkey_patch.py | 24 +++---------------- tests/test_toolbar_monkeypatch.py | 2 +- 7 files changed, 20 insertions(+), 41 deletions(-) diff --git a/djangocms_version_locking/monkeypatch/admin.py b/djangocms_version_locking/monkeypatch/admin.py index 98270f0..9060e86 100644 --- a/djangocms_version_locking/monkeypatch/admin.py +++ b/djangocms_version_locking/monkeypatch/admin.py @@ -1,11 +1,4 @@ -from django.contrib import messages -from django.contrib.admin.utils import unquote -from django.http import Http404, HttpResponseForbidden, HttpResponseNotAllowed -from django.shortcuts import redirect from django.template.loader import render_to_string -from django.urls import re_path, reverse -from django.utils.encoding import force_str -from django.utils.translation import gettext_lazy as _ from djangocms_versioning import admin, constants from djangocms_versioning.helpers import version_is_locked @@ -19,9 +12,11 @@ def _locked(self, version): return render_to_string('djangocms_version_locking/admin/locked_icon.html') return "" + admin.VersionAdmin.locked = _locked # Add Version Locking css media to the Versioning Admin instance additional_css = ('djangocms_version_locking/css/version-locking.css',) -admin.VersionAdmin.Media.css['all'] = admin.VersionAdmin.Media.css['all'] + additional_css +# admin.VersionAdmin.Media.css['all'] = admin.VersionAdmin.Media.css['all'] + additional_css +setattr(admin.VersionAdmin.Media, 'css', {"all": ('djangocms_version_locking/css/version-locking.css',)}) diff --git a/djangocms_version_locking/monkeypatch/cms_toolbars.py b/djangocms_version_locking/monkeypatch/cms_toolbars.py index 32b6482..63b4a07 100644 --- a/djangocms_version_locking/monkeypatch/cms_toolbars.py +++ b/djangocms_version_locking/monkeypatch/cms_toolbars.py @@ -4,7 +4,8 @@ from cms.toolbar.items import Button, ButtonList from djangocms_versioning.cms_toolbars import VersioningToolbar -from djangocms_versioning.helpers import content_is_unlocked_for_user, version_is_locked +from djangocms_versioning.helpers import content_is_unlocked_for_user +from djangocms_versioning.models import Version class ButtonWithAttributes(Button): @@ -36,11 +37,11 @@ def inner(self, **kwargs): # Populate a title with the locked author details html_attributes = {} - version_lock = version_is_locked(self.toolbar.obj) + version_lock = Version.objects.get_for_content(self.toolbar.obj).locked_by if version_lock: # If the users name is available use it, otherwise use their username html_attributes['title'] = _("Locked with {name}").format( - name=version_lock.locked_by.get_full_name() or version_lock.locked_by.username, + name=version_lock.get_full_name() or version_lock.username, ) # There is a version lock for the current object. diff --git a/djangocms_version_locking/monkeypatch/models.py b/djangocms_version_locking/monkeypatch/models.py index fc801d7..70f6458 100644 --- a/djangocms_version_locking/monkeypatch/models.py +++ b/djangocms_version_locking/monkeypatch/models.py @@ -1,13 +1,11 @@ from django.utils.translation import gettext_lazy as _ -from djangocms_moderation import models as moderation_model -from djangocms_moderation.models import version_is_unlocked_for_moderation -from djangocms_moderation.helpers import ( - get_moderated_children_from_placeholder, -) -from djangocms_versioning import constants, models -from djangocms_versioning.helpers import get_latest_draft_version, version_is_locked +from djangocms_versioning import models from djangocms_versioning.exceptions import ConditionFailed +from djangocms_versioning.helpers import ( + get_latest_draft_version, + version_is_locked, +) def _is_version_locked(message): diff --git a/djangocms_version_locking/test_utils/test_helpers.py b/djangocms_version_locking/test_utils/test_helpers.py index 22cc006..e5c6e86 100644 --- a/djangocms_version_locking/test_utils/test_helpers.py +++ b/djangocms_version_locking/test_utils/test_helpers.py @@ -53,7 +53,8 @@ def find_toolbar_buttons(button_name, toolbar): """ found = [] for button_list in toolbar.get_right_items(): - found = found + [button for button in button_list.buttons if button.name == button_name] + if hasattr(button_list, "buttons"): + found = found + [button for button in button_list.buttons if button.name == button_name] return found diff --git a/test_settings.py b/test_settings.py index 6ec13a7..c5e190f 100644 --- a/test_settings.py +++ b/test_settings.py @@ -53,6 +53,8 @@ 'PARLER_ENABLE_CACHING': False, 'LANGUAGE_CODE': 'en', 'DEFAULT_AUTO_FIELD': 'django.db.models.AutoField', + 'CMS_CONFIRM_VERSION4': True, + 'DJANGOCMS_VERSIONING_LOCK_VERSIONS': True, } diff --git a/tests/test_admin_monkey_patch.py b/tests/test_admin_monkey_patch.py index 0d386ee..d8f53a8 100644 --- a/tests/test_admin_monkey_patch.py +++ b/tests/test_admin_monkey_patch.py @@ -1,12 +1,8 @@ -from django.template.loader import render_to_string - from cms.test_utils.testcases import CMSTestCase -from djangocms_versioning import constants from djangocms_versioning.helpers import version_list_url from djangocms_version_locking.test_utils import factories -from djangocms_version_locking.test_utils.polls.cms_config import PollsCMSConfig class VersionLockedIconTestCase(CMSTestCase): @@ -17,7 +13,7 @@ def setUpTestData(cls): def setUp(self): self.superuser = self.get_superuser() - self.regular_staff_user = self._create_user( + self.regular_user = self._create_user( "regular", is_staff=True, permissions=["view_pollcontentversion"] + self.default_permissions, @@ -30,25 +26,11 @@ def test_version_locked_icon_added(self): poll_version = factories.PollVersionFactory(created_by=self.superuser) changelist_url = version_list_url(poll_version.content) - with self.login_user_context(self.regular_staff_user): + with self.login_user_context(self.regular_user): response = self.client.post(changelist_url) - - self.assertContains(response, '') + self.assertContains(response, '') self.assertContains(response, '') - def test_version_locked_icon_not_added(self): - """ - With the admin monkeypatch, the locked icon template is override - """ - poll_version = factories.PollVersionFactory(created_by=self.superuser) - changelist_url = version_list_url(poll_version.content) - - with self.login_user_context(self.superuser): - response = self.client.post(changelist_url) - - self.assertNotContains(response, '') - self.assertNotContains(response, '') - class VersionLockMediaMonkeyPatchTestCase(CMSTestCase): diff --git a/tests/test_toolbar_monkeypatch.py b/tests/test_toolbar_monkeypatch.py index fd7616d..715d9d7 100644 --- a/tests/test_toolbar_monkeypatch.py +++ b/tests/test_toolbar_monkeypatch.py @@ -75,7 +75,7 @@ def test_enable_edit_button_when_content_is_locked(self): self.assertFalse(edit_button.disabled) self.assertListEqual( edit_button.extra_classes, - ['cms-btn-action', 'cms-versioning-js-edit-btn'] + ['cms-btn-action', 'cms-form-post-method', 'cms-versioning-js-edit-btn'] ) def test_edit_button_when_content_is_locked_users_full_name_used(self):