Async client for testing ASGI web servers
Project description
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 deppend on the web framework (Quart, Startlette, ...), the same way people are doing ASGI servers like uvicorn or hypercorn that doesn't deppend on the framework.
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 asgi_testclient import TestClient
from .my_api import app
import pytest
@pytest.mark.asyncio
async def test_quart_app():
async with TestClient() 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"}
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
File details
Details for the file async-asgi-testclient-0.1.1.tar.gz
.
File metadata
- Download URL: async-asgi-testclient-0.1.1.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbb756a4c89629eab19977cf17d49dc04a1700fe41bfb485bd7915d1d1cd1604 |
|
MD5 | 568fdc81d09749486ec8c61c0ac98d1c |
|
BLAKE2b-256 | a4ece4822fa4b76ef8c74ed4ae544f06084b7eacb04b155447f3934d76828b04 |