More relevant tests for register_cas_account

This commit is contained in:
Martin Pépin 2020-06-20 17:45:39 +02:00
parent a71688bbd5
commit 73cf73157c
No known key found for this signature in database
GPG key ID: E7520278B1774448

View file

@ -25,13 +25,18 @@ class TestRegisterCasAccount(TestCase):
self.assertEqual(user.cas_account.entrance_year, 2019)
def test_cant_register_twice(self):
user = User.objects.create_user(username="whatever")
CASAccount.objects.create(user=user, cas_login="johndoe", entrance_year=2019)
john = User.objects.create_user(username="whatever")
CASAccount.objects.create(user=john, cas_login="johndoe", entrance_year=2019)
janis = User.objects.create_user(username="janisjoplin")
# John cannot have two CAS accounts
with self.assertRaises(ValueError):
register_cas_account(user, cas_login="johndoe")
register_cas_account(john, cas_login="joplin")
# Janis cannot steal John's account
with self.assertRaises(ValueError):
register_cas_account(user, cas_login="janisjoplin")
register_cas_account(janis, cas_login="johndoe")
self.assertEqual(CASAccount.objects.count(), 1)
@ -41,7 +46,5 @@ class TestRegisterCasAccount(TestCase):
with self.assertRaises(ValueError):
register_cas_account(user, cas_login="toto")
with self.assertRaises(ValueError):
register_cas_account(user, cas_login="ninasimone")
self.assertFalse(CASAccount.objects.exists())