mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
Enforce uid with uppercase for Studentcard and test more edge cases
This commit is contained in:
parent
5ae7d10e84
commit
19e353970d
@ -749,7 +749,8 @@ class StudentCard(models.Model):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid(uid):
|
def is_valid(uid):
|
||||||
return (
|
return (
|
||||||
len(uid) == StudentCard.UID_SIZE
|
uid.isupper()
|
||||||
|
and len(uid) == StudentCard.UID_SIZE
|
||||||
and not StudentCard.objects.filter(uid=uid).exists()
|
and not StudentCard.objects.filter(uid=uid).exists()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -188,6 +188,7 @@ class StudentCardTest(TestCase):
|
|||||||
self.assertContains(response, text="8B90734A802A8F")
|
self.assertContains(response, text="8B90734A802A8F")
|
||||||
|
|
||||||
def test_add_student_card_from_counter_fail(self):
|
def test_add_student_card_from_counter_fail(self):
|
||||||
|
# UID too short
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse(
|
||||||
"counter:click",
|
"counter:click",
|
||||||
@ -199,6 +200,7 @@ class StudentCardTest(TestCase):
|
|||||||
response, text="Ce n'est pas un UID de carte étudiante valide"
|
response, text="Ce n'est pas un UID de carte étudiante valide"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# UID too long
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse(
|
||||||
"counter:click",
|
"counter:click",
|
||||||
@ -210,6 +212,30 @@ class StudentCardTest(TestCase):
|
|||||||
response, text="Ce n'est pas un UID de carte étudiante valide"
|
response, text="Ce n'est pas un UID de carte étudiante valide"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test with already existing card
|
||||||
|
response = self.client.post(
|
||||||
|
reverse(
|
||||||
|
"counter:click",
|
||||||
|
kwargs={"counter_id": self.counter.id, "user_id": self.sli.id},
|
||||||
|
),
|
||||||
|
{"student_card_uid": "9A89B82018B0A0", "action": "add_student_card"},
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response, text="Ce n'est pas un UID de carte étudiante valide"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test with lowercase
|
||||||
|
response = self.client.post(
|
||||||
|
reverse(
|
||||||
|
"counter:click",
|
||||||
|
kwargs={"counter_id": self.counter.id, "user_id": self.sli.id},
|
||||||
|
),
|
||||||
|
{"student_card_uid": "8b90734a802a9f", "action": "add_student_card"},
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response, text="Ce n'est pas un UID de carte étudiante valide"
|
||||||
|
)
|
||||||
|
|
||||||
def test_delete_student_card_with_owner(self):
|
def test_delete_student_card_with_owner(self):
|
||||||
self.client.login(username="sli", password="plop")
|
self.client.login(username="sli", password="plop")
|
||||||
self.client.post(
|
self.client.post(
|
||||||
@ -308,6 +334,7 @@ class StudentCardTest(TestCase):
|
|||||||
|
|
||||||
def test_add_student_card_from_user_preferences_fail(self):
|
def test_add_student_card_from_user_preferences_fail(self):
|
||||||
self.client.login(username="sli", password="plop")
|
self.client.login(username="sli", password="plop")
|
||||||
|
# UID too short
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse(
|
||||||
"counter:add_student_card", kwargs={"customer_id": self.sli.customer.pk}
|
"counter:add_student_card", kwargs={"customer_id": self.sli.customer.pk}
|
||||||
@ -317,6 +344,7 @@ class StudentCardTest(TestCase):
|
|||||||
|
|
||||||
self.assertContains(response, text="Cet UID est invalide")
|
self.assertContains(response, text="Cet UID est invalide")
|
||||||
|
|
||||||
|
# UID too long
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse(
|
||||||
"counter:add_student_card", kwargs={"customer_id": self.sli.customer.pk}
|
"counter:add_student_card", kwargs={"customer_id": self.sli.customer.pk}
|
||||||
@ -325,6 +353,26 @@ class StudentCardTest(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertContains(response, text="Cet UID est invalide")
|
self.assertContains(response, text="Cet UID est invalide")
|
||||||
|
|
||||||
|
# Test with already existing card
|
||||||
|
response = self.client.post(
|
||||||
|
reverse(
|
||||||
|
"counter:add_student_card", kwargs={"customer_id": self.sli.customer.pk}
|
||||||
|
),
|
||||||
|
{"uid": "9A89B82018B0A0"},
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response, text="Un objet Student card avec ce champ Uid existe déjà."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test with lowercase
|
||||||
|
response = self.client.post(
|
||||||
|
reverse(
|
||||||
|
"counter:add_student_card", kwargs={"customer_id": self.sli.customer.pk}
|
||||||
|
),
|
||||||
|
{"uid": "8b90734a802a9f"},
|
||||||
|
)
|
||||||
|
self.assertContains(response, text="Cet UID est invalide")
|
||||||
|
|
||||||
# Test with unauthorized user
|
# Test with unauthorized user
|
||||||
self.client.login(username="krophil", password="plop")
|
self.client.login(username="krophil", password="plop")
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
|
Loading…
Reference in New Issue
Block a user