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:
importfalconimportpytestapplication=falcon.API()
@pytest.fixturedefapp():
returnapplicationAllows you to test your API:
classResource:
defon_post(self, req, resp, **kwargs):
resp.body=json.dumps(req.params)
application.add_route('/route', Resource())
deftest_post(client):
resp=client.post('/route', {'myparam': 'myvalue'})
assertresp.status==falcon.HTTP_OKassertresp.json['myparam'] =='myvalue'Response properties:
bodythe body asstrjsonthe body parsed as json when the response content-type is 'application/json'headersthe response headersstatusthe response status, asstr('200 OK', '405 Method Not Allowed'…)status_codethe response status code, asint(200, 201…)