From 80578af8fa5f22de16706027cb007aa71384b7ac Mon Sep 17 00:00:00 2001 From: amandine-sahl Date: Thu, 5 Dec 2024 10:53:13 +0100 Subject: [PATCH] Ajout route t_medias --- apptax/taxonomie/routestmedias.py | 17 +++++++++++++++-- apptax/tests/test_media.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apptax/taxonomie/routestmedias.py b/apptax/taxonomie/routestmedias.py index 2856444a7..9cd9b11c9 100644 --- a/apptax/taxonomie/routestmedias.py +++ b/apptax/taxonomie/routestmedias.py @@ -5,8 +5,8 @@ from flask import json, Blueprint, request, current_app, send_file, abort -from .models import TMedias -from .schemas import TMediasSchema +from .models import TMedias, BibTypesMedia +from .schemas import TMediasSchema, BibTypesMediaSchema from .filemanager import FILEMANAGER @@ -29,6 +29,19 @@ def get_tmedias(id=None): return TMediasSchema().dump(medias, many=True) +@adresses.route("/type", methods=["GET"]) +@adresses.route("/type/", methods=["GET"]) +def get_type_tmedias(id=None): + """ + Liste des types de médias + """ + if id: + type_media = BibTypesMedia.query.get(id) + return BibTypesMediaSchema().dump(type_media) + types_media = BibTypesMedia.query.all() + return BibTypesMediaSchema().dump(types_media, many=True) + + @adresses.route("/bycdref/", methods=["GET"]) def get_tmediasbyTaxon(cd_ref): """ diff --git a/apptax/tests/test_media.py b/apptax/tests/test_media.py index d62b788c9..69fb287a7 100644 --- a/apptax/tests/test_media.py +++ b/apptax/tests/test_media.py @@ -15,6 +15,7 @@ AppUser, ) from pypnusershub.tests.utils import set_logged_user_cookie +from schema import Schema, Optional, Or from .fixtures import noms_example, attribut_example, liste @@ -40,6 +41,21 @@ def user(): @pytest.mark.usefixtures("client_class", "temporary_transaction") class TestAPIMedia: + + type_media_schema = Schema( + [{"desc_type_media": Or(None, str), "id_type": int, "nom_type_media": str}] + ) + + def test_get_type_tmedias(self): + response = self.client.get(url_for("t_media.get_type_tmedias")) + assert response.status_code == 200 + assert self.type_media_schema.is_valid(response.json) + + def test_get_type_tmedias_one(self): + response = self.client.get(url_for("t_media.get_type_tmedias", id=1)) + assert response.status_code == 200 + assert response.json["nom_type_media"] == "Photo_principale" + def test_get_tmediasbyTaxon(self, noms_example): response = self.client.get(url_for("t_media.get_tmediasbyTaxon", cd_ref=67111)) assert response.status_code == 200