gestion des dates dans les tests/exemples

This commit is contained in:
Jean-Marie PLACE 2022-10-31 10:12:04 +01:00 committed by iziram
parent d50107079b
commit c85a51a8c5
5 changed files with 98 additions and 79 deletions

View File

@ -10,6 +10,7 @@
Note: les routes /departement[s] sont publiées sur l'API (/ScoDoc/api/), Note: les routes /departement[s] sont publiées sur l'API (/ScoDoc/api/),
mais évidemment pas sur l'API web (/ScoDoc/<dept>/api). mais évidemment pas sur l'API web (/ScoDoc/<dept>/api).
""" """
from datetime import datetime
from flask import jsonify, request from flask import jsonify, request
from flask_login import login_required from flask_login import login_required
@ -256,14 +257,17 @@ def dept_formsemestres_courants(acronym: str):
] ]
""" """
dept = Departement.query.filter_by(acronym=acronym).first_or_404() dept = Departement.query.filter_by(acronym=acronym).first_or_404()
faked_date = request.args.get("faked_date")
if faked_date:
test_date = datetime.fromisoformat(faked_date)
else:
test_date = app.db.func.now()
# Les semestres en cours de ce département # Les semestres en cours de ce département
formsemestres = FormSemestre.query.filter( formsemestres = FormSemestre.query.filter(
FormSemestre.dept_id == dept.id, FormSemestre.dept_id == dept.id,
FormSemestre.date_debut <= app.db.func.now(), FormSemestre.date_debut <= test_date,
FormSemestre.date_fin >= app.db.func.now(), FormSemestre.date_fin >= test_date,
) )
return jsonify([d.to_dict(convert_objects=True) for d in formsemestres]) return jsonify([d.to_dict(convert_objects=True) for d in formsemestres])
@ -277,12 +281,16 @@ def dept_formsemestres_courants_by_id(dept_id: int):
""" """
# Le département, spécifié par un id ou un acronyme # Le département, spécifié par un id ou un acronyme
dept = Departement.query.get_or_404(dept_id) dept = Departement.query.get_or_404(dept_id)
faked_date = request.args.get("faked_date")
if faked_date:
test_date = datetime.fromisoformat(faked_date)
else:
test_date = app.db.func.now()
# Les semestres en cours de ce département # Les semestres en cours de ce département
formsemestres = FormSemestre.query.filter( formsemestres = FormSemestre.query.filter(
FormSemestre.dept_id == dept.id, FormSemestre.dept_id == dept.id,
FormSemestre.date_debut <= app.db.func.now(), FormSemestre.date_debut <= test_date,
FormSemestre.date_fin >= app.db.func.now(), FormSemestre.date_fin >= test_date,
) )
return jsonify([d.to_dict(convert_objects=True) for d in formsemestres]) return jsonify([d.to_dict(convert_objects=True) for d in formsemestres])

View File

@ -7,8 +7,9 @@
""" """
API : accès aux étudiants API : accès aux étudiants
""" """
from datetime import datetime
from flask import g, jsonify from flask import g, jsonify, request
from flask_login import current_user from flask_login import current_user
from flask_login import login_required from flask_login import login_required
from sqlalchemy import desc, or_ from sqlalchemy import desc, or_
@ -75,11 +76,16 @@ def etudiants_courants(long=False):
""" """
allowed_depts = current_user.get_depts_with_permission(Permission.ScoView) allowed_depts = current_user.get_depts_with_permission(Permission.ScoView)
faked_date = request.args.get("faked_date")
if faked_date:
test_date = datetime.fromisoformat(faked_date)
else:
test_date = app.db.func.now()
etuds = Identite.query.filter( etuds = Identite.query.filter(
Identite.id == FormSemestreInscription.etudid, Identite.id == FormSemestreInscription.etudid,
FormSemestreInscription.formsemestre_id == FormSemestre.id, FormSemestreInscription.formsemestre_id == FormSemestre.id,
FormSemestre.date_debut <= app.db.func.now(), FormSemestre.date_debut <= test_date,
FormSemestre.date_fin >= app.db.func.now(), FormSemestre.date_fin >= test_date,
) )
if not None in allowed_depts: if not None in allowed_depts:
# restreint aux départements autorisés: # restreint aux départements autorisés:

View File

