Test Clietn for ASGI web applications
Project description
asgi-testClient
Testing ASGI applications made easy!
The why?
Why would you build this when all web frameworks come with one? Well, because mostly all those web frameworks have to build their own. I was building my own web framework perhaps (research & learning purpose) and got to the point where a needed a TestClient
but then a asked my self why does anybody building web frameworks have to build their own TestClient when there's a standard?. Ok, then just install starlette
a use it test client; would you install a library just to use a tiny part of it? This client does not have any dependencies.
Requirements
Python 3.6+
It should run on Python 3.5 but I haven' tested it.
Installation
pip install asgi-testclient
Usage
The client replicates the requests API, so if you have used request you should feel comfortable.
import pytest
from asgi_testclient import TestClient
from myapp import API
@pytest.fixture
def client():
return TestClient(API)
@pytest.mark.asyncio
async def test_get(client):
response = await client.get("/")
assert response.json() == {"hello": "world"}
assert response.status_code == 200
I have used pytest
in this example but you can use whichever runner you prefer. Note: the client method are coroutines get, post, delete, put, patch, etc..
.
TODO:
- Support Websockets client.
- Cookies support.
- Redirects.
- Support files encoding
- Stream request & response
Credits
Tom Christie
: I brought inspiration from thestarlette
test client.Kenneth ☤ Reitz
: This package tries to replicaterequests
API.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for asgi_testclient-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9de288dd57231db0d89e79da3dcda90b96fa88fd0abf623050540f4f0b0dad75 |
|
MD5 | 87e2d23048bce043e90565e875ed7ac6 |
|
BLAKE2b-256 | e777c1176aaf27dd69d420c234f4d5a3a3661fbb60a6b4437a89b25f53226313 |