Files
mtusi2026lab7/student-tests/test_cursor_http.py
T

50 lines
1.6 KiB
Python

import base64
import json
import os
import uuid
import pytest
from client import Client
@pytest.fixture(scope="module")
def shared():
client = Client(os.getenv("BASE_URL", "http://127.0.0.1:8085"))
return client, *client.bootstrap()
@pytest.mark.parametrize(
"date",
[
"2026-W01-1T00:00:00Z",
"20260101T000000Z",
"2026-01-01 00:00:00Z",
"2026-01-01X00:00:00Z",
"2026-01-01T00:00:00+00:00",
"2026-02-30T00:00:00Z",
"2026-01-01T24:00:00Z",
"2026-01-01T00:00:00.1234567Z",
],
)
def test_cursor_rejects_noncanonical_dates_over_http(shared, date):
c, alice, _, _, chat = shared
for path, scope in [
("/api/v1/chats", "chats:" + alice["id"]),
(f"/api/v1/chats/{chat['id']}/messages", "messages:" + chat["id"]),
]:
payload = [1, scope, date, str(uuid.uuid4())]
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
c.call("GET", path + "?cursor=" + cursor, 400, actor=alice)
@pytest.mark.parametrize("version", [True, 1.0])
def test_cursor_rejects_noninteger_version_over_http(shared, version):
c, alice, _, _, chat = shared
for path, scope in [
("/api/v1/chats", "chats:" + alice["id"]),
(f"/api/v1/chats/{chat['id']}/messages", "messages:" + chat["id"]),
]:
payload = [version, scope, "2026-01-01T00:00:00Z", str(uuid.uuid4())]
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
c.call("GET", path + "?cursor=" + cursor, 400, actor=alice)