74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Exemple utilisation API ScoDoc 9 avec jeton obtenu par basic authentication
|
|
|
|
utilisation:
|
|
à faire fonctionner en environnment de test (FLASK_ENV=test_api dans le fichier .env)
|
|
pytest tests/api/test_api_logos.py
|
|
"""
|
|
|
|
|
|
# XXX TODO
|
|
# Ce test a une logique très différente des autres : A UNIFIER
|
|
|
|
|
|
from tests.api.setup_test_api import API_URL
|
|
|
|
from scodoc import app
|
|
from tests.unit.config_test_logos import (
|
|
create_super_token,
|
|
create_admin_token,
|
|
create_lambda_token,
|
|
create_logos,
|
|
create_dept,
|
|
)
|
|
|
|
|
|
def test_super_access(create_super_token):
|
|
"""
|
|
Route: /logos
|
|
"""
|
|
dept1, dept2, dept3, token = create_super_token
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
with app.test_client() as client:
|
|
response = client.get(API_URL + "/logos", headers=headers)
|
|
assert response.status_code == 200
|
|
assert response.json is not None
|
|
|
|
|
|
def test_admin_access(create_admin_token):
|
|
"""
|
|
Route:
|
|
"""
|
|
dept1, dept2, dept3, token = create_admin_token
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
with app.test_client() as client:
|
|
response = client.get(API_URL + "/logos", headers=headers)
|
|
assert response.status_code == 403
|
|
|
|
|
|
def test_lambda_access(create_lambda_token):
|
|
"""
|
|
Route:
|
|
"""
|
|
dept1, dept2, dept3, token = create_lambda_token
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
with app.test_client() as client:
|
|
response = client.get(API_URL + "/logos", headers=headers)
|
|
assert response.status_code == 403
|
|
|
|
|
|
def test_initial_with_header_and_footer(create_super_token):
|
|
"""
|
|
Route:
|
|
"""
|
|
dept1, dept2, dept3, token = create_super_token
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
with app.test_client() as client:
|
|
response = client.get(API_URL + "/logos", headers=headers)
|
|
assert response.status_code == 200
|
|
assert response.json is not None
|
|
assert len(response.json) == 7
|