def post(self): valid_params = PAGING_PARAMS with safe_params(valid_params): try: raw_body_params = json.loads(self.request.body) except ValueError: error_message = _("JSON malformed. Received: {0}.") raise HTTPError(400, log_message=error_message.format( self.request.body)) body_params = normalize_all_uris_recursively(raw_body_params) if '@context' in body_params: del body_params['@context'] validate_json_schema(body_params, SUGGEST_PARAM_SCHEMA) self.query_params = ParamDict(self, **valid_params) response = do_suggest(self.query_params, body_params) if self.query_params['expand_uri'] == "0": response = normalize_all_uris_recursively(response, mode=SHORTEN) self.finalize(response)
def put(self, query_id): validate_headers(self.request.headers) client_id = self.request.headers.get(CLIENT_ID_HEADER) client_id_dict = {"client_id": client_id} json_payload_object = get_json_request_as_dict(self.request.body) validate_json_schema(json_payload_object, query_crud_schema) json_payload_object.update(client_id_dict) # TODO return instance data when editing it? status = store_query(json_payload_object, query_id, client_id) self.finalize(status)
def put(self, query_id): validate_headers(self.request.headers) client_id = self.request.headers.get(CLIENT_ID_HEADER) client_id_dict = {"client_id": client_id} json_payload_object = get_json_request_as_dict(self.request.body) validate_json_schema(json_payload_object, query_crud_schema) json_payload_object.update(client_id_dict) # TODO return instance data when editing it? status = store_query(json_payload_object, query_id, client_id) self.finalize(status)
def post(self): valid_params = PAGING_PARAMS with safe_params(valid_params): self.query_params = ParamDict(self, **valid_params) raw_body_params = get_json_request_as_dict(self.request.body) body_params = normalize_all_uris_recursively(raw_body_params) if '@context' in body_params: del body_params['@context'] validate_json_schema(body_params, SUGGEST_PARAM_SCHEMA) response = do_suggest(self.query_params, body_params) if self.query_params['expand_uri'] == "0": response = normalize_all_uris_recursively(response, mode=SHORTEN) self.finalize(response)
def post(self): valid_params = PAGING_PARAMS with safe_params(valid_params): try: raw_body_params = json.loads(self.request.body) except ValueError: error_message = _("JSON malformed. Received: {0}.") raise HTTPError(400, log_message=error_message.format(self.request.body)) body_params = normalize_all_uris_recursively(raw_body_params) if '@context' in body_params: del body_params['@context'] validate_json_schema(body_params, SUGGEST_PARAM_SCHEMA) self.query_params = ParamDict(self, **valid_params) response = do_suggest(self.query_params, body_params) if self.query_params['expand_uri'] == "0": response = normalize_all_uris_recursively(response, mode=SHORTEN) self.finalize(response)
def test_valid_json_schema(self, mocked_validate): valid_json = {"items": []} validate_json_schema(valid_json, self.JSON_SCHEMA_EXAMPLE)
def test_valid_json_schema(self, mocked_validate): valid_json = {"items": []} validate_json_schema(valid_json, self.JSON_SCHEMA_EXAMPLE)