Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Content-Disposition: form-data; name="map"
{ "0": ["variables.file"] }
--------------------------cec8e8123c05ba25
Content-Disposition: form-data; name="0"; filename="test.txt"
Content-Type: text/plain
test
--------------------------cec8e8123c05ba25--
""".strip()
request = create_multipart_request(data)
result = middleware(request, start_response)
start_response.assert_called_once_with(
HTTP_STATUS_400_BAD_REQUEST, error_response_headers
)
snapshot.assert_match(result)
def test_attempt_execute_query_with_invalid_variables_returns_error_json(
middleware,
start_response,
graphql_query_request_factory,
graphql_response_headers,
assert_json_response_equals_snapshot,
):
request = graphql_query_request_factory(query=complex_query, variables="invalid")
result = middleware(request, start_response)
start_response.assert_called_once_with(
HTTP_STATUS_400_BAD_REQUEST, graphql_response_headers
)
assert_json_response_equals_snapshot(result)
Content-Disposition: form-data; name="map"
not a json
--------------------------cec8e8123c05ba25
Content-Disposition: form-data; name="0"; filename="test.txt"
Content-Type: text/plain
test
--------------------------cec8e8123c05ba25--
""".strip()
request = create_multipart_request(data)
result = middleware(request, start_response)
start_response.assert_called_once_with(
HTTP_STATUS_400_BAD_REQUEST, error_response_headers
)
snapshot.assert_match(result)
def test_attempt_execute_query_without_query_entry_returns_error_json(
middleware,
start_response,
graphql_query_request_factory,
graphql_response_headers,
assert_json_response_equals_snapshot,
):
request = graphql_query_request_factory(variables=variables)
result = middleware(request, start_response)
start_response.assert_called_once_with(
HTTP_STATUS_400_BAD_REQUEST, graphql_response_headers
)
assert_json_response_equals_snapshot(result)
def return_response_from_result(
self, start_response: Callable, result: GraphQLResult
) -> List[bytes]:
success, response = result
status_str = HTTP_STATUS_200_OK if success else HTTP_STATUS_400_BAD_REQUEST
start_response(status_str, [("Content-Type", CONTENT_TYPE_JSON)])
return [json.dumps(response).encode("utf-8")]
def handle_graphql_error(
self, error: GraphQLError, start_response: Callable
) -> List[bytes]:
start_response(
HTTP_STATUS_400_BAD_REQUEST, [("Content-Type", CONTENT_TYPE_JSON)]
)
error_json = {"errors": [{"message": error.message}]}
return [json.dumps(error_json).encode("utf-8")]
def return_response_from_result(
self, start_response: Callable, result: GraphQLResult
) -> List[bytes]:
success, response = result
status_str = HTTP_STATUS_200_OK if success else HTTP_STATUS_400_BAD_REQUEST
start_response(status_str, [("Content-Type", CONTENT_TYPE_JSON)])
return [json.dumps(response).encode("utf-8")]
def handle_graphql_error(
self, error: GraphQLError, start_response: Callable
) -> List[bytes]:
start_response(
HTTP_STATUS_400_BAD_REQUEST, [("Content-Type", CONTENT_TYPE_JSON)]
)
error_json = {"errors": [{"message": error.message}]}
return [json.dumps(error_json).encode("utf-8")]