A testing framework working with Starlette TestClient.
Project description
LinearTest
A testing framework working with Starlette TestClient.
- Source code: https://github.com/fanyf22/lineartest/
- Documentation: https://fanyf22.github.io/lineartest/
Dependencies
python = "^3.10"
pydantic = "^2.6.4"
pyyaml = "^6.0.1"
httpx = "^0.27.0"
Installing
The package is published on https://pypi.org/lineartest.
Use pip
or similar commands to install it:
pip install lineartest
Features
lineartest.schedule
helps you run tests one-by-one in order, and the tests run later can retrieve the results from the tests run earlier.lineartest.client
helps you log the detail of a request and the response easily.
Example
from pydantic import BaseModel
from starlette.testclient import TestClient
from lineartest import LinearClient, schedule
# import your ASGI app here for testing
...
test_client = TestClient(app)
client = LinearClient(test_client)
# add `test_login` function to schedule
@schedule
def test_login(username, password):
class Response(BaseModel):
success: bool
token: str
# the parameters are the same as `TestClient`
res = client.post('/login', data={
'username': username,
'password': password
}, model=Response) # use `model` parameter to specify a response model
assert res.success
return res.token # the result will be stored by `schedule`
# add `test_resource` function to schedule
@schedule
def test_resource():
# use `schedule.get` to retrieve history result
token = schedule.get(test_login)
class Response(BaseModel):
success: bool
res = client.get('/', headers={
'Authorization': f'Bearer {token}'
}, model=Response)
assert res.success
# run the schedule
# you may pass positional or keyword arguments
schedule.run('username', password='password')
License
This project is licensed under the terms of the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lineartest-0.4.4.tar.gz
(5.7 kB
view details)
Built Distribution
File details
Details for the file lineartest-0.4.4.tar.gz
.
File metadata
- Download URL: lineartest-0.4.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfcfaae3bf5f46aea3b816c4642b25dbaddb218f3db6ad6ddb501129fa6d48db |
|
MD5 | ff6cd132420cc596f033886c000d584d |
|
BLAKE2b-256 | 94b3bb157cc62b346472670b3cbd44208a9146fb755218a5561434300f2dba9e |
File details
Details for the file lineartest-0.4.4-py3-none-any.whl
.
File metadata
- Download URL: lineartest-0.4.4-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7d70623e7128221db7c17a9c548018c6aa9ec547d90695c0faeebbb6817f21f |
|
MD5 | 0c8c6a2641a810639ed1932fcf360266 |
|
BLAKE2b-256 | 588a17dd6e6c1765e90ef1b26ae1ff6ad4ac1cc5a4a5f514bdcbf57336fc6f98 |