Metadata-Version: 2.1
Name: pytest-aiohttp-client
Version: 0.0.3
Summary: Pytest `client` fixture for the Aiohttp
Home-page: https://github.com/sivakov512/pytest-aiohttp-client
Author: Nikita Sivakov
Author-email: sivakov512@gmail.com
License: MIT
Keywords: pytest,fixture,aiohttp,client,api
Platform: UNKNOWN
Classifier: Framework :: AsyncIO
Classifier: Framework :: Pytest
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: pytest (>=6)
Requires-Dist: aiohttp (>=3)

# pytest-aiohttp-client
Awesome pytest fixture for awesome [aiohttp](https://docs.aiohttp.org/en/stable/)!

[![Build status](https://github.com/sivakov512/pytest-aiohttp-client/workflows/test/badge.svg)](https://github.com/sivakov512/pytest-aiohttp-client/actions?query=workflow%3Atest)
[![Coverage Status](https://coveralls.io/repos/github/sivakov512/pytest-aiohttp-client/badge.svg?branch=main)](https://coveralls.io/github/sivakov512/pytest-aiohttp-client?branch=main)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Python versions](https://img.shields.io/pypi/pyversions/pytest-aiohttp-client.svg)](https://pypi.python.org/pypi/pytest-aiohttp-client)
[![PyPi](https://img.shields.io/pypi/v/pytest-aiohttp-client.svg)](https://pypi.python.org/pypi/pytest-aiohttp-client)

## Installation
Install it via `pip` tool:

```bash
pip install pytest-aiohttp-client
```

## Usage example
Plugin provides `api` fixture, but you should define `aiohttp_app` fixture first:
```python
import pytest

from my_awesome_app import make_app


@pytest.fixture
def aiohttp_app() -> Application:
  return make_app()
```

### Default decoding
Fixture will decode and return payload by default as json or bytes (depends on `Content-Type` header):
```python
async def test_returns_json(api):
    got = await api.get("/json-url/")

    assert got == {"key": "value"}


async def test_returns_bytes(api):
    got = await api.get("/url/")

    assert got == b"Some text"
```

### Status code assertions
You can assert on status code:
```python
async def test_returns_ok(api):
    await api.get("/url/", expected_status=200)
```

### `Response` result
Type `as_response=True` if you need `ClientResponse` object:
```python
from aiohttp.client import ClientResponse

async def test_returns_response(api):
    got = await api.get("/url/", as_response=True)

    assert isinstance(got, ClientResponse)
```


## Development and contribution

* install project dependencies
```bash
python setup.py develop
```

* install linting, formatting and testing tools
```bash
pip install -r requirements.txt
```

* run tests
```bash
make test
```

* run linters
```bash
make lint
```

* feel free to contribute!