@ -90,7 +90,8 @@ class Sample:
HEADERS["Content-Type"] = "application/json ; charset=utf-8" HEADERS["Content-Type"] = "application/json ; charset=utf-8"
self.result = POST_JSON(self.url, json.loads(self.content), HEADERS) self.result = POST_JSON(self.url, json.loads(self.content), HEADERS)
elif self.method[0] != "#": elif self.method[0] != "#":
raise Exception(f"Bad method : {self.method}") error = f'Bad method : "{self.method}"'
raise Exception(error)
self.shorten() self.shorten()
file = open(f"sample_TEST.json.md", "tw") file = open(f"sample_TEST.json.md", "tw")
self.dump(file) self.dump(file)
@ -114,6 +115,8 @@ class Sample:
pp(self.result, indent=4) pp(self.result, indent=4)
def dump(self, file): def dump(self, file):
self.url = self.url.replace("?faked_date=2022-07-20", "")
file.write(f"#### {self.method} {self.url}\n") file.write(f"#### {self.method} {self.url}\n")
if len(self.content) > 0: if len(self.content) > 0:
file.write(f"> `Content-Type: application/json`\n") file.write(f"> `Content-Type: application/json`\n")
@ -193,7 +196,7 @@ def make_samples():
url = line[1] url = line[1]
permission = line[2] if line[2] != "" else "ScoView" permission = line[2] if line[2] != "" else "ScoView"
method = line[3] if line[3] != "" else "GET" method = line[3] if line[3] != "" else "GET"
content = line[4] content = line[4] if len(line) > 4 else ""
samples.add_sample(entry_name, url, method, permission, content) samples.add_sample(entry_name, url, method, permission, content)
samples.dump() samples.dump()
return samples return samples

View File

