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.2.0.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file pytest-falcon-0.2.0.tar.gz
.
File metadata
- Download URL: pytest-falcon-0.2.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5e43591f555388fd976928ae0c8c0e21e750a20c63f0d410fc24f304ffcebba |
|
MD5 | 344bc44ab4e2d07424b4b0e385bcc1bb |
|
BLAKE2b-256 | 34ec17a92896718f279a9fcec72da397753c0d9d37a65f0f66fb25a7fe295ccb |
File details
Details for the file pytest_falcon-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_falcon-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d3a88583112856e599f4a29774835ca6e56c4915a2fff7154942efe012138d7 |
|
MD5 | ec92437b8c360a1d98ab5f03d5db608a |
|
BLAKE2b-256 | 103dbd9ec7754709c33c5a0d047af6cbeb8427cc8ecd50fd5b7c98eae221e5cf |