Skip to content

Commit

Permalink
Release/2.2.0 (#265)
Browse files Browse the repository at this point in the history
* bump version to 2.2.0

* bump version to 2.2.0 changelog update

* fix testcases issue for djangocms-versioning 2.0.0

* remove testcase logic for versioning 2.0.0, as its not suggest to use

* update release date.

* fix pre-commit errors

* eclude json files for pre-commit code spell check

* fix pre-commit errors, add json files
  • Loading branch information
FreemanPancake authored May 16, 2024
1 parent 1ac64ec commit 1244819
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ repos:
- id: codespell
exclude: >
(?x)^(
.*\.(js|po)
.*\.(js|po|json)
)$
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
Changelog
=========

Unreleased
2.2.0 (2024-05-16)
==========

* Python 3.8, 3.9 support removed
* Python 3.10, 3.11 and 3.12 support added
* Django 2.2 support removed
* Django 4.2 support added
* fix: Treebeard support improved by inheriting a treebeard template

2.1.6 (2022-09-07)
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.6"
__version__ = "2.2.0"
9 changes: 9 additions & 0 deletions djangocms_moderation/compact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import get_version

from packaging.version import Version


DJANGO_VERSION = get_version()


DJANGO_4_1 = Version(DJANGO_VERSION) < Version('4.2')
2 changes: 1 addition & 1 deletion tests/requirements/dj42_cms40.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ django_polymorphic

https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
https://github.com/django-cms/djangocms-versioning/tarball/support/django-cms-4.0.x#egg=djangocms-versioning
https://github.com/joshyu/djangocms-version-locking/tarball/feat/django-42-compatible#egg=djangocms-version-locking
https://github.com/FidelityInternational/djangocms-version-locking/tarball/master#egg=djangocms-version-locking
https://github.com/django-cms/djangocms-alias/tarball/support/django-cms-4.0.x#egg=djangocms-alias
2 changes: 1 addition & 1 deletion tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Django>=4.2,<5.0
django-cms>=4.1,<4.2

djangocms-versioning>=2.0.0
djangocms-versioning>=2.0.1
djangocms-alias>=2.0.0
2 changes: 1 addition & 1 deletion tests/requirements/dj50_cms41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Django>=5.0,<5.1
django-cms>=4.1,<4.2

djangocms-versioning>=2.0.0
djangocms-versioning>=2.0.1
djangocms-alias>=2.0.0
18 changes: 9 additions & 9 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
)
from djangocms_moderation.models import ModerationCollection, ModerationRequest

from .utils.base import BaseTestCase
from .utils.base import AssertQueryMixin, BaseTestCase


class UpdateModerationRequestFormTest(BaseTestCase):
class UpdateModerationRequestFormTest(AssertQueryMixin, BaseTestCase):
def test_form_init_approved_action(self):
form = UpdateModerationRequestForm(
action=constants.ACTION_APPROVED,
Expand All @@ -31,7 +31,7 @@ def test_form_init_approved_action(self):
)
field_moderator = form.fields["moderator"]
self.assertEqual(field_moderator.empty_label, "Any Role 2")
self.assertQuerysetEqual(
self.assertQuerySetEqual(
field_moderator.queryset,
User.objects.filter(pk__in=[self.user2.pk]),
transform=lambda x: x,
Expand All @@ -48,7 +48,7 @@ def test_form_init_cancelled_action(self):
active_request=self.moderation_request1,
)
field_moderator = form.fields["moderator"]
self.assertQuerysetEqual(field_moderator.queryset, User.objects.none())
self.assertQuerySetEqual(field_moderator.queryset, User.objects.none())
self.assertIsInstance(field_moderator.widget, HiddenInput)

def test_form_init_rejected_action(self):
Expand All @@ -61,7 +61,7 @@ def test_form_init_rejected_action(self):
active_request=self.moderation_request1,
)
field_moderator = form.fields["moderator"]
self.assertQuerysetEqual(field_moderator.queryset, User.objects.none())
self.assertQuerySetEqual(field_moderator.queryset, User.objects.none())
self.assertIsInstance(field_moderator.widget, HiddenInput)

def test_form_save(self):
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_action_user_can_change_own_comment(self):
self.assertTrue(form.is_valid())


