forked from mtusi2026/mtusi2026lab2
ЛР 2: PostgreSQL, сессии в Valkey, трек 2
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Level 4: the API keeps working from PostgreSQL while the session cache is down."""
|
||||
from common import arguments, call, chat_with, expect, member, run
|
||||
|
||||
|
||||
def login_and_read_work_without_cache(base):
|
||||
alice = member(base, "nocache")
|
||||
bob = member(base, "nocache2")
|
||||
me = call(base, "GET", "/api/v1/users/me", token=alice["token"])
|
||||
expect(me["status"] == 200 and me["json"]["id"] == alice["id"], "/users/me без кэша дал %s" % me["status"])
|
||||
chat = chat_with(base, alice, bob)
|
||||
sent = call(base, "POST", "/api/v1/chats/%s/messages" % chat["id"], body={"text": "кэш выключен"}, token=alice["token"])
|
||||
expect(sent["status"] == 201, "запись без кэша дала %s" % sent["status"])
|
||||
history = call(base, "GET", "/api/v1/chats/%s/messages" % chat["id"], token=bob["token"])
|
||||
expect(history["status"] == 200, "чтение без кэша дало %s" % history["status"])
|
||||
expect(any(item["id"] == sent["json"]["id"] for item in history["json"]["items"]), "сообщение не видно без кэша")
|
||||
|
||||
|
||||
def unknown_token_is_still_rejected(base):
|
||||
expect(call(base, "GET", "/api/v1/users/me", token="definitely-not-a-valid-session-token")["status"] == 401, "неизвестный токен принят")
|
||||
expect(call(base, "GET", "/api/v1/users/me")["status"] == 401, "анонимный запрос принят")
|
||||
|
||||
|
||||
def readiness_ignores_the_cache(base):
|
||||
ready = call(base, "GET", "/health/ready")
|
||||
expect(ready["status"] == 200, "/health/ready без кэша дал %s" % ready["status"])
|
||||
|
||||
|
||||
TESTS = [login_and_read_work_without_cache, unknown_token_is_still_rejected, readiness_ignores_the_cache]
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(TESTS, arguments(__doc__).base_url)
|
||||
Reference in New Issue
Block a user