Skip to content

Commit

Permalink
fix: test_cms_menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Yu committed Oct 29, 2024
1 parent ed2237a commit df7eeb2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
6 changes: 6 additions & 0 deletions djangocms_navigation/test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from djangocms_versioning.models import Version
from factory.fuzzy import FuzzyChoice, FuzzyInteger, FuzzyText

from ..compat import CMS_41
from ..models import Menu, MenuContent, MenuItem


Expand Down Expand Up @@ -125,9 +126,14 @@ class PageContentWithVersionFactory(PageContentFactory):
def version(self, create, extracted, **kwargs):
# NOTE: Use this method as below to define version attributes:
# PageContentWithVersionFactory(version__label='label1')

Check warning on line 129 in djangocms_navigation/test_utils/factories.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
if not create:
# Simple build, do nothing.
return

if not CMS_41 and 'locked_by' in kwargs:
kwargs.pop('locked_by')

PageVersionFactory(content=self, **kwargs)


Expand Down
39 changes: 31 additions & 8 deletions tests/test_cms_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,14 @@ def test_draft_menu_on_draft_page(self):
page=page,
language=self.language,
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=PUBLISHED,
)
pagecontent_draft = factories.PageContentWithVersionFactory(
page=page,
language=self.language,
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=DRAFT,
)
draft_child = factories.ChildMenuItemFactory(parent=menu_cont_draft.root, content=pagecontent_draft.page)
Expand Down Expand Up @@ -373,12 +375,14 @@ def test_draft_menu_on_published_page(self):
page=page,
language=self.language,
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=PUBLISHED,
)
pagecontent_draft = factories.PageContentWithVersionFactory(
page=page,
language=self.language,
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=DRAFT,
)

Expand All @@ -393,8 +397,7 @@ def test_draft_menu_on_published_page(self):

# Node added in draft menu version is not rendered in published view, only published menu nodes are rendered
with self.login_user_context(self.get_superuser()):
response = self.client.get(pagecontent_published.page.get_absolute_url())

response = self.client.get(pagecontent_draft.page.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertIn(published_child.title, str(response.content))
self.assertNotIn(draft_child.title, str(response.content))
Expand Down Expand Up @@ -451,13 +454,20 @@ def setUp(self):
self.language = "en"
# A page that will contain a menu i.e. we can see the menu rendered on this page
preview_pagecontent = factories.PageContentWithVersionFactory(
language=self.language,
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=DRAFT,
)
published_pagecontent = factories.PageContentWithVersionFactory(
language=self.language,
version__created_by=self.get_superuser(),
version__state=PUBLISHED,
)

self.edit_endpoint = get_object_edit_url(preview_pagecontent, language=self.language)
self.preview_endpoint = get_object_preview_url(preview_pagecontent, language=self.language)
self.live_endpoint = preview_pagecontent.get_absolute_url(language=self.language)
self.live_endpoint = published_pagecontent.get_absolute_url(language=self.language)
# Menu creation
self.menu = factories.MenuFactory()
self.published_menu_content = factories.MenuContentWithVersionFactory(
Expand Down Expand Up @@ -1678,14 +1688,21 @@ class MainNavigationIntegrationTestCase(CMSTestCase):
"""
def setUp(self):
# create a page and urls we can use to make a request with the test client
self.draft_pagecontent = factories.PageContentWithVersionFactory(
language="en",
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=DRAFT,
)

self.pagecontent = factories.PageContentWithVersionFactory(
language="en",
version__created_by=self.get_superuser(),
version__state=PUBLISHED,
)
self.live_url = self.pagecontent.get_absolute_url()
self.edit_url = get_object_edit_url(self.pagecontent, language="en")
self.preview_url = get_object_preview_url(self.pagecontent, language="en")
self.edit_url = get_object_edit_url(self.draft_pagecontent, language="en")
self.preview_url = get_object_preview_url(self.draft_pagecontent, language="en")
# create two menus, neither marked as the main navigation
self.first_menucontent = factories.MenuContentWithVersionFactory(
language="en",
Expand Down Expand Up @@ -1753,7 +1770,6 @@ def test_both_main_navigation(self):
edit_response = self.client.get(self.edit_url)
preview_response = self.client.get(self.preview_url)
live_response = self.client.get(self.live_url)

for response in [edit_response, preview_response, live_response]:
with self.subTest(response):
nav_tree = get_nav_from_response(response)
Expand Down Expand Up @@ -1791,6 +1807,13 @@ def test_both_main_navigation_multiple_sites(self):
version__state=PUBLISHED,
page__node__site=site_2,
)
site_2_draft_pagecontent = factories.PageContentWithVersionFactory(
language="en",
version__created_by=self.get_superuser(),
version__locked_by=self.get_superuser(),
version__state=DRAFT,
page__node__site=site_2,
)

# test for when the menu is marked main navigation, and when it isnt
for is_main_navigation in [False, True]:
Expand All @@ -1800,8 +1823,8 @@ def test_both_main_navigation_multiple_sites(self):
make_main_navigation(site_2_menucontent)

with self.login_user_context(self.get_superuser()):
edit_response = self.client.get(get_object_edit_url(site_2_pagecontent))
preview_response = self.client.get(get_object_preview_url(site_2_pagecontent))
edit_response = self.client.get(get_object_edit_url(site_2_draft_pagecontent))
preview_response = self.client.get(get_object_preview_url(site_2_draft_pagecontent))
live_response = self.client.get(site_2_pagecontent.get_absolute_url())

for response in [edit_response, preview_response, live_response]:
Expand Down

0 comments on commit df7eeb2

Please sign in to comment.