-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛(courses) hide unpublished objects from list views (#1580)
The template code was a bit too naïve and did not exclude unpublished objects on the public site.
- Loading branch information
1 parent
cf53719
commit b3c46a8
Showing
8 changed files
with
218 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
End-to-end tests for the category list view | ||
""" | ||
from datetime import timedelta | ||
from unittest import mock | ||
|
||
from django.utils import timezone | ||
|
||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from richie.apps.core.factories import PageFactory, UserFactory | ||
from richie.apps.courses.factories import CategoryFactory | ||
|
||
|
||
class ListCategoryCMSTestCase(CMSTestCase): | ||
""" | ||
End-to-end test suite to validate the content and Ux of the category list view | ||
""" | ||
|
||
def test_templates_category_list_cms_content(self): | ||
""" | ||
Validate that the public website only displays categories that are currently published, | ||
while staff users can see draft and unpublished categories. | ||
""" | ||
page = PageFactory( | ||
template="courses/cms/category_list.html", | ||
title__language="en", | ||
should_publish=True, | ||
) | ||
|
||
CategoryFactory(page_parent=page, page_title="First category") | ||
CategoryFactory( | ||
page_parent=page, page_title="Second category", should_publish=True | ||
) | ||
|
||
# Publish with a publication date in the future | ||
future = timezone.now() + timedelta(hours=1) | ||
with mock.patch("cms.models.pagemodel.now", return_value=future): | ||
CategoryFactory( | ||
page_parent=page, page_title="Third category", should_publish=True | ||
) | ||
|
||
# Anonymous users should only see published categories | ||
response = self.client.get(page.get_absolute_url()) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertNotContains(response, "First") | ||
self.assertContains(response, "Second") | ||
self.assertNotContains(response, "Third") | ||
|
||
# Staff users can see draft and unpublished categories | ||
user = UserFactory(is_staff=True, is_superuser=True) | ||
self.client.login(username=user.username, password="password") | ||
|
||
response = self.client.get(page.get_absolute_url()) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
for title in ["First", "Second", "Third"]: | ||
self.assertContains(response, title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
End-to-end tests for the person list view | ||
""" | ||
from datetime import timedelta | ||
from unittest import mock | ||
|
||
from django.utils import timezone | ||
|
||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from richie.apps.core.factories import PageFactory, UserFactory | ||
from richie.apps.courses.factories import PersonFactory | ||
|
||
|
||
class ListPersonCMSTestCase(CMSTestCase): | ||
""" | ||
End-to-end test suite to validate the content and Ux of the person list view | ||
""" | ||
|
||
def test_templates_person_list_cms_content(self): | ||
""" | ||
Validate that the public website only displays persons that are currently published, | ||
while staff users can see draft and unpublished persons. | ||
""" | ||
page = PageFactory( | ||
template="courses/cms/person_list.html", | ||
title__language="en", | ||
should_publish=True, | ||
) | ||
|
||
PersonFactory(page_parent=page, page_title="First person") | ||
PersonFactory(page_parent=page, page_title="Second person", should_publish=True) | ||
|
||
# Publish with a publication date in the future | ||
future = timezone.now() + timedelta(hours=1) | ||
with mock.patch("cms.models.pagemodel.now", return_value=future): | ||
PersonFactory( | ||
page_parent=page, page_title="Third person", should_publish=True | ||
) | ||
|
||
# Anonymous users should only see published persons | ||
response = self.client.get(page.get_absolute_url()) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertNotContains(response, "First") | ||
self.assertContains(response, "Second") | ||
self.assertNotContains(response, "Third") | ||
|
||
# Staff users can see draft and unpublished persons | ||
user = UserFactory(is_staff=True, is_superuser=True) | ||
self.client.login(username=user.username, password="password") | ||
|
||
response = self.client.get(page.get_absolute_url()) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
for title in ["First", "Second", "Third"]: | ||
self.assertContains(response, title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
End-to-end tests for the program list view | ||
""" | ||
from datetime import timedelta | ||
from unittest import mock | ||
|
||
from django.utils import timezone | ||
|
||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from richie.apps.core.factories import PageFactory, UserFactory | ||
from richie.apps.courses.factories import ProgramFactory | ||
|
||
|
||
class ListProgramCMSTestCase(CMSTestCase): | ||
""" | ||
End-to-end test suite to validate the content and Ux of the program list view | ||
""" | ||
|
||
def test_templates_program_list_cms_content(self): | ||
""" | ||
Validate that the public website only displays programs that are currently published, | ||
while staff users can see draft and unpublished programs. | ||
""" | ||
page = PageFactory( | ||
template="courses/cms/program_list.html", | ||
title__language="en", | ||
should_publish=True, | ||
) | ||
|
||
ProgramFactory(page_parent=page, page_title="First program") | ||
ProgramFactory( | ||
page_parent=page, page_title="Second program", should_publish=True | ||
) | ||
|
||
# Publish with a publication date in the future | ||
future = timezone.now() + timedelta(hours=1) | ||
with mock.patch("cms.models.pagemodel.now", return_value=future): | ||
ProgramFactory( | ||
page_parent=page, page_title="Third program", should_publish=True | ||
) | ||
|
||
# Anonymous users should only see published programs | ||
response = self.client.get(page.get_absolute_url()) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertNotContains(response, "First") | ||
self.assertContains(response, "Second") | ||
self.assertNotContains(response, "Third") | ||
|
||
# Staff users can see draft and unpublished programs | ||
user = UserFactory(is_staff=True, is_superuser=True) | ||
self.client.login(username=user.username, password="password") | ||
|
||
response = self.client.get(page.get_absolute_url()) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
for title in ["First", "Second", "Third"]: | ||
self.assertContains(response, title) |