2021-12-24 06:08:35 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""Exemple utilisation API ScoDoc 9 avec jeton obtenu par basic authentication
|
|
|
|
|
|
|
|
utilisation:
|
2022-05-04 23:11:20 +02:00
|
|
|
à faire fonctionner en environnment de test (FLASK_ENV=test_api dans le fichier .env)
|
2021-12-24 06:08:35 +01:00
|
|
|
pytest tests/api/test_api_logos.py
|
|
|
|
"""
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
|
|
|
|
# XXX TODO
|
|
|
|
# Ce test a une logique très différente des autres : A UNIFIER
|
|
|
|
|
2022-12-07 13:22:11 +01:00
|
|
|
import requests
|
2023-04-06 10:38:31 +02:00
|
|
|
|
|
|
|
from app.scodoc import sco_utils as scu
|
|
|
|
from scodoc import app
|
2022-12-07 13:22:11 +01:00
|
|
|
from tests.api.setup_test_api import (
|
|
|
|
API_URL,
|
|
|
|
api_admin_headers,
|
|
|
|
api_headers,
|
|
|
|
CHECK_CERTIFICATE,
|
|
|
|
)
|
2021-12-24 06:08:35 +01:00
|
|
|
|
|
|
|
from tests.unit.config_test_logos import (
|
|
|
|
create_super_token,
|
|
|
|
create_admin_token,
|
|
|
|
create_lambda_token,
|
|
|
|
create_logos,
|
|
|
|
create_dept,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-08-21 09:17:45 +02:00
|
|
|
def test_super_access(api_admin_headers):
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2022-07-29 16:19:40 +02:00
|
|
|
Route: /logos
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/logos",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.json() is not None
|
2021-12-24 06:08:35 +01:00
|
|
|
|
|
|
|
|
2022-08-21 09:17:45 +02:00
|
|
|
def test_lambda_access(api_headers):
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2022-08-21 09:17:45 +02:00
|
|
|
Route: /logos
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/logos",
|
|
|
|
headers=api_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 401
|
2021-12-24 06:08:35 +01:00
|
|
|
|
|
|
|
|
2023-08-11 23:15:17 +02:00
|
|
|
# XXX A REVOIR
|
2022-08-21 09:17:45 +02:00
|
|
|
def test_global_logos(api_admin_headers):
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
|
|
|
Route:
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/logos",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.json() is not None
|
|
|
|
assert "header" in response.json()
|
2023-08-11 23:15:17 +02:00
|
|
|
# assert "footer" in response.json() # XXX ??? absent
|
2022-12-07 13:22:11 +01:00
|
|
|
assert "B" in response.json()
|
|
|
|
assert "C" in response.json()
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_by_id_logos(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Route: /departement/id/1/logos
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/departement/id/1/logos",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.json() is not None
|
|
|
|
assert "A" in response.json()
|
|
|
|
assert "D" in response.json()
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_by_name_logos(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Route: /departement/TAPI/logos
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/departement/TAPI/logos",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.json() is not None
|
|
|
|
assert "A" in response.json()
|
|
|
|
assert "D" in response.json()
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_png_by_id_logo(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Route: /departement/id/1/logo/D
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/departement/id/1/logo/D",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["Content-Type"] == "image/png"
|
|
|
|
assert response.headers["Content-Disposition"].startswith("inline")
|
|
|
|
assert "logo_D.png" in response.headers["Content-Disposition"]
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_global_png_logo(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Route: /logo/C
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/logo/C",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["Content-Type"] == "image/png"
|
|
|
|
assert response.headers["Content-Disposition"].startswith("inline")
|
|
|
|
assert "logo_C.png" in response.headers["Content-Disposition"]
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_global_jpg_logo(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Route: /logo/B
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/logo/B",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["Content-Type"] == "image/jpg"
|
|
|
|
assert response.headers["Content-Disposition"].startswith("inline")
|
|
|
|
assert "logo_B.jpg" in response.headers["Content-Disposition"]
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_png_by_name_logo(api_admin_headers):
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
Route: /departement/TAPI/logo/D
|
2022-08-21 09:17:45 +02:00
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/departement/TAPI/logo/D",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["Content-Type"] == "image/png"
|
|
|
|
assert response.headers["Content-Disposition"].startswith("inline")
|
|
|
|
assert "logo_D.png" in response.headers["Content-Disposition"]
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_jpg_by_id_logo(api_admin_headers):
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
Route: /departement/id/1/logo/A
|
2022-08-21 09:17:45 +02:00
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/departement/id/1/logo/A",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["Content-Type"] == "image/jpg"
|
|
|
|
assert response.headers["Content-Disposition"].startswith("inline")
|
|
|
|
assert "logo_A.jpg" in response.headers["Content-Disposition"]
|
2022-08-21 09:17:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_local_jpg_by_name_logo(api_admin_headers):
|
|
|
|
"""
|
|
|
|
Route: /departement/TAPI/logo/A
|
|
|
|
"""
|
2022-12-07 13:22:11 +01:00
|
|
|
response = requests.get(
|
|
|
|
API_URL + "/departement/TAPI/logo/A",
|
|
|
|
headers=api_admin_headers,
|
|
|
|
verify=CHECK_CERTIFICATE,
|
2023-04-06 10:38:31 +02:00
|
|
|
timeout=scu.SCO_TEST_API_TIMEOUT,
|
2022-12-07 13:22:11 +01:00
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["Content-Type"] == "image/jpg"
|
|
|
|
assert response.headers["Content-Disposition"].startswith("inline")
|
|
|
|
assert "logo_A.jpg" in response.headers["Content-Disposition"]
|