forked from mtusi2026/mtusi2026lab3
lab3: пустой cursor -> 400
This commit is contained in:
@@ -310,8 +310,7 @@ def decode_cursor(cursor: str):
|
|||||||
|
|
||||||
|
|
||||||
def page_after(cursor: str | None, *, chat_id: UUID | None = None, user_id: UUID | None = None):
|
def page_after(cursor: str | None, *, chat_id: UUID | None = None, user_id: UUID | None = None):
|
||||||
"""Курсор -> ключ (created_at, id), с которого продолжать. Чужой или битый курсор — 400."""
|
if cursor is None:
|
||||||
if not cursor:
|
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
created_at, object_id, cursor_chat_id, cursor_user_id = decode_cursor(cursor)
|
created_at, object_id, cursor_chat_id, cursor_user_id = decode_cursor(cursor)
|
||||||
|
|||||||
@@ -77,6 +77,17 @@ def test_pagination():
|
|||||||
print("PASS: pagination works across multiple pages, foreign cursor returns 400")
|
print("PASS: pagination works across multiple pages, foreign cursor returns 400")
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_cursor():
|
||||||
|
alice = new_user("alice")
|
||||||
|
chat = new_chat(alice)
|
||||||
|
send(alice, chat["id"], "one message")
|
||||||
|
for path in ("/api/v1/chats", f"/api/v1/chats/{chat['id']}/messages"):
|
||||||
|
for query in ("?cursor=", "?cursor", "?limit=10&cursor="):
|
||||||
|
call("GET", path + query, 400, token=alice["token"])
|
||||||
|
call("GET", path, 200, token=alice["token"])
|
||||||
|
print("PASS: empty cursor (?cursor= and ?cursor) returns 400, no cursor returns the first page")
|
||||||
|
|
||||||
|
|
||||||
def test_chat_list_pagination():
|
def test_chat_list_pagination():
|
||||||
alice, bob = new_user("alice"), new_user("bob")
|
alice, bob = new_user("alice"), new_user("bob")
|
||||||
created = [new_chat(alice, bob, title=f"Chat {i}")["id"] for i in range(3)]
|
created = [new_chat(alice, bob, title=f"Chat {i}")["id"] for i in range(3)]
|
||||||
@@ -230,6 +241,7 @@ if __name__ == "__main__":
|
|||||||
test_foreign_chat,
|
test_foreign_chat,
|
||||||
test_empty_message,
|
test_empty_message,
|
||||||
test_pagination,
|
test_pagination,
|
||||||
|
test_empty_cursor,
|
||||||
test_chat_list_pagination,
|
test_chat_list_pagination,
|
||||||
test_unicode,
|
test_unicode,
|
||||||
test_nul_character_is_stored,
|
test_nul_character_is_stored,
|
||||||
|
|||||||
Reference in New Issue
Block a user