def test_414_with_description(self, client): description = 'Be short please.' client.app.add_route('/414', UriTooLongResource(description=description)) response = client.simulate_request(path='/414', headers={}) parsed_body = json.loads(response.content.decode()) assert parsed_body['description'] == description
def deserialize(self, stream, content_type, content_length): try: return json.loads(stream.read().decode('utf-8')) except ValueError as err: raise errors.HTTPBadRequest( 'Invalid JSON', 'Could not parse JSON body - {0}'.format(err) )
def deserialize(self, raw): try: return json.loads(raw.decode('utf-8')) except ValueError as err: raise errors.HTTPBadRequest( 'Invalid JSON', 'Could not parse JSON body - {0}'.format(err) )
def deserialize(self, raw): try: return json.loads(raw.decode('utf-8')) except ValueError as err: raise errors.HTTPBadRequest( 'Invalid JSON', 'Could not parse JSON body - {0}'.format(err) )
def deserialize(self, stream, content_type, content_length): try: return json.loads(stream.read().decode('utf-8')) except ValueError as err: raise errors.HTTPBadRequest( 'Invalid JSON', 'Could not parse JSON body - {0}'.format(err) )
def deserialize(self, raw): try: obj = json.loads(raw.decode('utf-8')) if self.contract_in_camel_case: obj = self.snake_case_keys(obj) return obj except ValueError as err: raise falcon.errors.HTTPBadRequest( 'Invalid JSON', 'Could not parse JSON body - {0}'.format(err))
def test_simulate_json_body(self, document): app = falcon.API() resource = testing.SimpleTestResource() app.add_route('/', resource) json_types = ('application/json', 'application/json; charset=UTF-8') client = testing.TestClient(app) client.simulate_post('/', json=document) captured_body = resource.captured_req.bounded_stream.read().decode('utf-8') assert json.loads(captured_body) == document assert resource.captured_req.content_type in json_types headers = { 'Content-Type': 'x-falcon/peregrine', 'X-Falcon-Type': 'peregrine', } body = 'If provided, `json` parameter overrides `body`.' client.simulate_post('/', headers=headers, body=body, json=document) assert resource.captured_req.media == document assert resource.captured_req.content_type in json_types assert resource.captured_req.get_header('X-Falcon-Type') == 'peregrine'
def test_simulate_json_body(self, asgi, document): resource = testing.SimpleTestResourceAsync() if asgi else testing.SimpleTestResource() app = create_app(asgi) app.add_route('/', resource) json_types = ('application/json', 'application/json; charset=UTF-8') client = testing.TestClient(app) client.simulate_post('/', json=document, headers={'capture-req-body-bytes': '-1'}) assert json.loads(resource.captured_req_body.decode()) == document assert resource.captured_req.content_type in json_types headers = { 'Content-Type': 'x-falcon/peregrine', 'X-Falcon-Type': 'peregrine', 'capture-req-media': 'y' } body = 'If provided, `json` parameter overrides `body`.' client.simulate_post('/', headers=headers, body=body, json=document) assert resource.captured_req_media == document assert resource.captured_req.content_type in json_types assert resource.captured_req.get_header('X-Falcon-Type') == 'peregrine'
def test_simulate_json_body(self, document): app = falcon.API() resource = testing.SimpleTestResource() app.add_route('/', resource) json_types = ('application/json', 'application/json; charset=UTF-8') client = testing.TestClient(app) client.simulate_post('/', json=document) captured_body = resource.captured_req.bounded_stream.read().decode('utf-8') assert json.loads(captured_body) == document assert resource.captured_req.content_type in json_types headers = { 'Content-Type': 'x-falcon/peregrine', 'X-Falcon-Type': 'peregrine', } body = 'If provided, `json` parameter overrides `body`.' client.simulate_post('/', headers=headers, body=body, json=document) assert resource.captured_req.media == document assert resource.captured_req.content_type in json_types assert resource.captured_req.get_header('X-Falcon-Type') == 'peregrine'
def test_414_with_title(self, client): title = 'Argh! Error!' client.app.add_route('/414', UriTooLongResource(title=title)) response = client.simulate_request(path='/414', headers={}) parsed_body = json.loads(response.content.decode()) assert parsed_body['title'] == title
def json(self) -> Optional[Union[dict, list, str, int, float, bool]]: if not self.text: return None return util_json.loads(self.text)
def json(self): if not self.text: return None return util_json.loads(self.text)
def test_414_with_description(self, client): description = 'Be short please.' client.app.add_route('/414', UriTooLongResource(description=description)) response = client.simulate_request(path='/414', headers={}) parsed_body = json.loads(response.content.decode()) assert parsed_body['description'] == description
def test_414_with_title(self, client): title = 'Argh! Error!' client.app.add_route('/414', UriTooLongResource(title=title)) response = client.simulate_request(path='/414', headers={}) parsed_body = json.loads(response.content.decode()) assert parsed_body['title'] == title
def json(self): if not self.text: return None return util_json.loads(self.text)
def test_414_with_custom_kwargs(self, client): code = 'someid' client.app.add_route('/414', UriTooLongResource(code=code)) response = client.simulate_request(path='/414', headers={}) parsed_body = json.loads(response.content.decode()) assert parsed_body['code'] == code
def test_414_with_custom_kwargs(self, client): code = 'someid' client.app.add_route('/414', UriTooLongResource(code=code)) response = client.simulate_request(path='/414', headers={}) parsed_body = json.loads(response.content.decode()) assert parsed_body['code'] == code
def json(self): return util_json.loads(self.text)
def json(self): return util_json.loads(self.text)