class CollectionItemsFormTestCase(BaseTestCase):
class CollectionItemsFormTestCase(AssertQueryMixin, BaseTestCase):
def test_add_items_to_collection(self):
pg1_version = PageVersionFactory(created_by=self.user)
pg2_version = PageVersionFactory(created_by=self.user)
Expand All @@ -155,7 +155,7 @@ def test_add_items_to_collection(self):
form = CollectionItemsForm(data=data, user=self.user)
self.assertTrue(form.is_valid())
versions = form.clean_versions()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
versions,
Version.objects.filter(pk__in=[pg1_version.pk, pg2_version.pk]),
transform=lambda x: x,
Expand All @@ -172,7 +172,7 @@ def test_attempt_add_with_item_already_in_collection(self):
form = CollectionItemsForm(data=data, user=self.user)
self.assertTrue(form.is_valid())
versions = form.clean_versions()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
versions,
Version.objects.filter(pk__in=[pg_version.pk]),
transform=lambda x: x,
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_collection_choice_should_be_limited_to_current_user_and_collecting_stat
if not form.is_valid():
self.assertIn("collection", form.errors)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
form.fields["collection"].queryset,
ModerationCollection.objects.filter(
pk__in=[collection1.pk, collection2.pk]
Expand Down
30 changes: 15 additions & 15 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
)

from .utils import factories
from .utils.base import BaseTestCase
from .utils.base import AssertQueryMixin, BaseTestCase


class RoleTest(BaseTestCase):
class RoleTest(AssertQueryMixin, BaseTestCase):
def test_user_and_group_validation_error(self):
role = Role.objects.create(name="New Role 1", user=self.user, group=self.group)
self.assertRaisesMessage(
Expand All @@ -43,15 +43,15 @@ def test_user_is_assigned(self):
def test_get_users_queryset(self):
# with user
role = Role.objects.create(name="New Role 1", user=self.user)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
role.get_users_queryset(),
User.objects.filter(pk=self.user.pk),
transform=lambda x: x,
ordered=False,
)
# with group
role = Role.objects.create(name="New Role 2", group=self.group)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
role.get_users_queryset(),
User.objects.filter(pk__in=[self.user2.pk, self.user3.pk]),
transform=lambda x: x,
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_get_next_required(self):
self.assertIsNone(self.wf1st3.get_next_required())


class ModerationRequestTest(BaseTestCase):
class ModerationRequestTest(AssertQueryMixin, BaseTestCase):
def test_has_pending_step(self):
self.assertTrue(self.moderation_request1.has_pending_step())
self.assertFalse(self.moderation_request2.has_pending_step())
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_get_last_action(self):
)

def test_get_pending_steps(self):
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.moderation_request3.get_pending_steps(),
WorkflowStep.objects.filter(pk__in=[self.wf3st2.pk]),
transform=lambda x: x,
Expand All @@ -142,29 +142,29 @@ def test_get_pending_steps(self):

# ... so all the steps are now pending as we need to re-moderate the
# resubmitted request
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.moderation_request3.get_pending_steps(),
WorkflowStep.objects.filter(workflow=self.wf3),
transform=lambda x: x,
ordered=False,
)

def test_get_pending_required_steps(self):
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.moderation_request1.get_pending_required_steps(),
WorkflowStep.objects.filter(pk__in=[self.wf1st1.pk, self.wf1st3.pk]),
transform=lambda x: x,
ordered=False,
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.moderation_request3.get_pending_required_steps(),
WorkflowStep.objects.none(),
transform=lambda x: x,
ordered=False,
)

# Lets test with archived action
self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.moderation_request2.get_pending_required_steps(),
WorkflowStep.objects.none(),
transform=lambda x: x,
Expand All @@ -176,7 +176,7 @@ def test_get_pending_required_steps(self):
last_action.is_archived = True
last_action.save()

