Pytest helpers for the Falcon framework.
pip install pytest-falcon
You must create an app
fixture to expose the Falcon application you want to test:
import falcon
import pytest
application = falcon.API()
@pytest.fixture
def app():
return application
Allows you to test your API:
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 asstr
json
the body parsed as json when the response content-type is 'application/json'headers
the response headersstatus
the response status, asstr
('200 OK', '405 Method Not Allowed'…)status_code
the response status code, asint
(200, 201…)