@ -1,61 +1,62 @@
reference url permission method content reference url permission method content
departements /departements GET departements /departements ScoView GET
departements-ids /departements_ids GET departements-ids /departements_ids ScoView GET
departement /departement/TAPI GET departement /departement/TAPI ScoView GET
departement /departement/id/1 GET departement /departement/id/1 ScoView GET
departement-etudiants /departement/TAPI/etudiants GET departement-etudiants /departement/TAPI/etudiants ScoView GET
departement-etudiants /departement/id/1/etudiants GET departement-etudiants /departement/id/1/etudiants ScoView GET
departement-formsemestres_ids /departement/TAPI/formsemestres_ids GET departement-formsemestres_ids /departement/TAPI/formsemestres_ids ScoView GET
departement-formsemestres_ids /departement/id/1/formsemestres_ids GET departement-formsemestres_ids /departement/id/1/formsemestres_ids ScoView GET
departement-formsemestres-courants /departement/TAPI/formsemestres_courants GET departement-formsemestres-courants /departement/TAPI/formsemestres_courants?faked_date=2022-07-20 ScoView GET
departement-formsemestres-courants /departement/id/1/formsemestres_courants GET departement-formsemestres-courants /departement/id/1/formsemestres_courants?faked_date=2022-07-20 ScoView GET
departement-create /departement/create ScoSuperAdmin POST {"acronym": "NEWONE" , "visible": true} departement-create /departement/create ScoSuperAdmin POST {"acronym": "NEWONE" , "visible": true}
departement-edit /departement/NEWONE/edit ScoSuperAdmin POST {"visible": false} departement-edit /departement/NEWONE/edit ScoSuperAdmin POST {"visible": false}
departement-delete /departement/NEWONE/delete ScoSuperAdmin POST departement-delete /departement/NEWONE/delete ScoSuperAdmin POST
etudiants-courants /etudiants/courants GET etudiants-courants /etudiants/courants?faked_date=2022-07-20 ScoView GET
etudiants-courants /etudiants/courants/long GET etudiants-courants /etudiants/courants/long?faked_date=2022-07-20 ScoView GET
etudiant /etudiant/etudid/11 GET etudiant /etudiant/etudid/11 ScoView GET
etudiant /etudiant/nip/11 GET etudiant /etudiant/nip/11 ScoView GET
etudiant /etudiant/ine/INE11 GET etudiant /etudiant/ine/INE11 ScoView GET
etudiants-clef /etudiants/etudid/11 GET etudiants-clef /etudiants/etudid/11 ScoView GET
etudiants-clef /etudiants/ine/INE11 GET etudiants-clef /etudiants/ine/INE11 ScoView GET
etudiants-clef /etudiants/nip/11 GET etudiants-clef /etudiants/nip/11 ScoView GET
etudiant-formsemestres /etudiant/etudid/11/formsemestres GET etudiant-formsemestres /etudiant/etudid/11/formsemestres ScoView GET
etudiant-formsemestres /etudiant/ine/INE11/formsemestres GET etudiant-formsemestres /etudiant/ine/INE11/formsemestres ScoView GET
etudiant_formsemestres /etudiant/nip/11/formsemestres GET etudiant_formsemestres /etudiant/nip/11/formsemestres ScoView GET
etudiant-formsemestre-bulletin /etudiant/etudid/11/formsemestre/1/bulletin GET etudiant-formsemestre-bulletin /etudiant/etudid/11/formsemestre/1/bulletin ScoView GET
etudiant-formsemestre-bulletin /etudiant/ine/INE11/formsemestre/1/bulletin GET etudiant-formsemestre-bulletin /etudiant/ine/INE11/formsemestre/1/bulletin ScoView GET
etudiant-formsemestre-bulletin /etudiant/nip/11/formsemestre/1/bulletin GET etudiant-formsemestre-bulletin /etudiant/nip/11/formsemestre/1/bulletin ScoView GET
etudiant-formsemestre-bulletin /etudiant/nip/11/formsemestre/1/bulletin/short/pdf GET etudiant-formsemestre-bulletin /etudiant/nip/11/formsemestre/1/bulletin/short/pdf ScoView GET
etudiant-formsemestre-groups /etudiant/etudid/11/formsemestre/1/groups GET etudiant-formsemestre-groups /etudiant/etudid/11/formsemestre/1/groups ScoView GET
formations /formations GET formations /formations ScoView GET
formations_ids /formations_ids GET formations_ids /formations_ids ScoView GET
formation /formation/1 GET formation /formation/1 ScoView GET
formation-export /formation/1/export GET formation-export /formation/1/export ScoView GET
formation-export /formation/1/export_with_ids GET formation-export /formation/1/export_with_ids ScoView GET
formation-referentiel_competences /formation/1/referentiel_competences GET formation-referentiel_competences /formation/1/referentiel_competences ScoView GET
moduleimpl /moduleimpl/1 GET moduleimpl /moduleimpl/1 ScoView GET
formsemestre /formsemestre/1 GET formsemestre /formsemestre/1 ScoView GET
formsemestres-query /formsemestres/query?annee_scolaire=2022&etape_apo=A2 GET formsemestres-query /formsemestres/query?annee_scolaire=2022&etape_apo=A2 ScoView GET
formsemestre-bulletins /formsemestre/1/bulletins GET formsemestres-query /formsemestres/query?nip=11 ScoView GET
formsemestre-programme /formsemestre/1/programme GET formsemestre-bulletins /formsemestre/1/bulletins ScoView GET
formsemestre-etudiants /formsemestre/1/etudiants GET formsemestre-programme /formsemestre/1/programme ScoView GET
formsemestre-etudiants /formsemestre/1/etudiants/long GET formsemestre-etudiants /formsemestre/1/etudiants ScoView GET
formsemestre-etudiants-query /formsemestre/1/etudiants/query?etat=D GET formsemestre-etudiants /formsemestre/1/etudiants/long ScoView GET
formsemestre-etat_evals /formsemestre/1/etat_evals GET formsemestre-etudiants-query /formsemestre/1/etudiants/query?etat=D ScoView GET
formsemestre-resultats /formsemestre/1/resultats GET formsemestre-etat_evals /formsemestre/1/etat_evals ScoView GET
formsemestre-decisions_jury /formsemestre/1/decisions_jury GET formsemestre-resultats /formsemestre/1/resultats ScoView GET
formsemestre-partitions /formsemestre/1/partitions GET formsemestre-decisions_jury /formsemestre/1/decisions_jury ScoView GET
partition /partition/1 GET formsemestre-partitions /formsemestre/1/partitions ScoView GET
group-etudiants /group/1/etudiants GET partition /partition/1 ScoView GET
group-etudiants-query /group/1/etudiants/query?etat=D GET group-etudiants /group/1/etudiants ScoView GET
moduleimpl-evaluations /moduleimpl/1/evaluations GET group-etudiants-query /group/1/etudiants/query?etat=D ScoView GET
evaluation-notes /evaluation/1/notes GET moduleimpl-evaluations /moduleimpl/1/evaluations ScoView GET
user /user/1 GET evaluation-notes /evaluation/1/notes ScoView GET
users-query /users/query?starts_with=u_ GET user /user/1 ScoView GET
permissions /permissions GET users-query /users/query?starts_with=u_ ScoView GET
roles /roles GET permissions /permissions ScoView GET
role /role/Observateur GET roles /roles ScoView GET
role /role/Observateur ScoView GET
group-set_etudiant /group/1/set_etudiant/10 ScoSuperAdmin POST group-set_etudiant /group/1/set_etudiant/10 ScoSuperAdmin POST
group-remove_etudiant /group/1/remove_etudiant/10 ScoSuperAdmin POST group-remove_etudiant /group/1/remove_etudiant/10 ScoSuperAdmin POST
partition-group-create /partition/1/group/create ScoSuperAdmin POST {"group_name": "NEW_GROUP"} partition-group-create /partition/1/group/create ScoSuperAdmin POST {"group_name": "NEW_GROUP"}
@ -84,15 +85,15 @@ departement-logos /departement/TAPI/logos ScoSuperAdmin GET
departement-logos /departement/id/1/logos ScoSuperAdmin GET departement-logos /departement/id/1/logos ScoSuperAdmin GET
departement-logo /departement/TAPI/logo/demo ScoSuperAdmin GET departement-logo /departement/TAPI/logo/demo ScoSuperAdmin GET
departement-logo /departement/id/1/logo/demo ScoSuperAdmin GET departement-logo /departement/id/1/logo/demo ScoSuperAdmin GET
test-pdf /etudiant/nip/11/formsemestre/1/bulletin/pdf GET test-pdf /etudiant/nip/11/formsemestre/1/bulletin/pdf ScoView GET
test-pdf /etudiant/nip/11/formsemestre/1/bulletin/pdf GET test-pdf /etudiant/nip/11/formsemestre/1/bulletin/pdf ScoView GET
test-pdf /etudiant/etudid/11/formsemestre/1/bulletin/short/pdf GET test-pdf /etudiant/etudid/11/formsemestre/1/bulletin/short/pdf ScoView GET
test-pdf /etudiant/ine/INE11/formsemestre/1/bulletin/short/pdf GET test-pdf /etudiant/ine/INE11/formsemestre/1/bulletin/short/pdf ScoView GET
test-pdf /etudiant/nip/11/formsemestre/1/bulletin/short/pdf GET test-pdf /etudiant/nip/11/formsemestre/1/bulletin/short/pdf ScoView GET
test-pdf /etudiant/etudid/11/formsemestre/1/bulletin/pdf GET test-pdf /etudiant/etudid/11/formsemestre/1/bulletin/pdf ScoView GET
test-pdf /etudiant/etudid/11/formsemestre/1/bulletin/short GET test-pdf /etudiant/etudid/11/formsemestre/1/bulletin/short ScoView GET
test-pdf /etudiant/ine/INE11/formsemestre/1/bulletin/short GET test-pdf /etudiant/ine/INE11/formsemestre/1/bulletin/short ScoView GET
test-pdf /etudiant/nip/11/formsemestre/1/bulletin/short GET test-pdf /etudiant/nip/11/formsemestre/1/bulletin/short ScoView GET
test-pdf /etudiant/etudid/11/formsemestre/1/bulletin GET test-pdf /etudiant/etudid/11/formsemestre/1/bulletin ScoView GET
test-pdf /etudiant/ine/INE11/formsemestre/1/bulletin GET test-pdf /etudiant/ine/INE11/formsemestre/1/bulletin ScoView GET
test-pdf /etudiant/nip/11/formsemestre/1/bulletin GET test-pdf /etudiant/nip/11/formsemestre/1/bulletin ScoView GET

