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)
# 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.1.1.tar.gz
(2.8 kB
view details)
File details
Details for the file pytest-falcon-0.1.1.tar.gz
.
File metadata
- Download URL: pytest-falcon-0.1.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4993695de75fd1f50a5b883a6d43ee2e8f8f42c913e8ac047d6f06fafe43e5a3 |
|
MD5 | e91fefc8bae36ab8a7acc8c6917f256b |
|
BLAKE2b-256 | 26d3c7fb3cd03e1c407acca55e5405151f7a021ec64b3749e7e096b5c688b7ec |