feat: реализация второй лабы по тз

This commit is contained in:
Enterxx2
2026-10-11 18:14:20 +03:00
parent a6c74c9bb0
commit ea2b432a22
100 changed files with 3416 additions and 428 deletions
+21 -8
View File
@@ -5,7 +5,7 @@ from pathlib import Path
import httpx
import pytest
from helpers import auth, unique_username
from helpers import auth, basic, unique_password, unique_username
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_BASE_URL = json.loads((ROOT / "lab.json").read_text())["default_base_url"]
@@ -24,16 +24,29 @@ def api(base_url: str) -> Iterator[httpx.Client]:
yield client
def register_and_login(
client: httpx.Client, label: str, display_name: str | None = None
) -> dict:
"""Регистрация и вход; в словаре User плюс token и password для тестов"""
username = unique_username(label)
password = unique_password()
body = {
"username": username,
"display_name": display_name or f"Студент {label}",
"password": password,
}
response = client.post("/api/v1/users", json=body)
assert response.status_code == 201, response.text
user = response.json()
session = client.post("/api/v1/auth/sessions", headers=basic(username, password))
assert session.status_code == 201, session.text
return {**user, "token": session.json()["token"], "password": password}
@pytest.fixture
def make_user(api: httpx.Client) -> Callable[..., dict]:
def create(label: str = "user", display_name: str | None = None) -> dict:
body = {
"username": unique_username(label),
"display_name": display_name or f"Студент {label}",
}
response = api.post("/api/v1/users", json=body)
assert response.status_code == 201, response.text
return response.json()
return register_and_login(api, label, display_name)
return create