Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 13, 2025
1 parent 1df97cd commit 61fc07f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.timezone import now
from freezegun import freeze_time

from djangocms_versioning import constants
from djangocms_versioning.constants import DRAFT, PUBLISHED
from djangocms_versioning.datastructures import VersionableItem, default_copy
from djangocms_versioning.models import Version, VersionQuerySet
Expand Down Expand Up @@ -455,3 +456,39 @@ 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 61fc07f

Please sign in to comment.