init
This commit is contained in:
3
backend-django/backend/tests/models/__init__.py
Normal file
3
backend-django/backend/tests/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .administre import *
|
||||
from .calcul import *
|
||||
from .poste import *
|
||||
39
backend-django/backend/tests/models/administre.py
Normal file
39
backend-django/backend/tests/models/administre.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from ...models import Administre, StatutPamChoices
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase
|
||||
|
||||
class AdministreTestCase(TestCase):
|
||||
|
||||
def test_attributes_statut_pam(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 StatutPamChoices:
|
||||
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_statut_pam(self):
|
||||
""" vérifie qu'il n'est pas possible de stocker n'importe quoi en base """
|
||||
|
||||
valides = StatutPamChoices.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()
|
||||
|
||||
id_sap = 1
|
||||
|
||||
# valide : création OK
|
||||
for valide in valides:
|
||||
Administre.objects.create(pk=id_sap, a_statut_pam=valide)
|
||||
id_sap = id_sap + 1
|
||||
|
||||
# invalide : création KO
|
||||
with self.assertRaises(IntegrityError):
|
||||
Administre.objects.create(pk=id_sap, a_statut_pam=invalide)
|
||||
34
backend-django/backend/tests/models/calcul.py
Normal file
34
backend-django/backend/tests/models/calcul.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from ...models.calcul import Calcul, SousVivier
|
||||
from ...models.calcul import StatutCalculChoices as StatutCalcul
|
||||
|
||||
|
||||
class CalculTestCase(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
for i in range(1, 15):
|
||||
SousVivier.objects.create(pk=str(i))
|
||||
|
||||
def test_constraint_statut(self):
|
||||
valides = StatutCalcul.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()
|
||||
|
||||
i = 1
|
||||
|
||||
# valide : création OK
|
||||
for valide in valides:
|
||||
Calcul.objects.create(pk=str(i), ca_date_debut=timezone.now(), ca_statut=valide, ca_statut_pourcentage=0)
|
||||
i = i + 1
|
||||
|
||||
# invalide : création KO
|
||||
with self.assertRaises(IntegrityError):
|
||||
Calcul.objects.create(pk=str(i), ca_date_debut=timezone.now(), ca_statut=invalide, ca_statut_pourcentage=0)
|
||||
34
backend-django/backend/tests/models/poste.py
Normal file
34
backend-django/backend/tests/models/poste.py
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user