Pytest helpers for Falcon.
Project description
[![Build Status](https://travis-ci.org/yohanboniface/pytest-falcon.svg?branch=master)](https://travis-ci.org/yohanboniface/pytest-falcon) [![Pypi version](https://img.shields.io/pypi/v/pytest-falcon.svg)](https://pypi.python.org/pypi/pytest-falcon)
# Pytest-Falcon
Pytest helpers for the Falcon framework.
## Install
```
pip install pytest-falcon
```
## Usage
You must create an `app` fixture to expose the Falcon application you want to test:
```python
import falcon
import pytest
application = falcon.API()
@pytest.fixture
def app():
return application
```
## Fixtures
### client
Allows you to test your API:
```python
class Resource:
def on_post(self, req, resp, **kwargs):
resp.body = json.dumps(req.params)
application.add_route('/route', Resource())
def test_post(client):
resp = client.post('/route', {'myparam': 'myvalue'})
assert resp.status == falcon.HTTP_OK
assert resp.json['myparam'] == 'myvalue'
```
Response properties:
- `body` the body as `str`
- `json` the body parsed as json when the response content-type is 'application/json'
- `headers` the response headers
- `status` the response status, as `str` ('200 OK', '405 Method Not Allowed'…)
- `status_code` the response status code, as `int` (200, 201…)
# Pytest-Falcon
Pytest helpers for the Falcon framework.
## Install
```
pip install pytest-falcon
```
## Usage
You must create an `app` fixture to expose the Falcon application you want to test:
```python
import falcon
import pytest
application = falcon.API()
@pytest.fixture
def app():
return application
```
## Fixtures
### client
Allows you to test your API:
```python
class Resource:
def on_post(self, req, resp, **kwargs):
resp.body = json.dumps(req.params)
application.add_route('/route', Resource())
def test_post(client):
resp = client.post('/route', {'myparam': 'myvalue'})
assert resp.status == falcon.HTTP_OK
assert resp.json['myparam'] == 'myvalue'
```
Response properties:
- `body` the body as `str`
- `json` the body parsed as json when the response content-type is 'application/json'
- `headers` the response headers
- `status` the response status, as `str` ('200 OK', '405 Method Not Allowed'…)
- `status_code` the response status code, as `int` (200, 201…)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytest-falcon-0.3.2.tar.gz
(4.0 kB
view hashes)
Built Distributions
Close
Hashes for pytest_falcon-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32cbe1798da2cae66230023e3b1ad6a575c30f2ff5180c2da0be11010069ef19 |
|
MD5 | 594a5e0bbfaa608e17f82866f69463a2 |
|
BLAKE2b-256 | b6939687b2231c37c3a1a508280d78f4473cb9b27580ef3f0cff775519abafe0 |
Close
Hashes for pytest_falcon-0.3.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f878822c8cf9f9a26d8005ea2c3e5c12d291a70ec33847df9e876f489a66273c |
|
MD5 | 107fcdb133ea91882c3f3a8e47a35592 |
|
BLAKE2b-256 | f852fc57d214386a0ead381831df161c55b4084637e62eda9b141a00ed8260b2 |