35 lines
1.6 KiB
Python
35 lines
1.6 KiB
Python
from ...models import AvisPosteChoices as AvisPoste, Poste, PropositionsArmementChoices as PropositionsArmement
|
|
from django.db.utils import IntegrityError
|
|
from django.test import TestCase
|
|
|
|
class PosteTestCase(TestCase):
|
|
|
|
def test_attributes_avis(self):
|
|
""" vérifie que le comportement reste correct avec l'ajout de nouveaux attributs """
|
|
|
|
attr_calc = 'calc_enabled'
|
|
attr_dec = 'dec_enabled'
|
|
for choice in AvisPoste:
|
|
self.assertIsInstance(choice.label, str, f"{choice} : le libellé n'a pas le bon type")
|
|
self.assertIsInstance(choice.value, str, f"{choice} : la valeur n'a pas le bon type")
|
|
self.assertEqual(choice.value, choice, f"{choice} : n'est pas égal à sa valeur")
|
|
self.assertIsInstance(getattr(choice, attr_calc), bool, f"{choice} : l'attribut {attr_calc} n'a pas le bon type")
|
|
self.assertIsInstance(getattr(choice, attr_dec), bool, f"{choice} : l'attribut {attr_dec} n'a pas le bon type")
|
|
|
|
def test_constraint_propositions_armement(self):
|
|
valides = PropositionsArmement.values
|
|
invalide = 'autre'
|
|
|
|
def given():
|
|
self.assertTrue(valides, 'il devrait exister des choix valides')
|
|
self.assertNotIn(invalide, valides, 'le test nécessite une valeur invalide')
|
|
given()
|
|
|
|
# valide : création OK
|
|
for valide in valides:
|
|
Poste.objects.create(pk=valide, propositions_armement=valide)
|
|
|
|
# invalide : création KO
|
|
with self.assertRaises(IntegrityError):
|
|
Poste.objects.create(pk=invalide, propositions_armement=invalide)
|