Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Yu committed Oct 29, 2024
1 parent 18f1099 commit 376b457
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
40 changes: 22 additions & 18 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def test_raise_error_when_return_unregistered_user_model_in_select2_view(self):
def test_select2_view_text_page_repr(self):
"""Result should contain model repr text"""
page_contenttype_id = ContentType.objects.get_for_model(Page).id
PageContentFactory(
title="test", menu_title="test", page_title="test", language="en"
PageContentWithVersionFactory(
title="test", menu_title="test", page_title="test", language="en", version__state=PUBLISHED
) # flake8: noqa
PageContentFactory(
title="test2", menu_title="test2", page_title="test2", language="en"
PageContentWithVersionFactory(
title="test2", menu_title="test2", page_title="test2", language="en", version__state=PUBLISHED
) # flake8: noqa
with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -145,11 +145,11 @@ def test_select2_view_text_page_repr(self):
def test_select2_view_search_text_page(self):
""" Both pages should appear in results for test query"""
page_contenttype_id = ContentType.objects.get_for_model(Page).id
PageContentFactory(
title="test", menu_title="test", page_title="test", language="en"
PageContentWithVersionFactory(
title="test", menu_title="test", page_title="test", language="en", version__state=PUBLISHED
)
PageContentFactory(
title="test2", menu_title="test2", page_title="test2", language="en"
PageContentWithVersionFactory(
title="test2", menu_title="test2", page_title="test2", language="en", version__state=PUBLISHED
)
with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -163,11 +163,11 @@ def test_select2_view_search_text_page(self):
def test_select2_view_search_exact_text_page(self):
""" One page should appear in results for test2 exact query"""
page_contenttype_id = ContentType.objects.get_for_model(Page).id
PageContentFactory(
title="test", menu_title="test", page_title="test", language="en"
PageContentWithVersionFactory(
title="test", menu_title="test", page_title="test", language="en", version__state=PUBLISHED
)
PageContentFactory(
title="test2", menu_title="test2", page_title="test2", language="en"
PageContentWithVersionFactory(
title="test2", menu_title="test2", page_title="test2", language="en", version__state=PUBLISHED
)
with self.login_user_context(self.superuser):
response = self.client.get(
Expand Down Expand Up @@ -272,8 +272,8 @@ def test_with_pages_in_multiple_languages(self):
Check that when page content exists in multiple languages, only pages for the current language are returned
"""
page_contenttype_id = ContentType.objects.get_for_model(Page).id
french = PageContentFactory(
title="test", menu_title="test", page_title="test", language="fr",
french = PageContentWithVersionFactory(
title="test", menu_title="test", page_title="test", language="fr", version__state=PUBLISHED
)
PageContentFactory.create_batch(10, title="test", menu_title="test", page_title="test", language="en")

Expand All @@ -300,7 +300,7 @@ def test_with_pages_for_multiple_sites(self):
site1 = Site.objects.create(name="site1.com", domain="site1.com")
site2 = Site.objects.create(name="site2.com", domain="site2.com")
PageContentFactory.create_batch(10, title="test", page__node__site=site1, language="en")
expected = PageContentFactory(title="test", menu_title="site2 page", page__node__site=site2, language="en")
expected = PageContentWithVersionFactory(title="test", menu_title="site2 page", page__node__site=site2, language="en", version__state=PUBLISHED)

Check failure on line 303 in tests/test_views.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (152 > 120 characters)

with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -322,7 +322,9 @@ def test_searching_for_page_slug(self):
"""
page_contenttype_id = ContentType.objects.get_for_model(Page).id
PageContentFactory.create_batch(10, language="en")
expected = PageContentFactory(title="Test search by slug", menu_title="Test search by slug", language="en")
expected = PageContentWithVersionFactory(
title="Test search by slug", menu_title="Test search by slug", language="en", version__state=PUBLISHED
)
slug = expected.page.get_slug("en")
# early smoke test to stop us getting a false positive by finding the page by its title rather than slug
self.assertNotEqual(expected.title.lower(), slug)
Expand All @@ -347,7 +349,9 @@ def test_searching_for_page_path(self):
"""
page_contenttype_id = ContentType.objects.get_for_model(Page).id
PageContentFactory.create_batch(10, language="en")
expected = PageContentFactory(menu_title="Test search by overwritten url", language="en")
expected = PageContentWithVersionFactory(
title="test", menu_title="Test search by overwritten url", page_title="test", language="en", version__state=PUBLISHED

Check failure on line 353 in tests/test_views.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (129 > 120 characters)
)
# update page urls to use a randomly generated path to represent setting an overwritten url
path = fake.uri_path()
expected.page.urls.update(path=path)
Expand Down Expand Up @@ -480,7 +484,7 @@ def test_page_queryset_filters_pages_by_current_language(self):
for language in ["en", "fr", "de", "it"]:
with self.subTest(msg=language):
request = self.get_request(language=language)
request.GET = {"content_type_id": self.page_contenttype_id, "query": "test"}
request.GET = {"content_type_id": self.page_contenttype_id, "query": "test", "language": language}
self.view.request = request
results = self.view.get_data()

Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ deps =
flake8: -r{toxinidir}/tests/requirements/requirements_base.txt
isort: -r{toxinidir}/tests/requirements/requirements_base.txt

dj32_cms40: -r{toxinidir}/tests/requirements/dj32_cms40.txt
dj42_cms40: -r{toxinidir}/tests/requirements/dj42_cms40.txt
dj42_cms41: -r{toxinidir}/tests/requirements/dj42_cms41.txt
dj32-cms40: -r{toxinidir}/tests/requirements/dj32_cms40.txt
dj42-cms40: -r{toxinidir}/tests/requirements/dj42_cms40.txt
dj42-cms41: -r{toxinidir}/tests/requirements/dj42_cms41.txt

basepython =
py39: python3.9
Expand Down

0 comments on commit 376b457

Please sign in to comment.