forked from zestedesavoir/zds-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corrige les pages de validation pour montrer les actions de validation (
zestedesavoir#6582) * Corrige les pages de validation pour montrer les actions de validation * Supprime des lignes redondantes * Ajoute les tests de la nouvelle vue
- Loading branch information
Showing
8 changed files
with
178 additions
and
8 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
76 changes: 76 additions & 0 deletions
76
zds/tutorialv2/tests/tests_views/tests_contentvalidationview.py
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,76 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents | ||
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory | ||
from zds.tutorialv2.tests.factories import PublishableContentFactory, ValidationFactory | ||
|
||
|
||
def request_validation(content): | ||
"""Emulate a proper validation request.""" | ||
ValidationFactory(content=content, status="PENDING") | ||
content.sha_validation = content.sha_draft | ||
content.save() | ||
|
||
|
||
@override_for_contents() | ||
class PermissionTests(TutorialTestMixin, TestCase): | ||
"""Test permissions and associated behaviors, such as redirections and status codes.""" | ||
|
||
def setUp(self): | ||
# Create a content and put it in validation | ||
self.author = ProfileFactory().user | ||
content = PublishableContentFactory(author_list=[self.author]) | ||
request_validation(content) | ||
|
||
# Data about the tested route | ||
url_args = {"pk": content.pk, "slug": content.slug} | ||
self.target_url = reverse("content:validation-view", kwargs=url_args) | ||
self.login_url = reverse("member-login") + "?next=" + self.target_url | ||
|
||
def test_not_authenticated(self): | ||
"""Test that unauthenticated users are redirected to the login page.""" | ||
self.client.logout() # ensure no user is authenticated | ||
response = self.client.get(self.target_url) | ||
self.assertRedirects(response, self.login_url) | ||
|
||
def test_authenticated_author(self): | ||
"""Test that authors can reach the page.""" | ||
self.client.force_login(self.author) | ||
response = self.client.get(self.target_url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_authenticated_staff(self): | ||
"""Test that staffs can reach the page.""" | ||
staff = StaffProfileFactory().user | ||
self.client.force_login(staff) | ||
response = self.client.get(self.target_url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_authenticated_outsider(self): | ||
"""Test that unauthorized users get a 403.""" | ||
outsider = ProfileFactory().user | ||
self.client.force_login(outsider) | ||
response = self.client.get(self.target_url) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
|
||
@override_for_contents() | ||
class FunctionalTests(TutorialTestMixin, TestCase): | ||
"""Test the behavior of the feature.""" | ||
|
||
def setUp(self): | ||
# Create a content and put it in validation | ||
self.author = StaffProfileFactory().user | ||
content = PublishableContentFactory(author_list=[self.author]) | ||
request_validation(content) | ||
|
||
# Data about the tested route | ||
url_args = {"pk": content.pk, "slug": content.slug} | ||
self.target_url = reverse("content:validation-view", kwargs=url_args) | ||
|
||
def test_validation_actions_shown(self): | ||
"""Test that the validation page shows the validation actions.""" | ||
self.client.force_login(self.author) | ||
response = self.client.get(self.target_url) | ||
self.assertContains(response, "<h3>Validation</h3>") |
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