async-asgi-testclient


Nameasync-asgi-testclient JSON
Version 1.4.11 PyPI version JSON
download
home_pagehttps://github.com/vinissimus/async-asgi-testclient
SummaryAsync client for testing ASGI web applications
upload_time2022-06-13 09:30:07
maintainer
docs_urlNone
authorJordi Masip
requires_python
licenseMIT license
keywords async asgi testclient
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            # async-asgi-testclient

[![Build Status](https://travis-ci.com/vinissimus/async-asgi-testclient.svg?branch=master)](https://travis-ci.com/vinissimus/async-asgi-testclient) [![PyPI version](https://badge.fury.io/py/async-asgi-testclient.svg)](https://badge.fury.io/py/async-asgi-testclient) ![](https://img.shields.io/pypi/pyversions/async-asgi-testclient.svg) [![Codcov](https://codecov.io/gh/vinissimus/async-asgi-testclient/branch/master/graph/badge.svg)](https://codecov.io/gh/vinissimus/async-asgi-testclient/branch/master) ![](https://img.shields.io/github/license/vinissimus/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](https://gitlab.com/pgjones/quart), [Startlette](https://github.com/encode/starlette), ...).

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](https://gitlab.com/pgjones/quart).

## Quickstart

Requirements: Python 3.6+

Installation:

```bash
pip install async-asgi-testclient
```

## Usage

`my_api.py`:
```python
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`:
```python
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

 - [X] cookies
 - [X] multipart/form-data
 - [X] follow redirects
 - [X] response streams
 - [X] request streams
 - [X] websocket support
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vinissimus/async-asgi-testclient",
    "name": "async-asgi-testclient",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "async asgi testclient",
    "author": "Jordi Masip",
    "author_email": "jordi@masip.cat",
    "download_url": "https://files.pythonhosted.org/packages/52/9a/0eb3fd37d4f9ad1e9b2b6d6b91357d3ebf7534271c32e343185a5d204903/async-asgi-testclient-1.4.11.tar.gz",
    "platform": null,
    "description": "# async-asgi-testclient\n\n[![Build Status](https://travis-ci.com/vinissimus/async-asgi-testclient.svg?branch=master)](https://travis-ci.com/vinissimus/async-asgi-testclient) [![PyPI version](https://badge.fury.io/py/async-asgi-testclient.svg)](https://badge.fury.io/py/async-asgi-testclient) ![](https://img.shields.io/pypi/pyversions/async-asgi-testclient.svg) [![Codcov](https://codecov.io/gh/vinissimus/async-asgi-testclient/branch/master/graph/badge.svg)](https://codecov.io/gh/vinissimus/async-asgi-testclient/branch/master) ![](https://img.shields.io/github/license/vinissimus/async-asgi-testclient)\n\nAsync ASGI TestClient is a library for testing web applications that implements ASGI specification (version 2 and 3).\n\nThe motivation behind this project is building a common testing library that doesn't depend on the web framework ([Quart](https://gitlab.com/pgjones/quart), [Startlette](https://github.com/encode/starlette), ...).\n\nIt 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.\n\nThis library is based on the testing module provided in [Quart](https://gitlab.com/pgjones/quart).\n\n## Quickstart\n\nRequirements: Python 3.6+\n\nInstallation:\n\n```bash\npip install async-asgi-testclient\n```\n\n## Usage\n\n`my_api.py`:\n```python\nfrom quart import Quart, jsonify\n\napp = Quart(__name__)\n\n@app.route(\"/\")\nasync def root():\n    return \"plain response\"\n\n@app.route(\"/json\")\nasync def json():\n    return jsonify({\"hello\": \"world\"})\n\nif __name__ == '__main__':\n    app.run()\n```\n\n`test_app.py`:\n```python\nfrom async_asgi_testclient import TestClient\n\nimport pytest\n\n@pytest.mark.asyncio\nasync def test_quart_app():\n    from .my_api import app\n\n    async with TestClient(app) as client:\n        resp = await client.get(\"/\")\n        assert resp.status_code == 200\n        assert resp.text == \"plain response\"\n\n        resp = await client.get(\"/json\")\n        assert resp.status_code == 200\n        assert resp.json() == {\"hello\": \"world\"}\n```\n\n## Supports\n\n - [X] cookies\n - [X] multipart/form-data\n - [X] follow redirects\n - [X] response streams\n - [X] request streams\n - [X] websocket support",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Async client for testing ASGI web applications",
    "version": "1.4.11",
    "project_urls": {
        "Homepage": "https://github.com/vinissimus/async-asgi-testclient"
    },
    "split_keywords": [
        "async",
        "asgi",
        "testclient"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "529a0eb3fd37d4f9ad1e9b2b6d6b91357d3ebf7534271c32e343185a5d204903",
                "md5": "4896444d7d6aeb7164c4befbbebd8d45",
                "sha256": "4449ac85d512d661998ec61f91c9ae01851639611d748d81ae7f816736551792"
            },
            "downloads": -1,
            "filename": "async-asgi-testclient-1.4.11.tar.gz",
            "has_sig": false,
            "md5_digest": "4896444d7d6aeb7164c4befbbebd8d45",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11716,
            "upload_time": "2022-06-13T09:30:07",
            "upload_time_iso_8601": "2022-06-13T09:30:07.279794Z",
            "url": "https://files.pythonhosted.org/packages/52/9a/0eb3fd37d4f9ad1e9b2b6d6b91357d3ebf7534271c32e343185a5d204903/async-asgi-testclient-1.4.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-06-13 09:30:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vinissimus",
    "github_project": "async-asgi-testclient",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "lcname": "async-asgi-testclient"
}
        
Elapsed time: 0.17713s