forked from mtusi2026/mtusi2026lab5
ЛР5: асинхронная обработка вложений (RabbitMQ + worker), transactional outbox, варианты, трек 5.1
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"""Student tests run against an already-running compose stand.
|
||||
|
||||
Start the stand first (secrets + `docker compose up -d --build`), then:
|
||||
|
||||
.venv\\Scripts\\python -m pytest student-tests -v
|
||||
# or: make test-student PYTHON=.venv/bin/python
|
||||
|
||||
Override the target with BASE_URL (default http://localhost:8080).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8080")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def base_url() -> str:
|
||||
return BASE_URL.rstrip("/")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def client(base_url):
|
||||
from http_client import Client
|
||||
|
||||
return Client(base_url)
|
||||
|
||||
|
||||
def _register_and_login(client, label: str) -> dict:
|
||||
suffix = os.urandom(4).hex()
|
||||
username = f"s_{label}_{suffix}"
|
||||
password = "T3st-" + os.urandom(8).hex()
|
||||
registered = client.register(username, password, "Студент " + label)
|
||||
assert registered.status == 201, registered.body
|
||||
user = registered.json
|
||||
session = client.login(username, password)
|
||||
assert session.status == 201, session.body
|
||||
payload = session.json
|
||||
return {
|
||||
"id": user["id"],
|
||||
"username": username,
|
||||
"password": password,
|
||||
"user": user,
|
||||
"token": payload["token"],
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def alice(client):
|
||||
return _register_and_login(client, "alice")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def bob(client):
|
||||
return _register_and_login(client, "bob")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def chat(client, alice, bob):
|
||||
response = client.create_chat(alice["token"], [alice["id"], bob["id"]])
|
||||
assert response.status == 201, response.body
|
||||
return response.json
|
||||
Reference in New Issue
Block a user