Skip to main content

Async client for testing ASGI web applications

Project description

async-asgi-testclient

Build Status PyPI version

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, ...), the same way people are doing ASGI servers like uvicorn or hypercorn that doesn't depend 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 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
  • follow redirects
  • response streams
  • request streams
  • websocket support

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

async-asgi-testclient-0.2.2.tar.gz (20.3 kB view details)

Uploaded Source

File details

Details for the file async-asgi-testclient-0.2.2.tar.gz.

File metadata

  • Download URL: async-asgi-testclient-0.2.2.tar.gz
  • Upload date:
  • Size: 20.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

Hashes for async-asgi-testclient-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b02eb563910d4ab342f0b0309b5b2a4189f051abe2e880e7e409b884875ded36
MD5 5cdab39a6814a54d56452c99cdbc7246
BLAKE2b-256 37de150950117b633dfd68beaefa2e8f85b7676eb89db5e76817dc2af65c1aa3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page