Группы: приглашения вместо авто-добавления (согласиться/отказаться)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 20:07:20 +03:00
co-authored by Claude Opus 4.8
parent 66370c7df4
commit a5c54512a5
20 changed files with 742 additions and 98 deletions
+12 -27
View File
@@ -3,7 +3,7 @@ from __future__ import annotations
from fastapi.testclient import TestClient
from tests.conftest import create_finished_match, csrf_headers, login, start_match
from tests.conftest import add_group_member, create_finished_match, csrf_headers, login, start_match
def _exp_id(client: TestClient, code: str) -> int:
@@ -20,26 +20,25 @@ def _admin_login(client: TestClient, make_admin) -> None:
assert r.status_code == 200, r.text
def test_group_size_limit(client: TestClient):
def test_group_invite_capacity_limit(client: TestClient):
login(client, "Owner")
gid = client.post(
"/api/groups", json={"name": "Большая", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
# owner = 1; добавляем до 10, 10-й участник сверх лимита → 409.
for i in range(1, 11):
client.post("/api/auth/dev/users", json={"nickname": f"U{i}"}, headers=csrf_headers(client))
statuses = []
for i in range(1, 11):
r = client.post(
f"/api/groups/{gid}/members", json={"nickname": f"U{i}"}, headers=csrf_headers(client)
f"/api/groups/{gid}/invitations", json={"nickname": f"U{i}"}, headers=csrf_headers(client)
)
statuses.append(r.status_code)
# 9 успешных (итого 10 с владельцем), 10-й — отказ.
# owner(1) + 9 приглашений = 10 (лимит мест); 10-е приглашение сверх лимита → 409.
assert statuses[:9] == [200] * 9
assert statuses[9] == 409
def test_match_player_limit(client: TestClient):
def test_match_player_limit(client: TestClient, engine):
me = login(client, "Owner")
fw, fv = _exp_id(client, "forgotten_worlds"), _exp_id(client, "forsaken_voids")
gid = client.post(
@@ -47,12 +46,7 @@ def test_match_player_limit(client: TestClient):
).json()["id"]
ids = [me["id"]]
for i in range(1, 7):
client.post("/api/auth/dev/users", json={"nickname": f"P{i}"}, headers=csrf_headers(client))
ids.append(
client.post(
f"/api/groups/{gid}/members", json={"nickname": f"P{i}"}, headers=csrf_headers(client)
).json()["user_id"]
)
ids.append(add_group_member(engine, gid, f"P{i}"))
factions = client.get(f"/api/groups/{gid}/factions").json()
fids = [f["id"] for f in factions]
# 7 игроков на старте → 422 (максимум 6).
@@ -62,15 +56,12 @@ def test_match_player_limit(client: TestClient):
assert "6" in r.json()["error"]["message"]
def test_admin_edit_match_and_filters(client: TestClient, make_admin):
def test_admin_edit_match_and_filters(client: TestClient, make_admin, engine):
me = login(client, "Аня")
gid = client.post(
"/api/groups", json={"name": "Группа", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
client.post("/api/auth/dev/users", json={"nickname": "Боря"}, headers=csrf_headers(client))
b = client.post(
f"/api/groups/{gid}/members", json={"nickname": "Боря"}, headers=csrf_headers(client)
).json()["user_id"]
b = add_group_member(engine, gid, "Боря")
factions = {f["code"]: f["id"] for f in client.get(f"/api/groups/{gid}/factions").json()}
mid = create_finished_match(
client,
@@ -129,17 +120,14 @@ def test_admin_rename_account(client: TestClient, make_admin):
assert r.status_code == 422, r.text
def test_dev_delete_account_keeps_matches(client: TestClient, make_admin):
def test_dev_delete_account_keeps_matches(client: TestClient, make_admin, engine):
"""DEV-удаление: аккаунт удаляется, партии живут (игрок вычёркивается),
его созданные партии и группы переназначаются на админа."""
me = login(client, "Аня") # владелец группы и создатель партии
gid = client.post(
"/api/groups", json={"name": "Группа", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
client.post("/api/auth/dev/users", json={"nickname": "Боря"}, headers=csrf_headers(client))
b = client.post(
f"/api/groups/{gid}/members", json={"nickname": "Боря"}, headers=csrf_headers(client)
).json()["user_id"]
b = add_group_member(engine, gid, "Боря")
factions = {f["code"]: f["id"] for f in client.get(f"/api/groups/{gid}/factions").json()}
mid = create_finished_match(
client,
@@ -187,15 +175,12 @@ def test_dev_delete_account_rejects_admin(client: TestClient, make_admin):
assert r.status_code == 422, r.text
def test_admin_rename_faction_system_wide(client: TestClient, make_admin):
def test_admin_rename_faction_system_wide(client: TestClient, make_admin, engine):
me = login(client, "Кто-то")
gid = client.post(
"/api/groups", json={"name": "Группа", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
client.post("/api/auth/dev/users", json={"nickname": "Друг"}, headers=csrf_headers(client))
b = client.post(
f"/api/groups/{gid}/members", json={"nickname": "Друг"}, headers=csrf_headers(client)
).json()["user_id"]
b = add_group_member(engine, gid, "Друг")
factions = {f["code"]: f["id"] for f in client.get(f"/api/groups/{gid}/factions").json()}
mid = create_finished_match(
client,