def test_output_error(self): message = messages.Response(status_code=500) renderer = Json() vm = sample_view_model() vm.data['debug'] = False output = renderer._formatted_error(vm, context={'response': message}) assert output['name'] == 'Unknown Error'
def test_response(self): ioc = container.IocContainer() ioc.add('application.config', { 'cors': {}, }) route = routes.Literal(name='test', path='/', accepts=('GET', 'OPTIONS')) route_match = routes.RouteMatch(route=route, params={}) response = messages.Response() event = types.Event( name='test', params={ 'context': { 'response': response, 'request': messages.Request.from_environ( sample_environ(REQUEST_METHOD='OPTIONS')), 'route_match': route_match } }) listener = listeners.Request() listener.container = ioc listener(event) assert response._cors_processed
def test_expose_headers(self): request = messages.Request.from_environ(sample_environ()) response = messages.Response() utils.process_cors( request, response, **sample_cors_options(expose_headers=('authorization',))) assert response._cors_processed assert 'authorization' in response.headers.get('Access-Control-Expose-Headers')
def test_allow_credentials(self): request = messages.Request.from_environ(sample_environ()) response = messages.Response() utils.process_cors( request, response, **sample_cors_options(allow_credentials=True)) assert response._cors_processed assert response.headers.get('Access-Control-Allow-Credentials') == 'true'
def test_allow_origin_list(self): request = messages.Request.from_environ(sample_environ(HTTP_ORIGIN='http://127.0.0.1')) response = messages.Response() utils.process_cors( request, response, **sample_cors_options(allow_origin=('http://127.0.0.1', 'google.com'))) assert response._cors_processed assert 'http://127.0.0.1' == response.headers.get('Access-Control-Allow-Origin')
def test_allow_origin(self): request = messages.Request.from_environ(sample_environ()) response = messages.Response() utils.process_cors( request, response, **sample_cors_options()) assert response._cors_processed assert response.headers.get('Access-Control-Allow-Origin') == '*'
def test_preflight_check(self): request = messages.Request.from_environ(sample_environ(REQUEST_METHOD='OPTIONS')) response = messages.Response() options = sample_cors_options( allow_headers=('authorization',), allow_methods=('GET', 'OPTIONS')) utils.process_cors( request, response, **options) assert response._cors_processed assert 'authorization' in response.headers.get('Access-Control-Allow-Headers') assert utils.process_cors(request, response, **options)
def test_render(self): app = applications.Http() tb = toolbar.Toolbar( { 'panels': { 'tests.watson.framework.debug.support.Panel': {'enabled': True} } }, app, app.container.get('jinja2_renderer')) params = { 'context': { 'request': messages.Request.from_environ({}), 'response': messages.Response(200, body='<html><body></body></html>') }, 'view_model': views.Model(format='html') } event = types.Event('render', params=params) response = tb.render(event) assert '<!-- Injected Watson Debug Toolbar -->' in response.body
def test_status_code_serialize(self): self.controller.request = messages.Request.from_environ({}) self.controller.response = messages.Response() output = self.controller.error_action() assert self.controller.response.status_code == 406 assert 'message' in output