Adaptation des tests unitaires aux vues de l'API (qui renvoient des réponses Flask).

This commit is contained in:
Emmanuel Viennet 2021-09-21 16:34:58 +02:00
parent 2999199b19
commit 6cc1b60da4
2 changed files with 19 additions and 11 deletions

View File

@ -246,8 +246,10 @@ def test_abs_basic(test_client):
liste_abs = sco_abs_views.ListeAbsEtud( liste_abs = sco_abs_views.ListeAbsEtud(
etudid, format="json", absjust_only=1, sco_year="2020" etudid, format="json", absjust_only=1, sco_year="2020"
) ).get_data(as_text=True)
liste_abs2 = sco_abs_views.ListeAbsEtud(etudid, format="json", sco_year="2020") liste_abs2 = sco_abs_views.ListeAbsEtud(
etudid, format="json", sco_year="2020"
).get_data(as_text=True)
load_liste_abs = json.loads(liste_abs) load_liste_abs = json.loads(liste_abs)
load_liste_abs2 = json.loads(liste_abs2) load_liste_abs2 = json.loads(liste_abs2)
@ -283,7 +285,7 @@ def test_abs_basic(test_client):
format="json", format="json",
) )
# grp1_abs est une Response car on a appelé une vue (1er appel) # grp1_abs est une Response car on a appelé une vue (1er appel)
load_grp1_abs = json.loads(grp1_abs.get_data().decode("utf-8")) load_grp1_abs = json.loads(grp1_abs.get_data(as_text=True))
assert len(load_grp1_abs) == 10 assert len(load_grp1_abs) == 10
@ -327,7 +329,9 @@ def test_abs_basic(test_client):
code_ine=etuds[0]["code_ine"], code_ine=etuds[0]["code_ine"],
) )
li_bi = absences.listeBilletsEtud(etudid=etudid, format="json") li_bi = absences.listeBilletsEtud(etudid=etudid, format="json").get_data(
as_text=True
)
assert isinstance(li_bi, str) assert isinstance(li_bi, str)
load_li_bi = json.loads(li_bi) load_li_bi = json.loads(li_bi)

View File

@ -172,7 +172,7 @@ def test_formations(test_client):
assert load_lif[0]["formation_id"] == f["formation_id"] assert load_lif[0]["formation_id"] == f["formation_id"]
assert load_lif[0]["titre"] == f["titre"] assert load_lif[0]["titre"] == f["titre"]
lif2 = notes.formation_list(format="json") lif2 = notes.formation_list(format="json").get_data(as_text=True)
# lif2 est un chaine # lif2 est un chaine
assert isinstance(lif2, str) assert isinstance(lif2, str)
load_lif2 = json.loads(lif2) load_lif2 = json.loads(lif2)
@ -182,7 +182,9 @@ def test_formations(test_client):
# --- Export de formation_id # --- Export de formation_id
exp = sco_formations.formation_export(formation_id=f["formation_id"], format="json") exp = sco_formations.formation_export(
formation_id=f["formation_id"], format="json"
).get_data(as_text=True)
assert isinstance(exp, str) assert isinstance(exp, str)
load_exp = json.loads(exp) load_exp = json.loads(exp)
@ -200,7 +202,7 @@ def test_formations(test_client):
li_sem1 = notes.formsemestre_list( li_sem1 = notes.formsemestre_list(
formsemestre_id=sem1["formsemestre_id"], format="json" formsemestre_id=sem1["formsemestre_id"], format="json"
) ).get_data(as_text=True)
assert isinstance(li_sem1, str) assert isinstance(li_sem1, str)
load_li_sem1 = json.loads(li_sem1) # uniquement le semestre 1 dans la liste load_li_sem1 = json.loads(li_sem1) # uniquement le semestre 1 dans la liste
@ -212,7 +214,7 @@ def test_formations(test_client):
li_semf = notes.formsemestre_list( li_semf = notes.formsemestre_list(
formation_id=f["formation_id"], formation_id=f["formation_id"],
format="json", format="json",
) ).get_data(as_text=True)
assert isinstance(li_semf, str) assert isinstance(li_semf, str)
load_li_semf = json.loads(li_semf) load_li_semf = json.loads(li_semf)
@ -220,7 +222,7 @@ def test_formations(test_client):
assert len(load_li_semf) == 2 assert len(load_li_semf) == 2
assert load_li_semf[1]["semestre_id"] == sem2["semestre_id"] assert load_li_semf[1]["semestre_id"] == sem2["semestre_id"]
li_sem = notes.formsemestre_list(format="json") li_sem = notes.formsemestre_list(format="json").get_data(as_text=True)
load_li_sem = json.loads(li_sem) load_li_sem = json.loads(li_sem)
assert len(load_li_sem) == 3 assert len(load_li_sem) == 3
@ -328,7 +330,7 @@ def test_formations(test_client):
) )
sco_edit_formation.do_formation_delete(oid=f2["formation_id"]) sco_edit_formation.do_formation_delete(oid=f2["formation_id"])
lif3 = notes.formation_list(format="json") lif3 = notes.formation_list(format="json").get_data(as_text=True)
assert isinstance(lif3, str) assert isinstance(lif3, str)
load_lif3 = json.loads(lif3) load_lif3 = json.loads(lif3)
assert len(load_lif3) == 1 assert len(load_lif3) == 1
@ -371,5 +373,7 @@ def test_import_formation(test_client):
assert mi["module_id"] == mod["module_id"] assert mi["module_id"] == mod["module_id"]
# --- Export formation en XML # --- Export formation en XML
doc1 = sco_formations.formation_export(formation_id, format="xml") doc1 = sco_formations.formation_export(formation_id, format="xml").get_data(
as_text=True
)
assert isinstance(doc1, str) assert isinstance(doc1, str)