Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jul 15, 2024
1 parent 7f239f5 commit 53af09b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
11 changes: 2 additions & 9 deletions djangocms_versioning/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_content_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand 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
Expand All @@ -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)

0 comments on commit 53af09b

Please sign in to comment.