Can't render this file because it contains an unexpected character in line 12 and column 60.

View File

@ -163,6 +163,7 @@ def create_fake_etud(dept: Departement) -> Identite:
# créé un étudiant sur deux avec un NIP et INE alphanumérique # créé un étudiant sur deux avec un NIP et INE alphanumérique
etud.code_nip = f"{etud.id}" if (etud.id % 2) else f"NIP{etud.id}" etud.code_nip = f"{etud.id}" if (etud.id % 2) else f"NIP{etud.id}"
etud.code_ine = f"INE{etud.id}" if (etud.id % 2) else f"{etud.id}" etud.code_ine = f"INE{etud.id}" if (etud.id % 2) else f"{etud.id}"
etud.date_naissance = datetime.date(2005, 2, 1) + datetime.timedelta(days=etud.id)
db.session.add(etud) db.session.add(etud)
db.session.commit() db.session.commit()
adresse = models.Adresse( adresse = models.Adresse(
@ -238,7 +239,7 @@ def create_evaluations(formsemestre: FormSemestre):
for modimpl in formsemestre.modimpls: for modimpl in formsemestre.modimpls:
args = { args = {
"moduleimpl_id": modimpl.id, "moduleimpl_id": modimpl.id,
"jour": None, "jour": datetime.date(2022, 3, 1) + datetime.timedelta(days=modimpl.id),
"heure_debut": "8h00", "heure_debut": "8h00",
"heure_fin": "9h00", "heure_fin": "9h00",
"description": None, "description": None,