diff --git a/main.py b/main.py index 60b20db..47dc4e4 100644 --- a/main.py +++ b/main.py @@ -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): - """Курсор -> ключ (created_at, id), с которого продолжать. Чужой или битый курсор — 400.""" - if not cursor: + if cursor is None: return None try: created_at, object_id, cursor_chat_id, cursor_user_id = decode_cursor(cursor) diff --git a/student-tests/test_api.py b/student-tests/test_api.py index 4a68205..7c770d9 100644 --- a/student-tests/test_api.py +++ b/student-tests/test_api.py @@ -77,6 +77,17 @@ def test_pagination(): 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(): alice, bob = new_user("alice"), new_user("bob") 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_empty_message, test_pagination, + test_empty_cursor, test_chat_list_pagination, test_unicode, test_nul_character_is_stored,