Metadata-Version: 2.1
Name: lineartest
Version: 0.3.2
Summary: A testing framework working with Starlette TestClient.
License: MIT
Author: Philip Fan
Author-email: topfyf@qq.com
Requires-Python: >=3.10,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: httpx (>=0.27.0,<0.28.0)
Requires-Dist: pydantic (>=2.6.4,<3.0.0)
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
Requires-Dist: starlette (>=0.37.2,<0.38.0)
Description-Content-Type: text/markdown

# LinearTest
A testing framework working with Starlette TestClient.

- **Source code**: https://github.com/fanyf22/lineartest/
- **Documentation**: https://fanyf22.github.io/lineartest/

## Dependencies

```requirements
python>=3.10
starlette>=0.37.2
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:

```shell
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

```python
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.

