ScoDoc/tests/api/test_api_formsemestre_data.py

73 lines
2.1 KiB
Python
Raw Normal View History

2023-05-15 23:39:08 +02:00
"""Test formsemestre
Utilisation :
créer les variables d'environnement: (indiquer les valeurs
pour le serveur ScoDoc que vous voulez interroger)
export SCODOC_URL="https://scodoc.xxx.net/"
export SCODOC_USER="xxx"
export SCODOC_PASSWD="xxx"
export CHECK_CERTIFICATE=0 # ou 1 si serveur de production avec certif SSL valide
(on peut aussi placer ces valeurs dans un fichier .env du répertoire tests/api).
Lancer :
pytest tests/api/test_api_formsemestre.py
"""
2024-07-17 14:58:49 +02:00
2023-05-15 23:39:08 +02:00
import requests
from app.scodoc import sco_utils as scu
from tests.api.setup_test_api import (
API_URL,
CHECK_CERTIFICATE,
api_headers,
)
2024-07-17 14:58:49 +02:00
def test_groups_save_auto_assignment(api_headers):
2023-05-15 23:39:08 +02:00
"""
Routes:
2024-07-17 14:58:49 +02:00
/formsemestre/<id>/groups_save_auto_assignment
/formsemestre/<id>/groups_get_auto_assignment
2023-05-15 23:39:08 +02:00
"""
formsemestre_id = 1
r = requests.get(
f"{API_URL}/formsemestre/{formsemestre_id}",
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 200
# On stocke une chaine quelconque
data_orig = (
"""{ "attribute" : "Un paquet de json", "valide": pas nécessairement +}--"""
)
r = requests.post(
2024-07-17 14:58:49 +02:00
f"{API_URL}/formsemestre/{formsemestre_id}/groups_save_auto_assignment",
2023-05-15 23:39:08 +02:00
data=data_orig.encode("utf-8"),
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 200
# GET
r = requests.get(
2024-07-17 14:58:49 +02:00
f"{API_URL}/formsemestre/{formsemestre_id}/groups_get_auto_assignment",
2023-05-15 23:39:08 +02:00
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 200
assert r.text == data_orig
# Tente d'envoyer trop de données
r = requests.post(
2024-07-17 14:58:49 +02:00
f"{API_URL}/formsemestre/{formsemestre_id}/groups_save_auto_assignment",
2023-05-15 23:39:08 +02:00
data="F*CK" * 1000000, # environ 4MB
headers=api_headers,
verify=CHECK_CERTIFICATE,
timeout=scu.SCO_TEST_API_TIMEOUT,
)
assert r.status_code == 413