Skip to content

Commit

Permalink
add testcases changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Freeman authored and Freeman committed Aug 8, 2024
1 parent 25c946b commit 6e42193
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 41 deletions.
11 changes: 3 additions & 8 deletions djangocms_version_locking/monkeypatch/admin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',)})
7 changes: 4 additions & 3 deletions djangocms_version_locking/monkeypatch/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 5 additions & 7 deletions djangocms_version_locking/monkeypatch/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 2 additions & 1 deletion djangocms_version_locking/test_utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
24 changes: 3 additions & 21 deletions tests/test_admin_monkey_patch.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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,
Expand All @@ -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, '<a class="cms-version-locked-status-icon" title="Locked">')
self.assertContains(response, '<span class="cms-version-locked-status-icon" title="Locked">')
self.assertContains(response, '<img src="/static/djangocms_version_locking/svg/lock.svg">')

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, '<a class="cms-version-locked-status-icon" title="Locked">')
self.assertNotContains(response, '<img src="/static/djangocms_version_locking/svg/lock.svg">')


class VersionLockMediaMonkeyPatchTestCase(CMSTestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/test_toolbar_monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6e42193

Please sign in to comment.