Skip to content

Commit

Permalink
Add tests that locked versions do not get included in collections
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Mar 15, 2024
1 parent 88a68dd commit 21e755a
Showing 1 changed file with 86 additions and 6 deletions.
92 changes: 86 additions & 6 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@


try:
from djangocms_versioning.helpers import remove_version_lock
from djangocms_versioning.helpers import remove_version_lock, version_is_locked
except ImportError:
try:
from djangocms_version_locking.helpers import remove_version_lock
except ImportError:
def remove_version_lock(version):
pass
from djangocms_version_locking.helpers import remove_version_lock, version_is_locked


class CollectionItemsViewAddingRequestsTestCase(CMSTestCase):
Expand Down Expand Up @@ -626,6 +622,90 @@ def test_collection_with_redirect_url_query_redirect_sanitisation(self):
)


class ModerationCollectionTestCase(CMSTestCase):
def setUp(self):
self.language = "en"
self.user_1 = self.get_superuser()
self.user_2 = UserFactory()
self.collection = ModerationCollectionFactory(author=self.user_1)
self.page_version = PageVersionFactory(created_by=self.user_1)
self.placeholder = PlaceholderFactory(source=self.page_version.content)
self.poll_version = PollVersionFactory(created_by=self.user_2, content__language=self.language)

def test_add_version_with_locked_plugins(self):
"""
Locked plugins should not be allowed to be added to a collection
"""
PollPluginFactory(placeholder=self.placeholder, poll=self.poll_version.content.poll)

admin_endpoint = get_admin_url(
name="cms_moderation_items_to_collection", language="en", args=()
)

url = add_url_parameters(
admin_endpoint,
return_to_url="http://example.com",
version_ids=self.page_version.pk,
collection_id=self.collection.pk,
)

# Poll should be locked by default
poll_is_locked = version_is_locked(self.poll_version)
self.assertTrue(poll_is_locked)

with self.login_user_context(self.user_1):
self.client.post(
path=url,
data={"collection": self.collection.pk, "versions": [self.page_version.pk, self.poll_version.pk]},
follow=False,
)

# Get all moderation request objects for the collection
moderation_requests = ModerationRequest.objects.filter(collection=self.collection)

self.assertEqual(moderation_requests.count(), 1)
self.assertTrue(moderation_requests.filter(version=self.page_version).exists())
self.assertFalse(moderation_requests.filter(version=self.poll_version).exists())

def test_add_version_with_unlocked_child(self):
"""
Only plugins that are unlocked should be added to collection
"""

PollPluginFactory(placeholder=self.placeholder, poll=self.poll_version.content.poll)

admin_endpoint = get_admin_url(
name="cms_moderation_items_to_collection", language="en", args=()
)

url = add_url_parameters(
admin_endpoint,
return_to_url="http://example.com",
version_ids=self.page_version.pk,
collection_id=self.collection.pk,
)

# Poll should be locked by default
poll_is_locked = version_is_locked(self.poll_version)
self.assertTrue(poll_is_locked)

# Unlock the poll version
remove_version_lock(self.poll_version)

with self.login_user_context(self.user_1):
self.client.post(
path=url,
data={"collection": self.collection.pk, "versions": [self.page_version.pk, self.poll_version.pk]},
follow=False,
)

# Get all moderation request objects for the collection
moderation_requests = ModerationRequest.objects.filter(collection=self.collection)
self.assertEqual(moderation_requests.count(), 2)
self.assertTrue(moderation_requests.filter(version=self.page_version).exists())
self.assertTrue(moderation_requests.filter(version=self.poll_version).exists())


class CollectionItemsViewTest(CMSTestCase):
def setUp(self):
self.client.force_login(self.get_superuser())
Expand Down

0 comments on commit 21e755a

Please sign in to comment.