Hi,
I'm trying to use WebTest with pytest and Cornice. I have defined an endpoint that I can manually test with Postman with no issues. I try to test the same endpoint with:
class TestInvoice:
def test_create_invoice(self, app):
resp = app.post_json(COLLECTION_PATH, dict(customer=1, value="Test customer"))
assert resp.json["customer"] == "Test customer"
But I get the following error:
self = <Service collection_invoice at /invoices>
request = <Request at 0x104a490a0 POST http://localhost/invoices>
def default_error_handler(self, request):
"""Default error_handler.
Uses the renderer for the service to render `request.errors`.
Only works if the registered renderer for the Service exposes the
method `render_errors`, which is implemented by default by
:class:`cornice.renderer.CorniceRenderer`.
:param request: the current Request.
"""
renderer = request.registry.queryUtility(
IRendererFactory, name=self.renderer
)
> return renderer.render_errors(request)
E AttributeError: 'JSON' object has no attribute 'render_errors'
../../.virtualenvs/cloud_service/lib/python3.9/site-packages/cornice/service.py:228: AttributeError
I don't use the default JSON renderer, I wanted to use simplejson and marshmallow, so I replaced it with:
json_renderer = JSON(serializer=simplejson.dumps)
json_renderer.add_adapter(decimal.Decimal, simplejson.dumps)
config.add_renderer("json", json_renderer)
Is my renderer setup incorrect? I looked at the Cornice API, but I'm a bit stuck trying to figure it out.
Thanks,
Sergi