Skip to content

Commit

Permalink
Autorise la vue EditGoals seulement pour la méthode POST
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Jul 18, 2022
1 parent 800dae5 commit b9518d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_editgoals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def setUp(self):
self.bad_url = reverse("content:edit-goals", kwargs={"pk": 42})
self.success_url = reverse("content:view", kwargs={"pk": self.content.pk, "slug": self.content.slug})

def test_get_method(self):
"""
GET is forbidden, since the view processes the form but do not display anything.
Actually, all methods except POST are forbidden, but the test is good enough as is.
"""
self.client.force_login(self.staff)
response = self.client.get(self.good_url)
self.assertEqual(response.status_code, 405)

def test_unauthenticated_not_existing_pk(self):
"""Invalid pks in URL"""
self.client.logout()
Expand Down
1 change: 1 addition & 0 deletions zds/tutorialv2/views/goals.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class EditGoals(LoginRequiredMixin, PermissionRequiredMixin, SingleContentFormVi
form_class = EditGoalsForm
success_message = _("Les objectifs ont bien été modifiés.")
modal_form = True
http_method_names = ["post"]

def dispatch(self, request, *args, **kwargs):
content = get_object_or_404(PublishableContent, pk=self.kwargs["pk"])
Expand Down

0 comments on commit b9518d4

Please sign in to comment.