Flaxon 0.3.0 and Teloce-Py 0.3.0 are available on PyPI. Release instructions are maintained on this site; source links identify the framework snapshot. Check version and upgrade guidance.
Testing API
TestClient
Synchronous test client.
Constructor
TestClient(app: Any, base_url: str = "http://testserver")
Methods
get
def get(path: str, **kwargs: Any) -> TestResponse
Send a GET request.
post
def post(path: str, **kwargs: Any) -> TestResponse
Send a POST request.
put
def put(path: str, **kwargs: Any) -> TestResponse
Send a PUT request.
patch
def patch(path: str, **kwargs: Any) -> TestResponse
Send a PATCH request.
delete
def delete(path: str, **kwargs: Any) -> TestResponse
Send a DELETE request.
options
def options(path: str, **kwargs: Any) -> TestResponse
Send an OPTIONS request.
head
def head(path: str, **kwargs: Any) -> TestResponse
Send a HEAD request.
request
def request(method: str, path: str, **kwargs: Any) -> TestResponse
Send a custom request.
AsyncTestClient
Asynchronous test client.
Constructor
AsyncTestClient(app: Any, base_url: str = "http://testserver")
Methods
get
async def get(path: str, **kwargs: Any) -> TestResponse
Send a GET request.
post
async def post(path: str, **kwargs: Any) -> TestResponse
Send a POST request.
put
async def put(path: str, **kwargs: Any) -> TestResponse
Send a PUT request.
patch
async def patch(path: str, **kwargs: Any) -> TestResponse
Send a PATCH request.
delete
async def delete(path: str, **kwargs: Any) -> TestResponse
Send a DELETE request.
options
async def options(path: str, **kwargs: Any) -> TestResponse
Send an OPTIONS request.
head
async def head(path: str, **kwargs: Any) -> TestResponse
Send a HEAD request.
request
async def request(method: str, path: str, **kwargs: Any) -> TestResponse
Send a custom request.
WebSocketClient
Synchronous WebSocket client.
Constructor
WebSocketClient(app: Any, base_url: str = "ws://testserver")
Methods
connect
async def connect(
path: str,
headers: dict[str, str] | None = None
) -> None
Connect to a WebSocket endpoint.
disconnect
async def disconnect(code: int = 1000) -> None
Disconnect from the WebSocket.
send_text
async def send_text(text: str) -> None
Send a text message.
send_bytes
async def send_bytes(data: bytes) -> None
Send binary data.
send_json
async def send_json(data: Any) -> None
Send JSON data.
receive_text
async def receive_text() -> str
Receive a text message.
receive_json
async def receive_json() -> Any
Receive JSON data.
TestResponse
Test response object.
Attributes
| Attribute | Type | Description |
|---|---|---|
| status_code | int | HTTP status code |
| headers | dict[str, str] | Response headers |
| content | bytes | Response content |
Properties
text
@property
def text(self) -> str
Get response as text.
json
def json(self) -> Any
Get response as JSON.
Assertions
Test assertion helpers.
assert_status
@staticmethod
def assert_status(response: Any, expected: int) -> None
Assert HTTP status code.
assert_json
@staticmethod
def assert_json(response: Any) -> dict[str, Any]
Assert response is JSON.
assert_json_array
@staticmethod
def assert_json_array(response: Any) -> list[Any]
Assert response is a JSON array.
assert_has_key
@staticmethod
def assert_has_key(data: dict[str, Any], key: str) -> None
Assert dictionary contains a key.
assert_key_value
@staticmethod
def assert_key_value(
data: dict[str, Any],
key: str,
expected: Any
) -> None
Assert key has expected value.
assert_success
@staticmethod
def assert_success(data: dict[str, Any]) -> None
Assert success response.
assert_error
@staticmethod
def assert_error(data: dict[str, Any]) -> None
Assert error response.
assert_error_code
@staticmethod
def assert_error_code(data: dict[str, Any], code: str) -> None
Assert error code.
assert_validation_error
@staticmethod
def assert_validation_error(
data: dict[str, Any],
field: str | None = None
) -> None
Assert validation error.
assert_redirect
@staticmethod
def assert_redirect(
response: Any,
expected_location: str | None = None
) -> None
Assert redirect response.
assert_header
@staticmethod
def assert_header(
response: Any,
key: str,
expected: str | None = None
) -> None
Assert header exists and matches.
Fixture
Test fixture.
Constructor
Fixture(
name: str,
setup: Callable,
teardown: Callable | None = None
)
Methods
load
async def load() -> Any
Load fixture.
unload
async def unload() -> None
Unload fixture.
FixtureLoader
Fixture loader.
Methods
register
def register(fixture: Fixture) -> None
Register fixture.
get
def get(name: str) -> Fixture | None
Get fixture.
load
async def load(name: str) -> Any
Load fixture.
load_all
async def load_all() -> dict[str, Any]
Load all fixtures.
unload
async def unload(name: str) -> None
Unload fixture.
unload_all
async def unload_all() -> None
Unload all fixtures.
clear
def clear() -> None
Clear all fixtures.
Factory
Test data factory.
Methods
sequence
def sequence(name: str) -> int
Generate a sequence number.
random_string
def random_string(length: int = 10) -> str
Generate a random string.
random_email
def random_email() -> str
Generate a random email.
random_int
def random_int(min: int = 0, max: int = 100) -> int
Generate a random integer.
random_float
def random_float(
min: float = 0.0,
max: float = 100.0
) -> float
Generate a random float.
random_bool
def random_bool() -> bool
Generate a random boolean.
random_uuid
def random_uuid() -> str
Generate a random UUID.
build
def build(**kwargs: Any) -> dict[str, Any]
Build an object.
create
def create(**kwargs: Any) -> dict[str, Any]
Create and save an object.
DatabaseTestMixin
Database testing helpers.
Methods
setup_database
async def setup_database() -> None
Set up the test database.
teardown_database
async def teardown_database() -> None
Tear down the test database.
clear_database
async def clear_database() -> None
Clear the test database.
transaction
async def transaction() -> Any
Start a test transaction.
Use this capability in a full-stack app
Flaxon serves Python APIs and Teloce interfaces in one project. Keep validation, authorization and privileged operations on the server; components call those endpoints and present their results. Follow the full-stack lessons and Teloce integration reference to connect this capability to pages, components and application modules.