def test_select_parser_failed(self): negotiation = DefaultNegotiation() parsers = [JSON, URLEncodedForm] headers = {'Content-Type': 'application/xml'} with app.test_request_context(headers=headers): with self.assertRaises(exceptions.UnsupportedMediaType): renderer, media_type = negotiation.select_parser(parsers)
def test_select_renderer_failed(self): negotiation = DefaultNegotiation() renderers = [JSON, HTML] headers = {'Accept': 'application/xml'} with app.test_request_context(headers=headers): with self.assertRaises(exceptions.NotAcceptable): renderer, media_type = negotiation.select_renderer(renderers)
def test_select_renderer_no_accept_header(self): negotiation = DefaultNegotiation() renderers = [JSON, HTML] with app.test_request_context(): renderer, media_type = negotiation.select_renderer(renderers) self.assertEqual(renderer, JSON) self.assertEqual(str(media_type), 'application/json')
def test_select_renderer_no_accept_header(self): negotiation = DefaultNegotiation() renderers = [JSON, HTML] with app.test_request_context(): renderer, media_type = negotiation.select_renderer(renderers) assert renderer == JSON assert str(media_type) == 'application/json'
def test_select_parser(self): negotiation = DefaultNegotiation() parsers = [JSON, URLEncodedForm] headers = {'Content-Type': 'application/x-www-form-urlencoded'} with app.test_request_context(headers=headers): renderer, media_type = negotiation.select_parser(parsers) self.assertEqual(renderer, URLEncodedForm) self.assertEqual(str(media_type), 'application/x-www-form-urlencoded')
def test_select_renderer_server_preference(self): negotiation = DefaultNegotiation() renderers = [JSON, HTML] headers = {'Accept': '*/*'} with app.test_request_context(headers=headers): renderer, media_type = negotiation.select_renderer(renderers) self.assertEqual(renderer, JSON) self.assertEqual(str(media_type), 'application/json')
def test_select_rendered_client_preference(self): negotiation = DefaultNegotiation() renderers = [JSON, HTML] headers = {'Accept': 'application/json; q=0.5, application/html'} with app.test_request_context(headers=headers): renderer, media_type = negotiation.select_renderer(renderers) self.assertEqual(renderer, JSON) self.assertEqual(str(media_type), 'application/json')
def test_select_renderer_server_preference(self): negotiation = DefaultNegotiation() renderers = [JSON, HTML] headers = {'Accept': '*/*'} with app.test_request_context(headers=headers): renderer, media_type = negotiation.select_renderer(renderers) assert renderer == JSON assert str(media_type) == 'application/json'