From 53af09b3a1605227404c25d4e27298a1ffbec66a Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Mon, 15 Jul 2024 08:25:27 +0200 Subject: [PATCH] Update tests --- djangocms_versioning/managers.py | 11 ++--------- tests/test_content_models.py | 10 +++++----- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/djangocms_versioning/managers.py b/djangocms_versioning/managers.py index 1b043c2f..5d323b76 100644 --- a/djangocms_versioning/managers.py +++ b/djangocms_versioning/managers.py @@ -60,20 +60,13 @@ def _chain(self): clone._group_by_key = self._group_by_key return clone - def current_content_iterator(self, **kwargs): - """Returns generator (not a queryset) over current content versions. Current versions are either draft - versions or published versions (in that order)""" - warnings.warn("current_content_iterator is deprecated in favour of current_conent", - DeprecationWarning, stacklevel=2) - return iter(self.current_content(**kwargs)) - def current_content(self, **kwargs): """Returns a queryset current content versions. Current versions are either draft versions or published versions (in that order). This optimized query assumes that draft versions always have a higher pk than any other version type. This is true as long as no other version type can be converted to draft without creating a new version.""" - qs = self.filter(versions__state__in=(constants.DRAFT, constants.PUBLISHED)) - pk_filter = qs.values(*self._group_by_key)\ + pk_filter = self.filter(versions__state__in=(constants.DRAFT, constants.PUBLISHED))\ + .values(*self._group_by_key)\ .annotate(vers_pk=models.Max("versions__pk"))\ .values("vers_pk") return self.filter(versions__pk__in=pk_filter, **kwargs) diff --git a/tests/test_content_models.py b/tests/test_content_models.py index 0a4d07a1..4117446c 100644 --- a/tests/test_content_models.py +++ b/tests/test_content_models.py @@ -68,7 +68,7 @@ def setUp(self) -> None: self.create_page_content(page, "it", constants.ARCHIVED) self.create_page_content(page, "it", constants.PUBLISHED) - def test_current_content_iterator(self): + def test_current_content(self): # 12 PageContent versions in total self.assertEqual(len(list( PageContent.admin_manager.all() @@ -79,11 +79,11 @@ def test_current_content_iterator(self): self.assertEqual(len(qs), 4) self.assertEqual(qs._group_by_key, ["page", "language"]) self.assertEqual(len(list( - PageContent.admin_manager.filter(page__in=self.pages1).current_content_iterator() - )), 4, f"{list(PageContent.admin_manager.filter(page__in=self.pages1).current_content_iterator())}") + PageContent.admin_manager.filter(page__in=self.pages1).current_content() + )), 4, f"{list(PageContent.admin_manager.filter(page__in=self.pages1).current_content())}") # 2 current PageContent versions for self.pages2 self.assertEqual(len(list( - PageContent.admin_manager.filter(page__in=self.pages2).current_content_iterator() + PageContent.admin_manager.filter(page__in=self.pages2).current_content() )), 4) # Now unpublish all published in pages2 @@ -93,5 +93,5 @@ def test_current_content_iterator(self): # 2 current PageContent versions for self.pages2 self.assertEqual(len(list( - PageContent.admin_manager.filter(page__in=self.pages2).current_content_iterator() + PageContent.admin_manager.filter(page__in=self.pages2).current_content() )), 2)