Reformatage #29
1 changed files with 67 additions and 40 deletions
|
@ -1,16 +1,18 @@
|
||||||
from allauth.socialaccount.models import SocialAccount
|
from authens.tests.cas_utils import FakeCASClient
|
||||||
from allauth_cas.test.testcases import CASTestCase
|
from authens.models import CASAccount, OldCASAccount
|
||||||
from allauth_ens.adapter import deprecate_clippers
|
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date, timedelta
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from .models import User, Normalien, Lieu, Stage, StageMatiere, AvisLieu
|
from .models import User, Normalien, Lieu, Stage, StageMatiere, AvisLieu
|
||||||
|
|
||||||
class ExperiENSTestCase(CASTestCase):
|
class ExperiENSTestCase(TestCase):
|
||||||
|
|
||||||
# Dummy database
|
# Dummy database
|
||||||
|
|
||||||
|
@ -20,13 +22,15 @@ class ExperiENSTestCase(CASTestCase):
|
||||||
'conscrit')
|
'conscrit')
|
||||||
self.p_conscrit = self.u_conscrit.profil
|
self.p_conscrit = self.u_conscrit.profil
|
||||||
self.p_conscrit.nom = "Petit conscrit"
|
self.p_conscrit.nom = "Petit conscrit"
|
||||||
self.p_conscrit.promotion="Serpentard 2000"
|
self.p_conscrit.promotion = "Serpentard 2020"
|
||||||
self.p_conscrit.bio = "Je suis un petit conscrit"
|
self.p_conscrit.bio = "Je suis un petit conscrit"
|
||||||
self.p_conscrit.save()
|
self.p_conscrit.save()
|
||||||
|
|
||||||
self.sa_conscrit = SocialAccount(user=self.u_conscrit,
|
self.sa_conscrit = CASAccount(
|
||||||
provider="clipper",
|
user=self.u_conscrit,
|
||||||
uid="conscrit")
|
cas_login="conscrit",
|
||||||
|
entrance_year=2020,
|
||||||
|
)
|
||||||
self.sa_conscrit.save()
|
self.sa_conscrit.save()
|
||||||
|
|
||||||
self.u_archi = User.objects.create_user('archicube',
|
self.u_archi = User.objects.create_user('archicube',
|
||||||
|
@ -34,7 +38,7 @@ class ExperiENSTestCase(CASTestCase):
|
||||||
'archicube')
|
'archicube')
|
||||||
self.p_archi = self.u_archi.profil
|
self.p_archi = self.u_archi.profil
|
||||||
self.p_archi.nom="Vieil archicube"
|
self.p_archi.nom="Vieil archicube"
|
||||||
self.p_archi.promotion="Gryffondor 1994"
|
self.p_archi.promotion="Gryffondor 2014"
|
||||||
self.p_archi.bio="Je suis un vieil archicube"
|
self.p_archi.bio="Je suis un vieil archicube"
|
||||||
|
|
||||||
self.lieu1 = Lieu(nom="Beaux-Bâtons", type_lieu="universite",
|
self.lieu1 = Lieu(nom="Beaux-Bâtons", type_lieu="universite",
|
||||||
|
@ -52,8 +56,8 @@ class ExperiENSTestCase(CASTestCase):
|
||||||
self.matiere2.save()
|
self.matiere2.save()
|
||||||
|
|
||||||
self.cstage1 = Stage(auteur=self.p_conscrit, sujet="Wingardium Leviosa",
|
self.cstage1 = Stage(auteur=self.p_conscrit, sujet="Wingardium Leviosa",
|
||||||
date_debut=date(2000, 5, 10),
|
date_debut=date(2020, 5, 10),
|
||||||
date_fin=date(2000, 8, 26),
|
date_fin=date(2020, 8, 26),
|
||||||
type_stage="recherche",
|
type_stage="recherche",
|
||||||
niveau_scol="M1", public=True)
|
niveau_scol="M1", public=True)
|
||||||
self.cstage1.save()
|
self.cstage1.save()
|
||||||
|
@ -63,8 +67,8 @@ class ExperiENSTestCase(CASTestCase):
|
||||||
alieu1.save()
|
alieu1.save()
|
||||||
|
|
||||||
self.cstage2 = Stage(auteur=self.p_conscrit, sujet="Avada Kedavra",
|
self.cstage2 = Stage(auteur=self.p_conscrit, sujet="Avada Kedavra",
|
||||||
date_debut=date(2001, 5, 10),
|
date_debut=date(2021, 5, 10),
|
||||||
date_fin=date(2001, 8, 26),
|
date_fin=date(2021, 8, 26),
|
||||||
type_stage="sejour_dri",
|
type_stage="sejour_dri",
|
||||||
niveau_scol="M2", public=False)
|
niveau_scol="M2", public=False)
|
||||||
self.cstage2.save()
|
self.cstage2.save()
|
||||||
|
@ -75,8 +79,8 @@ class ExperiENSTestCase(CASTestCase):
|
||||||
|
|
||||||
|
|
||||||
self.astage1 = Stage(auteur=self.p_archi, sujet="Alohomora",
|
self.astage1 = Stage(auteur=self.p_archi, sujet="Alohomora",
|
||||||
date_debut=date(1994, 5, 10),
|
date_debut=date(2014, 5, 10),
|
||||||
date_fin=date(1994, 8, 26),
|
date_fin=date(2014, 8, 26),
|
||||||
type_stage="recherche",
|
type_stage="recherche",
|
||||||
niveau_scol="M2", public=True)
|
niveau_scol="M2", public=True)
|
||||||
self.astage1.save()
|
self.astage1.save()
|
||||||
|
@ -100,7 +104,7 @@ class ExperiENSTestCase(CASTestCase):
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ACCÈS PUBLICS
|
ACCÈS PUBLIC
|
||||||
"""
|
"""
|
||||||
class PublicViewsTest(ExperiENSTestCase):
|
class PublicViewsTest(ExperiENSTestCase):
|
||||||
"""
|
"""
|
||||||
|
@ -196,6 +200,7 @@ ACCÈS ARCHICUBE
|
||||||
class ArchicubeViewsTest(ExperiENSTestCase):
|
class ArchicubeViewsTest(ExperiENSTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
# Connexion with password
|
||||||
self.client.login(username='archicube', password='archicube')
|
self.client.login(username='archicube', password='archicube')
|
||||||
|
|
||||||
def assert403Archicubes(self, testurl):
|
def assert403Archicubes(self, testurl):
|
||||||
|
@ -309,16 +314,29 @@ class ArchicubeViewsTest(ExperiENSTestCase):
|
||||||
|
|
||||||
|
|
||||||
class DeprecatedArchicubeViewsTest(ArchicubeViewsTest):
|
class DeprecatedArchicubeViewsTest(ArchicubeViewsTest):
|
||||||
def setUp(self):
|
@mock.patch("authens.backends.get_cas_client")
|
||||||
|
def setUp(self, mock_cas_client):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.sa_archi = SocialAccount(user=self.u_archi,
|
fake_cas_client = FakeCASClient(cas_login="archicube", entrance_year=2012)
|
||||||
provider="clipper",
|
mock_cas_client.return_value = fake_cas_client
|
||||||
uid="archicube")
|
|
||||||
|
self.sa_archi = OldCASAccount(
|
||||||
|
user=self.u_archi,
|
||||||
|
cas_login="archicube",
|
||||||
|
entrance_year=2012,
|
||||||
|
)
|
||||||
self.sa_archi.save()
|
self.sa_archi.save()
|
||||||
|
|
||||||
deprecate_clippers()
|
# 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
|
||||||
self.client.login(username='archicube', password='archicube')
|
self.client.login(username='archicube', password='archicube')
|
||||||
|
|
||||||
|
|
||||||
|
@ -328,26 +346,34 @@ class DeprecatedArchicubeViewsTest(ArchicubeViewsTest):
|
||||||
ACCÈS EN SCOLARITE
|
ACCÈS EN SCOLARITE
|
||||||
"""
|
"""
|
||||||
class ScolariteViewsTest(ExperiENSTestCase):
|
class ScolariteViewsTest(ExperiENSTestCase):
|
||||||
def setUp(self):
|
@mock.patch("authens.backends.get_cas_client")
|
||||||
|
def setUp(self, mock_cas_client):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.u_vieuxcon = User.objects.create_user('vieuxcon',
|
fake_cas_client = FakeCASClient(cas_login="vieuxcon", entrance_year=2017)
|
||||||
|
mock_cas_client.return_value = fake_cas_client
|
||||||
|
|
||||||
|
self.u_vieuxcon = User.objects.create_user(
|
||||||
|
'vieuxcon',
|
||||||
'vieuxcon@ens.fr',
|
'vieuxcon@ens.fr',
|
||||||
'vieuxcon')
|
'vieuxcon'
|
||||||
|
)
|
||||||
self.p_vieuxcon = self.u_vieuxcon.profil
|
self.p_vieuxcon = self.u_vieuxcon.profil
|
||||||
self.p_vieuxcon.nom="Vieux con"
|
self.p_vieuxcon.nom="Vieux con"
|
||||||
self.p_vieuxcon.promotion="Poufsouffle 1997"
|
self.p_vieuxcon.promotion="Poufsouffle 2017"
|
||||||
self.p_vieuxcon.bio="Je suis un vieux con encore en scolarité"
|
self.p_vieuxcon.bio="Je suis un vieux con encore en scolarité"
|
||||||
self.p_vieuxcon.save()
|
self.p_vieuxcon.save()
|
||||||
|
|
||||||
self.sa_vieuxcon = SocialAccount(user=self.u_vieuxcon,
|
self.sa_vieuxcon = CASAccount(
|
||||||
provider="clipper",
|
user=self.u_vieuxcon,
|
||||||
uid="vieuxcon")
|
cas_login="vieuxcon",
|
||||||
|
entrance_year=2017,
|
||||||
|
)
|
||||||
self.sa_vieuxcon.save()
|
self.sa_vieuxcon.save()
|
||||||
|
|
||||||
self.vstage1 = Stage(auteur=self.p_vieuxcon, sujet="Oubliettes",
|
self.vstage1 = Stage(auteur=self.p_vieuxcon, sujet="Oubliettes",
|
||||||
date_debut=date(1998, 5, 10),
|
date_debut=date(2018, 5, 10),
|
||||||
date_fin=date(1998, 8, 26),
|
date_fin=date(2018, 8, 26),
|
||||||
type_stage="recherche",
|
type_stage="recherche",
|
||||||
niveau_scol="M1", public=False)
|
niveau_scol="M1", public=False)
|
||||||
self.vstage1.save()
|
self.vstage1.save()
|
||||||
|
@ -356,7 +382,8 @@ class ScolariteViewsTest(ExperiENSTestCase):
|
||||||
chapo="Pas si mal")
|
chapo="Pas si mal")
|
||||||
alieu1.save()
|
alieu1.save()
|
||||||
|
|
||||||
self.client.login(username='vieuxcon', password='vieuxcon')
|
# Connexion through CAS
|
||||||
|
self.client.login(ticket="dummy")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Vérifie que les seules fiches de stages visibles sont les siennes ou celles
|
Vérifie que les seules fiches de stages visibles sont les siennes ou celles
|
||||||
|
@ -400,7 +427,7 @@ class ScolariteViewsTest(ExperiENSTestCase):
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Vérifie que la recherche et les autres pages sont accessible
|
Vérifie que la recherche et les autres pages sont accessibles
|
||||||
"""
|
"""
|
||||||
def test_pages_visibility_scolarite(self):
|
def test_pages_visibility_scolarite(self):
|
||||||
testurl = reverse('avisstage:recherche')
|
testurl = reverse('avisstage:recherche')
|
||||||
|
|
Loading…
Reference in a new issue