Files
mtusi2026lab6/student-tests/test_cursor_format.py
T

40 lines
1.1 KiB
Python

import base64
import json
from uuid import uuid4
import pytest
from messenger.domain import Failure, boundary
@pytest.mark.parametrize(
"version,date",
[
(True, "2026-01-01T00:00:00Z"),
(1.0, "2026-01-01T00:00:00Z"),
(1, "2026-W01-1T00:00:00Z"),
(1, "20260101T000000Z"),
(1, "2026-01-01 00:00:00Z"),
(1, "2026-01-01X00:00:00Z"),
(1, "2026-02-30T00:00:00Z"),
(1, "2026-01-01T00:00:00.1234567Z"),
],
)
def test_boundary_rejects_python_iso_extensions(version, date):
payload = [version, "scope", date, str(uuid4())]
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
with pytest.raises(Failure) as error:
boundary("scope", cursor)
assert error.value.status == 400
@pytest.mark.parametrize(
"date", ["2026-01-01T00:00:00Z", "2026-01-01T00:00:00.1Z", "2026-01-01T00:00:00.123456Z"]
)
def test_boundary_preserves_generated_format(date):
uid = str(uuid4())
cursor = (
base64.urlsafe_b64encode(json.dumps([1, "scope", date, uid]).encode()).decode().rstrip("=")
)
assert boundary("scope", cursor) == (date, uid)