Skip to content

Commit

Permalink
test: add regression test for https://github.com/django-cms/django-cm…
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 13, 2025
1 parent c9cf8a2 commit 793cd21
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
52 changes: 52 additions & 0 deletions tests/test_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from cms.test_utils.testcases import CMSTestCase

from djangocms_versioning import constants
from djangocms_versioning.test_utils import factories
from djangocms_versioning.test_utils.polls.models import PollContent


class TestLatestContentCurrentContent(CMSTestCase):
def setUp(self):
poll1 = factories.PollFactory()
factories.PollVersionFactory(state=constants.PUBLISHED, content__language="de")

factories.PollVersionFactory(state=constants.ARCHIVED, content__poll=poll1, content__language="de")
v1 = factories.PollVersionFactory(state=constants.UNPUBLISHED, content__poll=poll1, content__language="de")
v2 = factories.PollVersionFactory(state=constants.ARCHIVED, content__poll=poll1, content__language="en")
v3 = factories.PollVersionFactory(state=constants.DRAFT, content__poll=poll1, content__language="en")
v4 = factories.PollVersionFactory(state=constants.UNPUBLISHED, content__poll=poll1, content__language="fr")

self.poll = poll1
self.poll_content1 = v1.content
self.poll_content2 = v2.content
self.poll_content3 = v3.content
self.poll_content4 = v4.content

def test_latest_content(self):
"""only one version per grouper and grouping field (language) returned."""
latest_content = PollContent.admin_manager.latest_content(poll=self.poll)
self.assertEqual(latest_content.count(), 3)
self.assertIn(self.poll_content1, latest_content)
self.assertIn(self.poll_content3, latest_content)
self.assertIn(self.poll_content4, latest_content)

def test_latest_content_by_language(self):
"""only one version per grouper and grouping field (language) returned. Additional
filter before or after latest_content() should **not** affect the result."""

latest_content = PollContent.admin_manager.latest_content().filter(poll=self.poll, language="en")
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content3, latest_content)

latest_content = PollContent.admin_manager.filter(poll=self.poll, language="en").latest_content()
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content3, latest_content)

latest_content = PollContent.admin_manager.latest_content().filter(poll=self.poll, language="de")
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content1, latest_content)

latest_content = PollContent.admin_manager.filter(poll=self.poll, language="de").latest_content()
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content1, latest_content)

36 changes: 0 additions & 36 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,39 +456,3 @@ def test_content_object_gets_duplicated_with_source(self):
new_version = original_version.copy(user)

self.assertEqual(original_version, new_version.source)


class TestLatestContent(CMSTestCase):
def setUp(self):
poll1 = factories.PollFactory()

# v0 = factories.PollVersionFactory(state=constants.ARCHIVED, content__poll=poll1, content__language="de")
v1 = factories.PollVersionFactory(state=constants.UNPUBLISHED, content__poll=poll1, content__language="de")
v2 = factories.PollVersionFactory(state=constants.ARCHIVED, content__poll=poll1, content__language="en")
v3 = factories.PollVersionFactory(state=constants.DRAFT, content__poll=poll1, content__language="en")
self.poll_content1 = v1.content
self.poll_content2 = v2.content
self.poll_content3 = v3.content

def test_latest_content(self):
latest_content = PollContent.admin_manager.latest_content()
self.assertEqual(latest_content.count(), 2)
self.assertIn(self.poll_content1, latest_content)
self.assertIn(self.poll_content3, latest_content)

def test_latest_content_by_language(self):
latest_content = PollContent.admin_manager.latest_content().filter(language="en")
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content3, latest_content)

latest_content = PollContent.admin_manager.filter(language="en").latest_content()
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content3, latest_content)

latest_content = PollContent.admin_manager.latest_content().filter(language="de")
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content1, latest_content)

latest_content = PollContent.admin_manager.filter(language="de").latest_content()
self.assertEqual(latest_content.count(), 1)
self.assertIn(self.poll_content1, latest_content)

0 comments on commit 793cd21

Please sign in to comment.