Coverage for tests/test_boundary_validation.py: 100%
29 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-01 20:15 +0300
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-01 20:15 +0300
1"""Public boundary validation for constrained numeric arguments."""
3from __future__ import annotations
5from collections.abc import Awaitable, Callable
6from typing import cast
8from snektest import assert_raises, test
10from snekql import (
11 Database,
12 DatabaseRuntimeError,
13 Model,
14 Pending,
15 QueryConstructionError,
16 Text,
17 select,
18)
19from tests.logging_helpers import NULL_LOGGER
22class BoundaryUser[S = Pending](Model[S, "BoundaryUser[object]"]):
23 """Table model used by select boundary validation tests."""
25 email: BoundaryUser.Col[str] = Text(nullable=False)
28@test(mark="fast")
29def select_limit_and_offset_reject_invalid_values_at_boundary() -> None:
30 """Constrained select integers are validated by public chain methods."""
32 limit_fn = cast("Callable[[object], object]", select(BoundaryUser).all().limit)
33 offset_fn = cast("Callable[[object], object]", select(BoundaryUser).all().offset)
35 with assert_raises(QueryConstructionError):
36 _ = limit_fn(-1)
38 with assert_raises(QueryConstructionError):
39 _ = limit_fn(True)
41 with assert_raises(QueryConstructionError):
42 _ = offset_fn("1")
45@test(mark="medium")
46async def database_numeric_configuration_rejects_invalid_values_at_boundary() -> None:
47 """Runtime numeric configuration rejects invalid values as domain errors."""
49 initialize_fn = cast("Callable[..., Awaitable[object]]", Database.initialize)
51 with assert_raises(DatabaseRuntimeError):
52 _ = await initialize_fn(NULL_LOGGER, database=":memory:", pool_size=True)
54 database = await Database.initialize(NULL_LOGGER, database=":memory:")
55 try:
56 transaction_fn = cast("Callable[..., object]", database.transaction)
57 with assert_raises(DatabaseRuntimeError):
58 _ = transaction_fn(timeout="1")
59 finally:
60 await database.close()