forked from mtusi2026/mtusi2026lab2
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
import os
|
|
import pytest
|
|
import uuid
|
|
import requests
|
|
|
|
|
|
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8080")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def base_url():
|
|
return BASE_URL
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def alice(base_url):
|
|
username = f"st_alice_{uuid.uuid4().hex[:8]}"
|
|
response = requests.post(f"{base_url}/api/v1/users", json={
|
|
"username": username,
|
|
"display_name": "Alice Student",
|
|
})
|
|
assert response.status_code == 201, response.text
|
|
return {"id": response.json()["id"], "username": username, "user": response.json()}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def bob(base_url):
|
|
username = f"st_bob_{uuid.uuid4().hex[:8]}"
|
|
response = requests.post(f"{base_url}/api/v1/users", json={
|
|
"username": username,
|
|
"display_name": "Bob Student",
|
|
})
|
|
assert response.status_code == 201, response.text
|
|
return {"id": response.json()["id"], "username": username, "user": response.json()}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def eve(base_url):
|
|
username = f"st_eve_{uuid.uuid4().hex[:8]}"
|
|
response = requests.post(f"{base_url}/api/v1/users", json={
|
|
"username": username,
|
|
"display_name": "Eve Student",
|
|
})
|
|
assert response.status_code == 201, response.text
|
|
return {"id": response.json()["id"], "username": username, "user": response.json()}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def chat(base_url, alice, bob):
|
|
|
|
response = requests.post(f"{base_url}/api/v1/chats", headers={
|
|
"X-User-Id": alice["id"]
|
|
}, json={
|
|
"title": "Student Test Chat",
|
|
"member_ids": [alice["id"], bob["id"]]
|
|
})
|
|
assert response.status_code == 201, response.text
|
|
return response.json()
|
|
|
|
def auth(actor):
|
|
return {"X-User-Id": actor["id"]}
|