Async client for testing ASGI web applications
Project Links
Meta
Author: Jordi Masip
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Natural Language
- English
Programming Language
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
async-asgi-testclient
Async ASGI TestClient is a library for testing web applications that implements ASGI specification (version 2 and 3).
The motivation behind this project is building a common testing library that doesn't depend on the web framework (Quart, Startlette, ...).
It works by calling the ASGI app directly. This avoids the need to run the app with a http server in a different process/thread/asyncio-loop. Since the app and test run in the same asyncio loop, it's easier to write tests and debug code.
This library is based on the testing module provided in Quart.
Quickstart
Requirements: Python 3.6+
Installation:
pip install async-asgi-testclient
Usage
my_api.py
:
from quart import Quart, jsonify
app = Quart(__name__)
@app.route("/")
async def root():
return "plain response"
@app.route("/json")
async def json():
return jsonify({"hello": "world"})
if __name__ == '__main__':
app.run()
test_app.py
:
from async_asgi_testclient import TestClient
import pytest
@pytest.mark.asyncio
async def test_quart_app():
from .my_api import app
async with TestClient(app) as client:
resp = await client.get("/")
assert resp.status_code == 200
assert resp.text == "plain response"
resp = await client.get("/json")
assert resp.status_code == 200
assert resp.json() == {"hello": "world"}
Supports
- cookies
- multipart/form-data
- follow redirects
- response streams
- request streams
- websocket support
Jun 13, 2022
1.4.11
Mar 11, 2022
1.4.10
Dec 22, 2021
1.4.9
Dec 14, 2021
1.4.8
Nov 11, 2021
1.4.7
Mar 02, 2021
1.4.6
Jan 11, 2021
1.4.5
Mar 18, 2020
1.4.4
Feb 10, 2020
1.4.3
Jan 24, 2020
1.4.2
Jan 21, 2020
1.4.1
Jan 20, 2020
1.4.0
Dec 30, 2019
1.3.0
Dec 07, 2019
1.2.2
Nov 26, 2019
1.2.1
Nov 06, 2019
1.2.0
Oct 28, 2019
1.1.3
Oct 21, 2019
1.1.2
Sep 27, 2019
1.1.1
Sep 24, 2019
1.1.0
Sep 24, 2019
1.0.4
Jul 01, 2019
1.0.3
Jun 19, 2019
1.0.2
Jun 17, 2019
1.0.1
Jun 17, 2019
1.0.0
Jun 14, 2019
0.2.2
Jun 14, 2019
0.2.1
Jun 07, 2019
0.2.0
Apr 23, 2019
0.1.3
Apr 17, 2019
0.1.2
Apr 16, 2019
0.1.1
Apr 16, 2019
0.1
Files in release
No dependencies