def test_NefertariJsonRendererFactory_run_after_calls(self): factory = renderers.NefertariJsonRendererFactory(None) filters = { 'super_action': [lambda request, result: result + ' processed'], } request = mock.Mock(action='super_action', filters=filters) processed = factory.run_after_calls('foo', {'request': request}) assert processed == 'foo processed'
def test_render_response(self): system = self._system_mocks() system['request'].action = 'delete' mixin = renderers.NefertariJsonRendererFactory(None) mixin._render_response({'foo': 'bar'}, system) resp = system['request'].response.body resp = json.loads(resp.decode('utf-8')) assert sorted(resp.keys()) == sorted([ 'request_url', 'timestamp', 'title', 'status_code', 'explanation', 'message']) assert resp['message'] == 'Deleted' assert resp['status_code'] == 200
def test_render_response_no_method(self): system = self._system_mocks() system['request'].action = 'index' mixin = renderers.NefertariJsonRendererFactory(None) resp = mixin._render_response({'foo': 'bar'}, system) assert resp == '{"foo": "bar"}'
def test_render_response_no_request(self): system = self._system_mocks() system.pop('request') mixin = renderers.NefertariJsonRendererFactory(None) resp = mixin._render_response({'foo': 'bar'}, system) assert resp == '{"foo": "bar"}'
def test_NefertariJsonRendererFactory_run_after_calls_no_filters(self): factory = renderers.NefertariJsonRendererFactory(None) request = mock.Mock(action='action', filters={}) processed = factory.run_after_calls('foo', {'request': request}) assert processed == 'foo'