forked from ScoDoc/DocScoDoc
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
"""Test API : utilisateurs
|
||
|
|
||
|
Utilisation :
|
||
|
pytest tests/api/test_api_users.py
|
||
|
"""
|
||
|
|
||
|
from tests.api.setup_test_api import (
|
||
|
API_URL,
|
||
|
CHECK_CERTIFICATE,
|
||
|
GET,
|
||
|
POST_JSON,
|
||
|
api_headers,
|
||
|
api_admin_headers,
|
||
|
get_auth_headers,
|
||
|
)
|
||
|
|
||
|
|
||
|
def test_list_users(api_admin_headers):
|
||
|
"""
|
||
|
Routes: /user/<int:uid>
|
||
|
/users/query?departement=dept_acronym&active=1&like=<str:nom>
|
||
|
"""
|
||
|
admin_h = api_admin_headers
|
||
|
depts = GET("/departements", headers=admin_h)
|
||
|
assert len(depts) > 0
|
||
|
u = GET("/user/1", headers=admin_h)
|
||
|
assert u["id"] == 1
|
||
|
assert u["user_name"]
|
||
|
assert u["date_expiration"] is None
|
||
|
dept_u = u["dept"]
|
||
|
|
||
|
# Tous les utilisateurs, vus par SuperAdmin:
|
||
|
users = GET("/users/query", headers=admin_h)
|
||
|
|
||
|
# Les utilisateurs de chaque département (+ ceux sans département)
|
||
|
all_users = []
|
||
|
for acronym in [dept["acronym"] for dept in depts] + [""]:
|
||
|
all_users += GET(f"/users/query?departement={acronym}", headers=admin_h)
|
||
|
all_users.sort(key=lambda u: u["user_name"])
|
||
|
assert len(all_users) == len(users)
|
||
|
# On a créé un user "u_" par département:
|
||
|
u_users = GET("/users/query?starts_with=U ", headers=admin_h)
|
||
|
assert len(u_users) == len(depts)
|
||
|
assert len(GET("/users/query?departement=AA", headers=admin_h)) == 1
|
||
|
assert len(GET("/users/query?departement=AA&starts_with=U ", headers=admin_h)) == 1
|
||
|
assert (
|
||
|
len(
|
||
|
GET(
|
||
|
"/users/query?departement=AA&starts_with=XXX",
|
||
|
headers=admin_h,
|
||
|
)
|
||
|
)
|
||
|
== 0
|
||
|
)
|
||
|
# Utilisateurs vus par d'autres utilisateurs (droits accès)
|
||
|
for i, u in enumerate(u for u in u_users if u["dept"] != "TAPI"):
|
||
|
headers = get_auth_headers(u["user_name"], "test")
|
||
|
users_by_u = GET("/users/query", headers=headers)
|
||
|
assert len(users_by_u) == 4 + i
|
||
|
# explication: tous ont le droit de voir les 3 users de TAPI
|
||
|
# (test, other et u_TAPI)
|
||
|
# plus l'utilisateur de chaque département jusqu'au leur
|
||
|
# (u_AA voit AA, u_BB voit AA et BB, etc)
|