DocScoDoc/tests/api/test_api_logos.py

57 lines
1.8 KiB
Python
Raw Normal View History

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:
à faire fonctionner en environnment de test (FLASK_ENV=test dans le fichier .env)
pytest tests/api/test_api_logos.py
"""
import pytest
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):
dept1, dept2, dept3, token = create_super_token
HEADERS = {"Authorization": f"Bearer {token}"}
with app.test_client() as client:
response = client.get("/ScoDoc/api/logos", headers=HEADERS)
assert response.status_code == 200
assert response.json is not None
def test_admin_access(create_admin_token):
dept1, dept2, dept3, token = create_admin_token
headers = {"Authorization": f"Bearer {token}"}
with app.test_client() as client:
response = client.get("/ScoDoc/api/logos", headers=headers)
assert response.status_code == 401
def test_lambda_access(create_lambda_token):
dept1, dept2, dept3, token = create_lambda_token
headers = {"Authorization": f"Bearer {token}"}
with app.test_client() as client:
response = client.get("/ScoDoc/api/logos", headers=headers)
assert response.status_code == 401
def test_initial_with_header_and_footer(create_super_token):
dept1, dept2, dept3, token = create_super_token
headers = {"Authorization": f"Bearer {token}"}
with app.test_client() as client:
response = client.get("/ScoDoc/api/logos", headers=headers)
assert response.status_code == 200
assert response.json is not None
assert len(response.json) == 7