Skip to content

Testing Client

from justapi import JustAPIApp, JustAPITestClient
app = JustAPIApp()
@app.get("/hello")
def hello():
return {"message": "Hello!"}
client = JustAPITestClient(app)
def test_hello():
response = client.get("/hello")
assert response["status"] == 200
assert response["body"] == b'{"message":"Hello!"}'
Method Signature Description
get(path) GET path Send GET request
post(path, body) POST path with JSON body Send POST request
post_with(path, body, headers) POST path with headers POST with custom headers
put(path, body) PUT path with JSON body Send PUT request
patch(path, body) PATCH path with JSON body Send PATCH request
delete(path) DELETE path Send DELETE request

All methods return a dict:

{
"status": 200, # HTTP status code
"headers": {...}, # Response headers
"body": b"..." # Raw body bytes
}
def test_with_auth():
response = client.post_with(
"/items",
{"name": "Widget"},
headers={"Authorization": "Bearer my-token"},
)
assert response["status"] == 201
client = JustAPITestClient(app, database="sqlite:///test.db")