init
This commit is contained in:
75
backend-django/backend/tests/pam/__init__.py
Normal file
75
backend-django/backend/tests/pam/__init__.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
import pandas as pd
|
||||
from rest_framework.test import APIClient, APITestCase
|
||||
from ...utils_extraction import to_table_pam
|
||||
|
||||
from ...models import (Administre, CustomUser, Decision, DecisionChoices,
|
||||
Domaine, Filiere, FormationEmploi, Garnison, Poste,
|
||||
RefGest, RefOrg, RefSvFil, SousVivier, Administres_Pams, Postes_Pams, PAM)
|
||||
|
||||
import datetime
|
||||
|
||||
|
||||
|
||||
class PamTestCase(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.date = datetime.date(2023,1,1)
|
||||
cls.pam_2022 = PAM.objects.create(pam_id='2022',pam_date=datetime.date(2022,7,15), pam_libelle= "PAM de l'année 2022", pam_statut='PAM en cours')
|
||||
cls.pam_2023 = PAM.objects.create(pam_id='2023',pam_date=datetime.date(2022,7,15), pam_libelle= "PAM de l'année 2023", pam_statut='PAM A+1')
|
||||
|
||||
|
||||
def test_extraction_pam(self):
|
||||
"""
|
||||
Construit la table PAM qui servira à récuperer l'année du PAM et piloter l'affichage des données en fonction du bon pam pour chaque tables
|
||||
Cloture le PAM en le sauvegardant dans un fichier excel
|
||||
"""
|
||||
annee_pam = str(self.date.year)
|
||||
annee_pam_suivant = str(self.date.year + 1)
|
||||
|
||||
pam=pd.DataFrame(columns = ['pam_id','pam_date', 'pam_libelle','pam_statut'])
|
||||
pam_id = annee_pam
|
||||
pam_id_suivant = annee_pam_suivant
|
||||
pam_libelle = f"PAM de l'année {annee_pam}"
|
||||
pam_libelle_suivant = f"PAM de l'année {annee_pam_suivant}"
|
||||
pam_date = self.date
|
||||
pam_date_suivant = pam_date
|
||||
pam_statut = "PAM en cours"
|
||||
pam_statut_suivant = "PAM A+1"
|
||||
|
||||
sorg_id = "SORG"
|
||||
sorg_libelle = "SORG"
|
||||
sorg_statut = "SORG"
|
||||
|
||||
pam['pam_id'] = [pam_id,pam_id_suivant, sorg_id]
|
||||
pam['pam_date'] = [pam_date,pam_date_suivant, pam_date]
|
||||
pam['pam_libelle'] = [pam_libelle,pam_libelle_suivant,sorg_libelle]
|
||||
pam['pam_statut'] = [pam_statut,pam_statut_suivant,sorg_statut]
|
||||
|
||||
return pam
|
||||
|
||||
|
||||
def test_insertion_pam(self):
|
||||
self.liste_create = []
|
||||
self.liste_update = []
|
||||
self.update_header = ['pam_date','pam_libelle','pam_statut']
|
||||
self.df = self.test_extraction_pam()
|
||||
for i in range(self.df.shape[0]):
|
||||
self.pams = PAM.objects.filter(pam_id=self.df.at[i,'pam_id'])
|
||||
self.pam = PAM(pam_id=self.df.at[i, 'pam_id'],pam_date=self.df.at[i, 'pam_date'], pam_libelle=self.df.at[i, 'pam_libelle'],
|
||||
pam_statut=self.df.at[i, 'pam_statut'])
|
||||
|
||||
if self.pam.pam_id in self.pams.values_list('pam_id', flat = True):
|
||||
self.liste_update.append(self.pam)
|
||||
else:
|
||||
cloture=PAM.objects.filter(pam_statut="PAM en cours")
|
||||
cloture.update(pam_statut ="PAM clôturé")
|
||||
self.liste_create.append(self.pam)
|
||||
|
||||
if self.liste_create:
|
||||
PAM.objects.bulk_create(self.liste_create)
|
||||
if self.liste_update:
|
||||
PAM.objects.bulk_update(self.liste_update, fields=self.update_header)
|
||||
Reference in New Issue
Block a user