Skip to content

Commit

Permalink
Fix test for django CMS 4.0 toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Mar 12, 2024
1 parent 52eb8d5 commit 1685a78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions tests/test_cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ def test_add_edit_button_with_version_lock(self):
toolbar.post_template_populate()

if versioning_version < "2":
self.assertTrue(self._button_exists("Edit", toolbar.toolbar))
self.assertTrue(
self._button_exists(lambda button: button.name.endswith("Edit"), toolbar.toolbar)
)
# Edit button should not be clickable
button = self._find_buttons("Edit", toolbar.toolbar)
button = self._find_buttons(lambda button: button.name.endswith("Edit"), toolbar.toolbar)
self.assertTrue(button[0].disabled)
else:
self.assertFalse(
Expand Down
18 changes: 13 additions & 5 deletions tests/test_monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cms.models import PageContent
from cms.models.fields import PlaceholderRelationField

from djangocms_versioning import __version__ as versioning_version
from djangocms_versioning import versionables
from djangocms_versioning.admin import VersionAdmin
from djangocms_versioning.constants import DRAFT, PUBLISHED
Expand Down Expand Up @@ -42,8 +43,12 @@ def test_get_edit_link(self, mock_is_obj_review_locked):
)
# We test that moderation check is called when getting an edit link
self.assertTrue(mock_is_obj_review_locked.called)
# Edit link is removed as `mock_is_obj_review_locked` is True
self.assertEqual("", edit_link)
if versioning_version < "2":
# Edit link is inactive as `mock_is_obj_review_locked` is True
self.assertIn("inactive", edit_link)
else:
# Edit link is removed as `mock_is_obj_review_locked` is True
self.assertEqual("", edit_link)
# self.assertIn("inactive", edit_link)

@mock.patch("djangocms_moderation.monkeypatch.is_registered_for_moderation")
Expand Down Expand Up @@ -79,7 +84,6 @@ def test_get_archive_link(self, _mock):
args=(version.pk,),
)
_mock.return_value = True
from djangocms_versioning import __version__ as versioning_version
if versioning_version != "2.0.0":
archive_link = self.version_admin._get_archive_link(version, self.mock_request)
else:
Expand All @@ -89,8 +93,12 @@ def test_get_archive_link(self, _mock):
archive_link = ""
# We test that moderation check is called when getting an edit link
self.assertEqual(1, _mock.call_count)
# Edit link is unavailable
self.assertEqual("", archive_link)
if versioning_version < "2":
# Edit link is inactive as `mock_is_obj_review_locked` is True
self.assertIn("inactive", archive_link)
else:
# Edit link is unavailable
self.assertEqual("", archive_link)

_mock.return_value = None
archive_link = self.version_admin._get_archive_link(version, self.mock_request)
Expand Down

0 comments on commit 1685a78

Please sign in to comment.