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.1.tar.gz
(3.2 kB
view hashes)
Built Distributions
Close
Hashes for pytest_falcon-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88df3d64e5a3c4d4a1d1b5a863992ffdfbdccf4cfa52b5f894d4d77be1a9338c |
|
MD5 | f2536bbb78ef68bb4000a8060255f9a0 |
|
BLAKE2b-256 | b42303915f0fb70679f33cac66ee262bd89cbc640d05c994cd3c7ae111db4058 |
Close
Hashes for pytest_falcon-0.3.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fcb40da44ca5c5cd2734c93b22f9543c6b954b3250529ba212e90636c8d2a7d |
|
MD5 | 7284379cfbe4e5e7047680332362d4cd |
|
BLAKE2b-256 | 98315b90b8aa61c7fb8bc01b714b02949ef3699972bff6d250a744e2b413bdab |