Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_custom_context_value_function_is_called_with_request_value(schema):
get_context_value = Mock(return_value=True)
app = GraphQL(schema, context_value=get_context_value)
request = {"CONTENT_TYPE": DATA_TYPE_JSON}
app.execute_query(request, {"query": "{ status }"})
get_context_value.assert_called_once_with(request)
async def extract_data_from_request(self, request: Request):
content_type = request.headers.get("Content-Type", "")
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return await self.extract_data_from_json_request(request)
if content_type == DATA_TYPE_MULTIPART:
return await self.extract_data_from_multipart_request(request)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
def get_request_data(self, environ: dict) -> dict:
content_type = environ.get("CONTENT_TYPE", "")
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return self.extract_data_from_json_request(environ)
if content_type == DATA_TYPE_MULTIPART:
return self.extract_data_from_multipart_request(environ)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
def get_request_data(self, environ: dict) -> dict:
content_type = environ.get("CONTENT_TYPE", "")
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return self.extract_data_from_json_request(environ)
if content_type == DATA_TYPE_MULTIPART:
return self.extract_data_from_multipart_request(environ)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
def get_request_data(self, environ: dict) -> dict:
content_type = environ.get("CONTENT_TYPE", "")
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return self.extract_data_from_json_request(environ)
if content_type == DATA_TYPE_MULTIPART:
return self.extract_data_from_multipart_request(environ)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
async def extract_data_from_request(self, request: Request):
content_type = request.headers.get("Content-Type", "")
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return await self.extract_data_from_json_request(request)
if content_type == DATA_TYPE_MULTIPART:
return await self.extract_data_from_multipart_request(request)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
def extract_data_from_request(self, request: HttpRequest):
content_type = request.content_type or ""
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return self.extract_data_from_json_request(request)
if content_type == DATA_TYPE_MULTIPART:
return self.extract_data_from_multipart_request(request)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
def get_request_data(self, environ: dict) -> dict:
content_type = environ.get("CONTENT_TYPE", "")
content_type = content_type.split(";")[0]
if content_type == DATA_TYPE_JSON:
return self.extract_data_from_json_request(environ)
if content_type == DATA_TYPE_MULTIPART:
return self.extract_data_from_multipart_request(environ)
raise HttpBadRequestError(
"Posted content must be of type {} or {}".format(
DATA_TYPE_JSON, DATA_TYPE_MULTIPART
)
def get_request_data(self, body: bytes) -> dict:
for header, value in self.scope["headers"]:
if header == b"content-type" and value == DATA_TYPE_JSON.encode("utf-8"):
break
else:
raise HttpBadRequestError(
"Posted content must be of type {}".format(DATA_TYPE_JSON)
)
data = self.parse_request_body(body)
if not isinstance(data, dict):
raise GraphQLError("Valid request body should be a JSON object")
return data
def get_request_data(self, body: bytes) -> dict:
for header, value in self.scope["headers"]:
if header == b"content-type" and value == DATA_TYPE_JSON.encode("utf-8"):
break
else:
raise HttpBadRequestError(
"Posted content must be of type {}".format(DATA_TYPE_JSON)
)
data = self.parse_request_body(body)
if not isinstance(data, dict):
raise GraphQLError("Valid request body should be a JSON object")
return data