Skip to content

Commit

Permalink
Ajout route t_medias
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Dec 5, 2024
1 parent a78dd8d commit 80578af
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apptax/taxonomie/routestmedias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,6 +29,19 @@ def get_tmedias(id=None):
return TMediasSchema().dump(medias, many=True)


@adresses.route("/type", methods=["GET"])
@adresses.route("/type/<int:id>", 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/<cd_ref>", methods=["GET"])
def get_tmediasbyTaxon(cd_ref):
"""
Expand Down
16 changes: 16 additions & 0 deletions apptax/tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 80578af

Please sign in to comment.