From 26454de0c4c58c707d9c916b6d7c8eb0849219a9 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 25 Jul 2022 06:53:35 +0200 Subject: [PATCH] API: Fix /api/group/edit --- app/api/auth.py | 3 ++- app/api/partitions.py | 2 +- app/models/groups.py | 4 +--- tests/api/exemple-api-basic.py | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/api/auth.py b/app/api/auth.py index cae9957d..8662312a 100644 --- a/app/api/auth.py +++ b/app/api/auth.py @@ -62,7 +62,8 @@ def verify_token(token) -> User: """ user = User.check_token(token) if token else None - flask_login.login_user(user) + if user is not None: + flask_login.login_user(user) g.current_user = user return user diff --git a/app/api/partitions.py b/app/api/partitions.py index fd94ab96..a287aa96 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -71,7 +71,7 @@ def formsemestre_partitions(formsemestre_id: int): """ formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id) - partitions = sorted(formsemestre.partitions, key=lambda p: p.numero) + partitions = sorted(formsemestre.partitions, key=lambda p: p.numero or 0) return jsonify( { partition.id: partition.to_dict(with_groups=True) diff --git a/app/models/groups.py b/app/models/groups.py index fe5d1041..7c87d442 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -136,9 +136,7 @@ class GroupDescr(db.Model): "numero": self.numero, } if with_partition: - d["partition"] = sorted( - self.partition, key=lambda p: p.numero or 0 - ).to_dict(with_groups=False) + d["partition"] = self.partition.to_dict(with_groups=False) return d @classmethod diff --git a/tests/api/exemple-api-basic.py b/tests/api/exemple-api-basic.py index f43ce833..9d03946b 100644 --- a/tests/api/exemple-api-basic.py +++ b/tests/api/exemple-api-basic.py @@ -59,7 +59,7 @@ def GET(path: str, headers={}, errmsg=None): """Get and returns as JSON""" r = requests.get(API_URL + path, headers=headers or HEADERS, verify=CHK_CERT) if r.status_code != 200: - raise ScoError(errmsg or f"erreur status={r.status_code} !") + raise ScoError(errmsg or f"""erreur status={r.status_code} !\n{r.json()}""") return r.json() # decode la reponse JSON @@ -72,7 +72,7 @@ def POST(path: str, data: dict = {}, headers={}, errmsg=None): verify=CHK_CERT, ) if r.status_code != 200: - raise ScoError(errmsg or f"erreur status={r.status_code} !") + raise ScoError(errmsg or f"erreur status={r.status_code} !\n{r.json()}") return r.json() # decode la reponse JSON @@ -85,7 +85,7 @@ def POST_JSON(path: str, data: dict = {}, headers={}, errmsg=None): verify=CHK_CERT, ) if r.status_code != 200: - raise ScoError(errmsg or f"erreur status={r.status_code} !") + raise ScoError(errmsg or f"erreur status={r.status_code} !\n{r.json()}") return r.json() # decode la reponse JSON