This commit is contained in:
Ludovic Stephan 2020-06-13 20:42:04 +02:00
parent 6cd64dd441
commit 189159f9e5
2 changed files with 36 additions and 2 deletions

View file

@ -53,7 +53,7 @@ class OldCASAuthForm(forms.Form):
def get_invalid_login_error(self):
return forms.ValidationError(
_(
"Aucun utilisateur n'existe avec ce clipper, cette promo et/ou ce mot"
"Aucun utilisateur n'existe avec ce clipper, cette promo et/ou ce mot "
"de passe. Veuillez vérifier votre saisie. Attention, tous les champs "
"sont sensibles à la casse !"
),

View file

@ -7,7 +7,8 @@ from django.contrib.sessions.models import Session
from django.test import Client, TestCase
from django.urls import reverse
from authens.models import CASAccount
from authens.forms import OldCASAuthForm
from authens.models import CASAccount, OldCASAccount
from authens.tests.cas_utils import FakeCASClient
UserModel = get_user_model()
@ -44,6 +45,39 @@ class TestLoginViews(TestCase):
response = Client().get(reverse("authens:login"))
self.assertEqual(response.status_code, 200)
def test_oldcas_login(self):
url = reverse("authens:login.oldcas")
client = Client()
user = UserModel.objects.create_user(username="johndoe31", password="password")
# Decoy user that may be authenticated by mistake
UserModel.objects.create_user(username="johndoe", password="password")
OldCASAccount.objects.create(user=user, cas_login="johndoe", entrance_year=2019)
post_data = dict(cas_login="johndoe", password="password", entrance_year=2019)
response = client.post(url, post_data)
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
def test_oldcas_login_error(self):
url = reverse("authens:login.oldcas")
client = Client()
user = UserModel.objects.create_user(username="johndoe31", password="password")
OldCASAccount.objects.create(user=user, cas_login="johndoe", entrance_year=2019)
wrong_year = dict(cas_login="johndoe", password="password", entrance_year=2018)
wrong_login = dict(
cas_login="johndoe31", password="password", entrance_year=2019
)
response = client.post(url, wrong_year, follow=True)
non_field_errors = response.context["form"].non_field_errors().as_data()
self.assertEqual(non_field_errors[0].code, "invalid_login")
response = client.post(url, wrong_login, follow=True)
non_field_errors = response.context["form"].non_field_errors().as_data()
self.assertEqual(non_field_errors[0].code, "invalid_login")
class TestLogoutView(TestCase):
def test_regular_logout(self):