experiENS/avisstage/tests.py

566 lines
18 KiB
Python
Raw Normal View History

2021-02-07 18:23:24 +01:00
from datetime import date, timedelta
2021-02-07 23:24:33 +01:00
from unittest import mock
2018-12-29 23:23:36 +01:00
2021-02-07 23:24:33 +01:00
from authens.models import CASAccount, OldCASAccount
from authens.tests.cas_utils import FakeCASClient
from django.conf import settings
2017-04-04 00:31:50 +02:00
from django.test import TestCase
2018-12-29 23:23:36 +01:00
from django.urls import reverse
2021-02-07 18:23:24 +01:00
from django.utils import timezone
2021-02-08 02:27:37 +01:00
from .models import AvisLieu, Lieu, Stage, StageMatiere, User
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
2021-02-07 18:23:24 +01:00
class ExperiENSTestCase(TestCase):
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
# Dummy database
2021-02-07 18:23:24 +01:00
2018-12-29 23:23:36 +01:00
def setUp(self):
2021-02-07 23:15:47 +01:00
self.u_conscrit = User.objects.create_user(
"conscrit", "conscrit@ens.fr", "conscrit"
)
2018-12-29 23:23:36 +01:00
self.p_conscrit = self.u_conscrit.profil
2021-02-07 18:23:24 +01:00
self.p_conscrit.nom = "Petit conscrit"
self.p_conscrit.promotion = "Serpentard 2020"
self.p_conscrit.bio = "Je suis un petit conscrit"
2018-12-29 23:23:36 +01:00
self.p_conscrit.save()
2021-02-07 18:23:24 +01:00
self.sa_conscrit = CASAccount(
user=self.u_conscrit,
cas_login="conscrit",
entrance_year=2020,
)
2018-12-29 23:23:36 +01:00
self.sa_conscrit.save()
2021-02-07 23:15:47 +01:00
self.u_archi = User.objects.create_user(
"archicube", "archicube@ens.fr", "archicube"
)
self.p_archi = self.u_archi.profil
self.p_archi.nom = "Vieil archicube"
self.p_archi.promotion = "Gryffondor 2014"
self.p_archi.bio = "Je suis un vieil archicube"
self.lieu1 = Lieu(
nom="Beaux-Bâtons",
type_lieu="universite",
ville="Brocéliande",
pays="FR",
coord="POINT(-1.63971 48.116382)",
)
2018-12-29 23:23:36 +01:00
self.lieu1.save()
2021-02-07 23:15:47 +01:00
self.lieu2 = Lieu(
nom="Durmstrang",
type_lieu="universite",
ville="Edimbourg",
pays="GB",
coord="POINT(56.32153 -1.259715)",
)
2018-12-29 23:23:36 +01:00
self.lieu2.save()
self.matiere1 = StageMatiere(nom="Arithmancie", slug="arithmancie")
self.matiere1.save()
self.matiere2 = StageMatiere(nom="Sortilège", slug="sortilege")
self.matiere2.save()
2021-02-07 23:15:47 +01:00
self.cstage1 = Stage(
auteur=self.p_conscrit,
sujet="Wingardium Leviosa",
date_debut=date(2020, 5, 10),
date_fin=date(2020, 8, 26),
type_stage="recherche",
niveau_scol="M1",
public=True,
)
2018-12-29 23:23:36 +01:00
self.cstage1.save()
self.cstage1.matieres.add(self.matiere1)
2021-02-07 23:15:47 +01:00
alieu1 = AvisLieu(stage=self.cstage1, lieu=self.lieu1, chapo="Trop bien")
2018-12-29 23:23:36 +01:00
alieu1.save()
2021-02-07 23:15:47 +01:00
self.cstage2 = Stage(
auteur=self.p_conscrit,
sujet="Avada Kedavra",
date_debut=date(2021, 5, 10),
date_fin=date(2021, 8, 26),
type_stage="sejour_dri",
niveau_scol="M2",
public=False,
)
2018-12-29 23:23:36 +01:00
self.cstage2.save()
self.cstage2.matieres.add(self.matiere2)
2021-02-07 23:15:47 +01:00
alieu2 = AvisLieu(stage=self.cstage2, lieu=self.lieu2, chapo="Trop nul")
2018-12-29 23:23:36 +01:00
alieu2.save()
2021-02-07 23:15:47 +01:00
self.astage1 = Stage(
auteur=self.p_archi,
sujet="Alohomora",
date_debut=date(2014, 5, 10),
date_fin=date(2014, 8, 26),
type_stage="recherche",
niveau_scol="M2",
public=True,
)
2018-12-29 23:23:36 +01:00
self.astage1.save()
self.astage1.matieres.add(self.matiere2)
2021-02-07 23:15:47 +01:00
alieu3 = AvisLieu(stage=self.astage1, lieu=self.lieu1, chapo="Trop moyen")
2018-12-29 23:23:36 +01:00
alieu3.save()
def assertRedirectToLogin(self, testurl):
r = self.client.get(testurl)
2021-02-07 23:15:47 +01:00
return self.assertRedirects(r, settings.LOGIN_URL + "?next=" + testurl)
2018-12-29 23:23:36 +01:00
def assertPageNotFound(self, testurl):
r = self.client.get(testurl)
self.assertEqual(r.status_code, 404)
"""
2021-02-07 18:23:24 +01:00
ACCÈS PUBLIC
2018-12-29 23:23:36 +01:00
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
class PublicViewsTest(ExperiENSTestCase):
"""
Vérifie que les fiches de stages ne sont pas visibles hors connexion
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_stage_visibility_public(self):
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:stage", kwargs={"pk": self.cstage1.id})
)
self.assertRedirectToLogin(
reverse("avisstage:stage", kwargs={"pk": self.cstage2.id})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:stage", kwargs={"pk": self.astage1.id})
)
2018-12-29 23:23:36 +01:00
"""
Vérifie que les profils de normaliens ne sont pas visibles hors connexion
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_profil_visibility_public(self):
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:profil", kwargs={"username": self.u_conscrit.username})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:profil", kwargs={"username": self.u_archi.username})
)
2018-12-29 23:23:36 +01:00
"""
Vérifie que la recherche n'est pas accessible hors connexion
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_pages_visibility_public(self):
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:recherche"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:recherche_resultats"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:stage_items"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:feedback"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:moderation"))
2018-12-29 23:23:36 +01:00
"""
Vérifie que l'API n'est pas accessible hors connexion
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_api_visibility_public(self):
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "lieu", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 401)
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "stage", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 401)
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "profil", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 401)
"""
Vérifie que les pages d'édition ne sont pas accessible hors connexion
"""
2021-02-07 23:15:47 +01:00
def test_edit_visibility_public(self):
self.assertRedirectToLogin(
reverse("avisstage:stage_edit", kwargs={"pk": self.cstage1.id})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:stage_edit", kwargs={"pk": self.astage1.id})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:stage_publication", kwargs={"pk": self.cstage1.id})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(
reverse("avisstage:stage_publication", kwargs={"pk": self.astage1.id})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:stage_ajout"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assertRedirectToLogin(reverse("avisstage:profil_edit"))
2018-12-29 23:23:36 +01:00
"""
ACCÈS ARCHICUBE
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
class ArchicubeViewsTest(ExperiENSTestCase):
def setUp(self):
super().setUp()
2021-02-07 18:23:24 +01:00
# Connexion with password
2021-02-07 23:15:47 +01:00
self.client.login(username="archicube", password="archicube")
2018-12-29 23:23:36 +01:00
def assert403Archicubes(self, testurl):
r = self.client.get(testurl)
2021-02-07 23:15:47 +01:00
return self.assertRedirects(r, reverse("avisstage:403-archicubes"))
2018-12-29 23:23:36 +01:00
"""
Vérifie que les seules fiches de stages visibles sont les siennes
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_stage_visibility_archi(self):
2021-02-07 23:15:47 +01:00
self.assertPageNotFound(
reverse("avisstage:stage", kwargs={"pk": self.cstage1.id})
)
self.assertPageNotFound(
reverse("avisstage:stage", kwargs={"pk": self.cstage2.id})
)
testurl = reverse("avisstage:stage", kwargs={"pk": self.astage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
"""
Vérifie que le seul profil visible est le sien
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_profil_visibility_archi(self):
2021-02-07 23:15:47 +01:00
self.assertPageNotFound(
reverse("avisstage:profil", kwargs={"username": self.u_conscrit.username})
)
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:profil", kwargs={"username": self.u_archi.username}
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
"""
Vérifie que la recherche n'est pas accessible
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_pages_visibility_archi(self):
2021-02-07 23:15:47 +01:00
self.assert403Archicubes(reverse("avisstage:recherche"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assert403Archicubes(reverse("avisstage:recherche_resultats"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
self.assert403Archicubes(reverse("avisstage:stage_items"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:feedback")
r = self.client.post(
testurl, {"objet": "Contact", "message": "Ceci est un texte"}
)
self.assertRedirects(r, reverse("avisstage:index"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:moderation")
r = self.client.get(testurl)
self.assertRedirects(r, reverse("admin:login") + "?next=" + testurl)
2018-12-29 23:23:36 +01:00
"""
Vérifie que la seule API accessible est celle des lieux
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_api_visibility_archi(self):
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "lieu", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "stage", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 401)
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "profil", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 401)
"""
Vérifie que le seul stage modifiable est le sien
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_edit_visibility_archi(self):
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_edit", kwargs={"pk": self.cstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 403)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_edit", kwargs={"pk": self.astage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_publication", kwargs={"pk": self.cstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.post(testurl, {"publier": True})
self.assertEqual(r.status_code, 403)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_publication", kwargs={"pk": self.astage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.post(testurl, {"publier": True})
2021-02-07 23:15:47 +01:00
self.assertRedirects(
r, reverse("avisstage:stage", kwargs={"pk": self.astage1.id})
)
testurl = reverse("avisstage:stage_ajout")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:profil_edit")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
# TODO : test post()
2018-12-30 16:29:36 +01:00
class DeprecatedArchicubeViewsTest(ArchicubeViewsTest):
2021-02-07 18:23:24 +01:00
@mock.patch("authens.backends.get_cas_client")
def setUp(self, mock_cas_client):
2018-12-30 16:29:36 +01:00
super().setUp()
2021-02-07 18:23:24 +01:00
fake_cas_client = FakeCASClient(cas_login="archicube", entrance_year=2012)
mock_cas_client.return_value = fake_cas_client
2021-02-07 23:15:47 +01:00
2021-02-07 18:23:24 +01:00
self.sa_archi = OldCASAccount(
user=self.u_archi,
cas_login="archicube",
entrance_year=2012,
)
2018-12-30 16:29:36 +01:00
self.sa_archi.save()
2018-12-29 23:23:36 +01:00
2021-02-07 18:23:24 +01:00
# First connexion through CAS
self.client.login(ticket="dummy")
self.client.logout()
# Time flies
self.p_archi.last_cas_login = (timezone.now() - timedelta(days=365)).date()
self.p_archi.save()
# New connexion with password
2021-02-07 23:15:47 +01:00
self.client.login(username="archicube", password="archicube")
2018-12-29 23:23:36 +01:00
"""
ACCÈS EN SCOLARITE
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
class ScolariteViewsTest(ExperiENSTestCase):
2021-02-07 18:23:24 +01:00
@mock.patch("authens.backends.get_cas_client")
def setUp(self, mock_cas_client):
2018-12-29 23:23:36 +01:00
super().setUp()
2021-02-07 18:23:24 +01:00
fake_cas_client = FakeCASClient(cas_login="vieuxcon", entrance_year=2017)
mock_cas_client.return_value = fake_cas_client
2021-02-07 23:15:47 +01:00
2021-02-07 18:23:24 +01:00
self.u_vieuxcon = User.objects.create_user(
2021-02-07 23:15:47 +01:00
"vieuxcon", "vieuxcon@ens.fr", "vieuxcon"
2021-02-07 18:23:24 +01:00
)
2018-12-29 23:23:36 +01:00
self.p_vieuxcon = self.u_vieuxcon.profil
2021-02-07 23:15:47 +01:00
self.p_vieuxcon.nom = "Vieux con"
self.p_vieuxcon.promotion = "Poufsouffle 2017"
self.p_vieuxcon.bio = "Je suis un vieux con encore en scolarité"
2018-12-29 23:23:36 +01:00
self.p_vieuxcon.save()
2021-02-07 18:23:24 +01:00
self.sa_vieuxcon = CASAccount(
user=self.u_vieuxcon,
cas_login="vieuxcon",
entrance_year=2017,
)
2018-12-29 23:23:36 +01:00
self.sa_vieuxcon.save()
2021-02-07 23:15:47 +01:00
self.vstage1 = Stage(
auteur=self.p_vieuxcon,
sujet="Oubliettes",
date_debut=date(2018, 5, 10),
date_fin=date(2018, 8, 26),
type_stage="recherche",
niveau_scol="M1",
public=False,
)
2018-12-29 23:23:36 +01:00
self.vstage1.save()
self.vstage1.matieres.add(self.matiere2)
2021-02-07 23:15:47 +01:00
alieu1 = AvisLieu(stage=self.vstage1, lieu=self.lieu2, chapo="Pas si mal")
2018-12-29 23:23:36 +01:00
alieu1.save()
2021-02-07 18:23:24 +01:00
# Connexion through CAS
self.client.login(ticket="dummy")
2018-12-29 23:23:36 +01:00
"""
Vérifie que les seules fiches de stages visibles sont les siennes ou celles
publiques
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_stage_visibility_scolarite(self):
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage", kwargs={"pk": self.cstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
self.assertPageNotFound(
reverse("avisstage:stage", kwargs={"pk": self.cstage2.id})
)
testurl = reverse("avisstage:stage", kwargs={"pk": self.vstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
"""
Vérifie que tous les profils sont visibles
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_profil_visibility_scolarite(self):
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:profil", kwargs={"username": self.u_conscrit.username}
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
self.assertContains(r, "Wingardium Leviosa") # Public
self.assertNotContains(r, "Avada Kedavra") # Brouillon
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:profil", kwargs={"username": self.u_archi.username}
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:profil", kwargs={"username": self.u_vieuxcon.username}
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
"""
2021-02-07 18:23:24 +01:00
Vérifie que la recherche et les autres pages sont accessibles
2018-12-29 23:23:36 +01:00
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_pages_visibility_scolarite(self):
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:recherche")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:recherche_resultats")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
self.assertContains(r, "Wingardium Leviosa") # Public
self.assertNotContains(r, "Avada Kedavra") # Brouillon
testurl = (
reverse("avisstage:stage_items")
+ "?ids="
+ ";".join(
("%d" % k.id) for k in [self.cstage1, self.cstage2, self.astage1]
)
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
self.assertContains(r, "Wingardium Leviosa") # Public
self.assertNotContains(r, "Avada Kedavra") # Brouillon
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:feedback")
r = self.client.post(
testurl, {"objet": "Contact", "message": "Ceci est un texte"}
)
self.assertRedirects(r, reverse("avisstage:index"))
2018-12-29 23:23:36 +01:00
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:moderation")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
2021-02-07 23:15:47 +01:00
self.assertRedirects(r, reverse("admin:login") + "?next=" + testurl)
2018-12-29 23:23:36 +01:00
"""
Vérifie que toutes les API sont accessibles et qu'elles ne montrent que les
stages publics
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_api_visibility_scolarite(self):
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "lieu", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "stage", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
self.assertContains(r, "Wingardium Leviosa") # Public
self.assertNotContains(r, "Avada Kedavra") # Brouillon
testurl = reverse(
"avisstage:api_dispatch_list",
kwargs={"resource_name": "profil", "api_name": "v1"},
)
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
"""
Vérifie que le seul stage modifiable est le sien
"""
2021-02-07 23:15:47 +01:00
2018-12-29 23:23:36 +01:00
def test_edit_visibility_scolarite(self):
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_edit", kwargs={"pk": self.cstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 403)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_edit", kwargs={"pk": self.astage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 403)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_edit", kwargs={"pk": self.vstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_publication", kwargs={"pk": self.cstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.post(testurl, {"publier": True})
self.assertEqual(r.status_code, 403)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:stage_publication", kwargs={"pk": self.vstage1.id})
2018-12-29 23:23:36 +01:00
r = self.client.post(testurl, {"publier": True})
2021-02-07 23:15:47 +01:00
self.assertRedirects(
r, reverse("avisstage:stage", kwargs={"pk": self.vstage1.id})
)
testurl = reverse("avisstage:stage_ajout")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2021-02-07 23:15:47 +01:00
testurl = reverse("avisstage:profil_edit")
2018-12-29 23:23:36 +01:00
r = self.client.get(testurl)
self.assertEqual(r.status_code, 200)
2017-04-04 00:31:50 +02:00
2018-12-29 23:23:36 +01:00
# TODO : test post()