Corrige les tests

This commit is contained in:
Robin Champenois 2021-01-31 23:25:44 +01:00
parent 126bce9be3
commit 04efa743f6

View file

@ -1,32 +1,36 @@
from allauth.socialaccount.models import SocialAccount
from allauth_cas.test.testcases import CASTestCase
from allauth_ens.adapter import deprecate_clippers
from authens.tests.cas_utils import FakeCASClient
from authens.models import CASAccount, OldCASAccount
from datetime import date
from datetime import date, timedelta
from django.test import TestCase
from django.urls import reverse
from django.conf import settings
from django.utils import timezone
from unittest import mock
from .models import User, Normalien, Lieu, Stage, StageMatiere, AvisLieu
class ExperiENSTestCase(CASTestCase):
class ExperiENSTestCase(TestCase):
# Dummy database
def setUp(self):
self.u_conscrit = User.objects.create_user('conscrit',
'conscrit@ens.fr',
'conscrit')
self.p_conscrit = self.u_conscrit.profil
self.p_conscrit.nom="Petit conscrit"
self.p_conscrit.promotion="Serpentard 2000"
self.p_conscrit.bio="Je suis un petit conscrit"
self.p_conscrit.nom = "Petit conscrit"
self.p_conscrit.promotion = "Serpentard 2020"
self.p_conscrit.bio = "Je suis un petit conscrit"
self.p_conscrit.save()
self.sa_conscrit = SocialAccount(user=self.u_conscrit,
provider="clipper",
uid="conscrit")
self.sa_conscrit = CASAccount(
user=self.u_conscrit,
cas_login="conscrit",
entrance_year=2020,
)
self.sa_conscrit.save()
self.u_archi = User.objects.create_user('archicube',
@ -34,7 +38,7 @@ class ExperiENSTestCase(CASTestCase):
'archicube')
self.p_archi = self.u_archi.profil
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.lieu1 = Lieu(nom="Beaux-Bâtons", type_lieu="universite",
@ -52,8 +56,8 @@ class ExperiENSTestCase(CASTestCase):
self.matiere2.save()
self.cstage1 = Stage(auteur=self.p_conscrit, sujet="Wingardium Leviosa",
date_debut=date(2000, 5, 10),
date_fin=date(2000, 8, 26),
date_debut=date(2020, 5, 10),
date_fin=date(2020, 8, 26),
type_stage="recherche",
niveau_scol="M1", public=True)
self.cstage1.save()
@ -63,8 +67,8 @@ class ExperiENSTestCase(CASTestCase):
alieu1.save()
self.cstage2 = Stage(auteur=self.p_conscrit, sujet="Avada Kedavra",
date_debut=date(2001, 5, 10),
date_fin=date(2001, 8, 26),
date_debut=date(2021, 5, 10),
date_fin=date(2021, 8, 26),
type_stage="sejour_dri",
niveau_scol="M2", public=False)
self.cstage2.save()
@ -75,8 +79,8 @@ class ExperiENSTestCase(CASTestCase):
self.astage1 = Stage(auteur=self.p_archi, sujet="Alohomora",
date_debut=date(1994, 5, 10),
date_fin=date(1994, 8, 26),
date_debut=date(2014, 5, 10),
date_fin=date(2014, 8, 26),
type_stage="recherche",
niveau_scol="M2", public=True)
self.astage1.save()
@ -100,7 +104,7 @@ class ExperiENSTestCase(CASTestCase):
"""
ACCÈS PUBLICS
ACCÈS PUBLIC
"""
class PublicViewsTest(ExperiENSTestCase):
"""
@ -196,6 +200,7 @@ ACCÈS ARCHICUBE
class ArchicubeViewsTest(ExperiENSTestCase):
def setUp(self):
super().setUp()
# Connexion with password
self.client.login(username='archicube', password='archicube')
def assert403Archicubes(self, testurl):
@ -309,16 +314,29 @@ class ArchicubeViewsTest(ExperiENSTestCase):
class DeprecatedArchicubeViewsTest(ArchicubeViewsTest):
def setUp(self):
@mock.patch("authens.backends.get_cas_client")
def setUp(self, mock_cas_client):
super().setUp()
self.sa_archi = SocialAccount(user=self.u_archi,
provider="clipper",
uid="archicube")
fake_cas_client = FakeCASClient(cas_login="archicube", entrance_year=2012)
mock_cas_client.return_value = fake_cas_client
self.sa_archi = OldCASAccount(
user=self.u_archi,
cas_login="archicube",
entrance_year=2012,
)
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')
@ -328,26 +346,34 @@ class DeprecatedArchicubeViewsTest(ArchicubeViewsTest):
ACCÈS EN SCOLARITE
"""
class ScolariteViewsTest(ExperiENSTestCase):
def setUp(self):
@mock.patch("authens.backends.get_cas_client")
def setUp(self, mock_cas_client):
super().setUp()
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')
self.u_vieuxcon = User.objects.create_user(
'vieuxcon',
'vieuxcon@ens.fr',
'vieuxcon'
)
self.p_vieuxcon = self.u_vieuxcon.profil
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.save()
self.sa_vieuxcon = SocialAccount(user=self.u_vieuxcon,
provider="clipper",
uid="vieuxcon")
self.sa_vieuxcon = CASAccount(
user=self.u_vieuxcon,
cas_login="vieuxcon",
entrance_year=2017,
)
self.sa_vieuxcon.save()
self.vstage1 = Stage(auteur=self.p_vieuxcon, sujet="Oubliettes",
date_debut=date(1998, 5, 10),
date_fin=date(1998, 8, 26),
date_debut=date(2018, 5, 10),
date_fin=date(2018, 8, 26),
type_stage="recherche",
niveau_scol="M1", public=False)
self.vstage1.save()
@ -355,8 +381,9 @@ class ScolariteViewsTest(ExperiENSTestCase):
alieu1 = AvisLieu(stage=self.vstage1, lieu=self.lieu2,
chapo="Pas si mal")
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
@ -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):
testurl = reverse('avisstage:recherche')