Skip to content

Commit

Permalink
extend test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Dec 20, 2024
1 parent 31f698e commit c46bdab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
10 changes: 8 additions & 2 deletions apptax/taxonomie/routestmedias.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import os
from flask import json, Blueprint, request, current_app, send_file, abort
from werkzeug.exceptions import Forbidden


from .models import TMedias, BibTypesMedia
Expand Down Expand Up @@ -91,10 +92,15 @@ def getThumbnail_tmedias(id_media):
height_params: str = params.get("h", None)
width_params: str = params.get("w", None)

if width_params and width_params.isdigit():
if (width_params and not width_params.isdigit()) or (
height_params and not height_params.isdigit()
):
raise Forbidden("Valeur de la hauteur ou largeur incorrecte: Un entier est attendu")

if width_params:
size = (int(width_params), size[1])

if height_params and height_params.isdigit():
if height_params:
size = (size[0], int(height_params))

force = False
Expand Down
37 changes: 17 additions & 20 deletions apptax/tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from apptax.taxonomie.models import BibTypesMedia, TMedias
import pytest
from flask import url_for, current_app
from flask import url_for, current_app, Response

from apptax.database import db

Expand Down Expand Up @@ -133,25 +133,22 @@ def test_get_tmedias(self):
# id_media = json.loads(response.data)["id_media"]
# self.get_thumbnail(id_media)

def test_get_thumbnail(self, media):
@pytest.mark.parametrize(
"get_params,expected_status_code",
[
({}, 200),
(dict(w=100), 200),
(dict(h=100), 200),
(dict(w=100, h=100), 200),
(dict(w="a", h="b"), 403),
(dict(h="b"), 403),
],
)
def test_get_thumbnail(self, media, get_params, expected_status_code):
id_media = media.id_media

response = self.client.get(
url_for("t_media.getThumbnail_tmedias", id_media=id_media),
)
assert response.status_code == 200

response = self.client.get(
url_for("t_media.getThumbnail_tmedias", id_media=id_media, w=200, h=200),
response: Response = self.client.get(
url_for("t_media.getThumbnail_tmedias", id_media=id_media, **get_params),
)
assert response.status_code == 200

response = self.client.get(
url_for("t_media.getThumbnail_tmedias", id_media=id_media, w=200),
)
assert response.status_code == 200

response = self.client.get(
url_for("t_media.getThumbnail_tmedias", id_media=id_media, h=200),
)
assert response.status_code == 200
print(response.headers)
assert response.status_code == expected_status_code

0 comments on commit c46bdab

Please sign in to comment.