diff --git a/tests/test_models.py b/tests/test_models.py index 8485d9ec..1bf68a51 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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 @@ -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)