From f9fa4753a254d0a7ca7fbea7e3afa55bb68b3696 Mon Sep 17 00:00:00 2001 From: iziram Date: Tue, 11 Jul 2023 11:35:50 +0200 Subject: [PATCH] =?UTF-8?q?Assiduit=C3=A9s=20:=20Bug=20Fix=20justifs/list?= =?UTF-8?q?=20+=20Tests=20OK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/assiduites.py | 5 +++-- app/scodoc/sco_archives_justificatifs.py | 7 ++++--- tests/api/test_api_justificatifs.py | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/models/assiduites.py b/app/models/assiduites.py index 15018a8e..f343016a 100644 --- a/app/models/assiduites.py +++ b/app/models/assiduites.py @@ -72,7 +72,8 @@ class Assiduite(db.Model): if format_api: etat = EtatAssiduite.inverse().get(self.etat).name if self.user_id is not None: - user: User = User.query.get(self.user_id) + user: User = db.session.get(User, self.user_id) + if user is None: username = "Non renseigné" else: @@ -224,7 +225,7 @@ class Justificatif(db.Model): if format_api: etat = EtatJustificatif.inverse().get(self.etat).name if self.user_id is not None: - user: User = User.query.get(self.user_id) + user: User = db.session.get(User, self.user_id) if user is None: username = "Non renseigné" else: diff --git a/app/scodoc/sco_archives_justificatifs.py b/app/scodoc/sco_archives_justificatifs.py index a121ded8..0030d203 100644 --- a/app/scodoc/sco_archives_justificatifs.py +++ b/app/scodoc/sco_archives_justificatifs.py @@ -65,12 +65,12 @@ class Trace: file.write("\n".join(lines)) def get_trace( - self, fnames: list[str] = () + self, fnames: list[str] = None ) -> dict[str, list[datetime, datetime, str]]: """Récupère la trace pour les noms de fichiers. si aucun nom n'est donné, récupère tous les fichiers""" - if fnames is None or len(fnames) == 0: + if fnames is None: return self.content traced: dict = {} @@ -187,8 +187,9 @@ class JustificatifArchiver(BaseArchiver): filenames = self.list_archive(archive_id) trace: Trace = Trace(self.get_obj_dir(etudid)) traced = trace.get_trace(filenames) + retour = [(key, value[2]) for key, value in traced.items()] - return [(key, value[2]) for key, value in traced.items()] + return retour def get_justificatif_file(self, archive_name: str, etudid: int, filename: str): """ diff --git a/tests/api/test_api_justificatifs.py b/tests/api/test_api_justificatifs.py index a08ad9da..68f65792 100644 --- a/tests/api/test_api_justificatifs.py +++ b/tests/api/test_api_justificatifs.py @@ -376,13 +376,15 @@ def test_list_justificatifs(api_admin_headers): res: list = GET("/justificatif/1/list", api_admin_headers) - assert isinstance(res, list) - assert len(res) == 2 + assert isinstance(res, dict) + assert len(res["filenames"]) == 2 + assert res["total"] == 2 res: list = GET("/justificatif/2/list", api_admin_headers) - assert isinstance(res, list) - assert len(res) == 0 + assert isinstance(res, dict) + assert len(res["filenames"]) == 0 + assert res["total"] == 0 # Mauvais fonctionnement @@ -439,7 +441,9 @@ def test_remove_justificatif(api_admin_headers): "/justificatif/1/remove", {"remove": "all"}, api_admin_headers ) assert res == {"response": "removed"} - assert len(GET("/justificatif/1/list", api_admin_headers)) == 0 + l = GET("/justificatif/1/list", api_admin_headers) + assert isinstance(l, dict) + assert l["total"] == 0 res: dict = POST_JSON( "/justificatif/2/remove", @@ -447,7 +451,9 @@ def test_remove_justificatif(api_admin_headers): api_admin_headers, ) assert res == {"response": "removed"} - assert len(GET("/justificatif/2/list", api_admin_headers)) == 1 + l = GET("/justificatif/2/list", api_admin_headers) + assert isinstance(l, dict) + assert l["total"] == 1 res: dict = POST_JSON( "/justificatif/2/remove", @@ -455,7 +461,9 @@ def test_remove_justificatif(api_admin_headers): api_admin_headers, ) assert res == {"response": "removed"} - assert len(GET("/justificatif/2/list", api_admin_headers)) == 0 + l = GET("/justificatif/2/list", api_admin_headers) + assert isinstance(l, dict) + assert l["total"] == 0 # Mauvais fonctionnement