43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""Outils des tests du site : client, connexion, aperçu des diagrammes."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from .specs import DUMP, _dumped
|
|
|
|
ORIGIN = "http://testserver"
|
|
|
|
PASSWORD = "un-mot-de-passe-solide"
|
|
|
|
H = {"Origin": ORIGIN}
|
|
|
|
CH = "UC" + "a" * 22
|
|
|
|
OTHER = "UC" + "b" * 22
|
|
|
|
COMMENT_TEXTS = ["Apothecary Diaries saison 2", "une applepie", "rien", "APOTHECARY DIARIES et applepie"]
|
|
|
|
|
|
def preview(c, config, view=None, status=200):
|
|
body = {"config": config}
|
|
if view is not None:
|
|
body["view"] = view
|
|
r = c.post("/api/preview", json=body, headers={"Origin": ORIGIN})
|
|
assert r.status_code == status, r.text
|
|
out = r.json()
|
|
if DUMP and status == 200 and out.get("spec"):
|
|
_dumped.append({"name": json.dumps([config, view]), "spec": out["spec"]})
|
|
return out
|
|
|
|
|
|
def login_as(c, user):
|
|
c.post("/logout", headers={"Origin": ORIGIN})
|
|
r = c.post("/login", data={"username": user, "password": PASSWORD}, headers={"Origin": ORIGIN},
|
|
follow_redirects=False)
|
|
assert r.status_code == 303 and r.headers["location"] == "/"
|
|
|
|
|
|
def login(client, password=PASSWORD, origin=ORIGIN):
|
|
return client.post("/login", data={"username": "alice", "password": password},
|
|
headers={"Origin": origin}, follow_redirects=False)
|