chore: carry over lab 1 solution into lab 2 skeleton
Copy the committed lab 1 sources as-is: src/, student-tests/, bench/, Dockerfile, docker-compose.yml, pyproject.toml, uv.lock, .python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/, openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays in the lab 1 repository. Merge the new skeleton files with own sections: Makefile (lab 2 targets plus own run, docker, bench and common targets), .gitignore, .dockerignore and .env.example. Rename the image to mtusi-messenger:lab2 and point AGENTS.md at lab 2. The application is still the in-memory lab 1 implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""Спек `users`: регистрация и текущий пользователь."""
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from api_client import API, Actor, Api, unique_username
|
||||
from contract import assert_error, assert_ok
|
||||
|
||||
|
||||
def register_raw(
|
||||
api: Api,
|
||||
username: str,
|
||||
display_name: str = "User",
|
||||
) -> httpx.Response:
|
||||
return api.request(
|
||||
"POST",
|
||||
f"{API}/users",
|
||||
json={"username": username, "display_name": display_name},
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Успешная регистрация")
|
||||
def test_register(api: Api, bob: Actor) -> None:
|
||||
username = unique_username()
|
||||
resp = register_raw(api, username, "Алиса")
|
||||
user = assert_ok(resp, 201, "User")
|
||||
assert (user["username"], user["display_name"]) == (username, "Алиса")
|
||||
assert user["id"] != bob.id
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Заглавные буквы")
|
||||
def test_username_uppercase(api: Api) -> None:
|
||||
username = unique_username()
|
||||
assert_error(register_raw(api, username.upper()), 400)
|
||||
# то же имя строчными свободно: отказ был только из-за регистра
|
||||
api.register(username=username)
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Слишком короткий")
|
||||
def test_username_too_short(api: Api) -> None:
|
||||
assert_error(register_raw(api, "ab"), 400)
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Перевод строки в конце")
|
||||
def test_username_trailing_newline(api: Api) -> None:
|
||||
assert_error(register_raw(api, unique_username() + "\n"), 400)
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Граница длины")
|
||||
def test_display_name_length(api: Api) -> None:
|
||||
user = assert_ok(
|
||||
register_raw(api, unique_username(), "👋" * 100),
|
||||
201,
|
||||
"User",
|
||||
)
|
||||
assert user["display_name"] == "👋" * 100
|
||||
assert_error(register_raw(api, unique_username(), "👋" * 101), 400)
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Только пробелы")
|
||||
def test_display_name_blank(api: Api) -> None:
|
||||
assert_error(register_raw(api, unique_username(), " "), 400)
|
||||
# значимые пробелы по краям не обрезаются
|
||||
user = api.register(display_name=" Алиса ").user
|
||||
assert user["display_name"] == " Алиса "
|
||||
|
||||
|
||||
@pytest.mark.spec("users", "Совпадает с регистрацией")
|
||||
def test_me_equals_registration(api: Api, alice: Actor) -> None:
|
||||
resp = api.request("GET", f"{API}/users/me", actor=alice)
|
||||
assert assert_ok(resp, 200, "User") == alice.user
|
||||
Reference in New Issue
Block a user