Skip to main content

Test Clietn for ASGI web applications

Project description

asgi-testClient

Travis (.org) PyPI - Python Version PyPI codecov PyPI - Downloads black

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:

  • <input type="checkbox" disabled="" /> Support Websockets client.
  • <input type="checkbox" disabled="" /> Cookies support.
  • <input type="checkbox" disabled="" /> Redirects.
  • <input type="checkbox" disabled="" /> Support files encoding
  • <input type="checkbox" disabled="" /> Stream request & response

Credits

  • Tom Christie: I brought inspiration from the starlette test client.
  • Kenneth ☤ Reitz: This package tries to replicate requests API.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for asgi-testclient, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size asgi_testclient-0.1.0-py3-none-any.whl (13.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size asgi-testclient-0.1.0.tar.gz (6.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page