self.assertQuerysetEqual(
self.assertQuerySetEqual(
self.moderation_request2.get_pending_required_steps(),
WorkflowStep.objects.filter(pk=last_action.step_approved.pk),
transform=lambda x: x,
Expand Down Expand Up @@ -663,7 +663,7 @@ def test_cancel(self):
self.assertEqual(actions[0].moderation_request, active_request)


class AddVersionTestCase(TestCase):
class AddVersionTestCase(AssertQueryMixin, TestCase):

def setUp(self):
self.collection = factories.ModerationCollectionFactory()
Expand Down Expand Up @@ -717,13 +717,13 @@ def test_add_version_duplicate_with_same_parent(self):
moderation_request, added_items = self.collection.add_version(version, parent)

self.assertEqual(ModerationRequest.objects.all().count(), 2)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
ModerationRequest.objects.all(),
[parent.moderation_request.pk, child.moderation_request.pk],
transform=lambda o: o.pk
)
self.assertEqual(ModerationRequestTreeNode.objects.all().count(), 2)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
ModerationRequestTreeNode.objects.all(),
[parent.pk, child.pk],
transform=lambda o: o.pk
Expand All @@ -746,7 +746,7 @@ def test_add_version_duplicate_with_different_parent(self):
moderation_request, added_items = self.collection.add_version(version, parent)

self.assertEqual(ModerationRequest.objects.all().count(), 3)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
ModerationRequest.objects.all(),
[root.moderation_request.pk, child.moderation_request.pk, parent.moderation_request.pk],
transform=lambda o: o.pk
Expand Down
16 changes: 4 additions & 12 deletions tests/test_monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ 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)
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
if versioning_version >= "2.0.2":
self.assertEqual("", edit_link)
# self.assertIn("inactive", edit_link)
else:
self.assertIn("inactive", edit_link)

@mock.patch("djangocms_moderation.monkeypatch.is_registered_for_moderation")
@mock.patch("djangocms_moderation.monkeypatch.is_obj_review_locked")
Expand Down Expand Up @@ -92,12 +89,7 @@ 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)
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)
self.assertIn("inactive", archive_link)

_mock.return_value = None
archive_link = self.version_admin._get_archive_link(version, self.mock_request)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from djangocms_moderation.utils import get_admin_url

from .utils.base import BaseViewTestCase
from .utils.base import AssertQueryMixin, BaseViewTestCase
from .utils.factories import (
ChildModerationRequestTreeNodeFactory,
ModerationCollectionFactory,
Expand Down Expand Up @@ -706,7 +706,7 @@ def test_add_version_with_unlocked_child(self):
self.assertTrue(moderation_requests.filter(version=self.poll_version).exists())


class CollectionItemsViewTest(CMSTestCase):
class CollectionItemsViewTest(AssertQueryMixin, CMSTestCase):
def setUp(self):
self.client.force_login(self.get_superuser())
self.url = get_admin_url(
Expand Down Expand Up @@ -746,7 +746,7 @@ def test_initial_form_values_when_collection_id_passed(self):
self.assertEqual(
response.context["form"].initial["collection"], str(collection.pk)
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
response.context["form"].initial["versions"],
[pg_version.pk, poll_version.pk],
transform=lambda o: o.pk,
Expand All @@ -762,7 +762,7 @@ def test_initial_form_values_when_collection_id_not_passed(self):

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["form"].initial.keys()), 1)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
response.context["form"].initial["versions"],
[pg_version.pk, poll_version.pk],
transform=lambda o: o.pk,
Expand Down
1 change: 0 additions & 1 deletion tests/utils/app_1/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "tests.utils.app_1.apps.App1Config"
1 change: 0 additions & 1 deletion tests/utils/app_2/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "tests.utils.app_2.apps.App2Config"
11 changes: 11 additions & 0 deletions tests/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from djangocms_versioning.test_utils.factories import PageVersionFactory

from djangocms_moderation import constants
from djangocms_moderation.compact import DJANGO_4_1
from djangocms_moderation.models import (
ModerationCollection,
ModerationRequest,
Expand All @@ -18,6 +19,16 @@ class MockRequest:
GET = {}


class AssertQueryMixin:
"""Mixin to append uppercase `assertQuerySetEqual` for TestCase class
if django version below 4.2
"""

if DJANGO_4_1:
def assertQuerySetEqual(self, *args, **kwargs):
return self.assertQuerysetEqual(*args, **kwargs)


class BaseTestCase(CMSTestCase):
@classmethod
def setUpTestData(cls):
Expand Down
1 change: 0 additions & 1 deletion tests/utils/moderated_polls/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "tests.utils.moderated_polls.apps.PollsConfig"
3 changes: 0 additions & 3 deletions tests/utils/versioned_none_moderated_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
default_app_config = (
"tests.utils.versioned_none_moderated_app.apps.VersionedNoneModeratedAppConfig"
)

0 comments on commit 1244819

Please sign in to comment.