From 615c0b0980f92280f58ac91b9ffe908da6c9c17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Pito=C5=84?= Date: Tue, 20 Feb 2024 14:23:47 +0100 Subject: [PATCH] Fix tests --- tests/asgi/conftest.py | 8 +- tests/asgi/test_configuration.py | 92 +++++++++---------- tests/asgi/test_explorer.py | 10 +- tests/asgi/test_http_methods.py | 4 +- tests/asgi/test_query_execution.py | 2 +- .../test_websockets_graphql_transport_ws.py | 46 ++++------ tests/asgi/test_websockets_graphql_ws.py | 50 +++++----- .../fastapi/test_http_request.py | 2 +- .../fastapi/test_websocket_connection.py | 2 +- .../starlette/test_http_request.py | 2 +- .../starlette/test_websocket_connection.py | 2 +- 11 files changed, 103 insertions(+), 117 deletions(-) diff --git a/tests/asgi/conftest.py b/tests/asgi/conftest.py index e438a2141..a7034662a 100644 --- a/tests/asgi/conftest.py +++ b/tests/asgi/conftest.py @@ -41,19 +41,19 @@ def dummy_filter(args, _): @pytest.fixture def client(app): - return TestClient(app, backend="asyncio") + return TestClient(app) @pytest.fixture def client_graphql_ws_keepalive(app_graphql_ws_keepalive): - return TestClient(app_graphql_ws_keepalive, backend="asyncio") + return TestClient(app_graphql_ws_keepalive) @pytest.fixture def client_graphql_transport_ws(app_graphql_transport_ws): - return TestClient(app_graphql_transport_ws, backend="asyncio") + return TestClient(app_graphql_transport_ws) @pytest.fixture def client_for_tracing(app_with_tracing): - return TestClient(app_with_tracing, backend="asyncio") + return TestClient(app_with_tracing) diff --git a/tests/asgi/test_configuration.py b/tests/asgi/test_configuration.py index d8b938c28..e06e435fa 100644 --- a/tests/asgi/test_configuration.py +++ b/tests/asgi/test_configuration.py @@ -19,7 +19,7 @@ def test_custom_context_value_is_passed_to_resolvers(schema): app = GraphQL(schema, context_value={"test": "TEST-CONTEXT"}) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": "{ testContext }"}) assert response.json() == {"data": {"testContext": "TEST-CONTEXT"}} @@ -28,7 +28,7 @@ def test_custom_context_value_function_is_set_and_called_by_app(schema): get_context_value = Mock(return_value=True) app = GraphQL(schema, context_value=get_context_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ status }"}) get_context_value.assert_called_once_with(ANY, {"query": "{ status }"}) @@ -36,7 +36,7 @@ def test_custom_context_value_function_is_set_and_called_by_app(schema): def test_custom_context_value_function_result_is_passed_to_resolvers(schema): get_context_value = Mock(return_value={"test": "TEST-CONTEXT"}) app = GraphQL(schema, context_value=get_context_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": "{ testContext }"}) assert response.json() == {"data": {"testContext": "TEST-CONTEXT"}} @@ -48,7 +48,7 @@ async def get_context_value(*_): return {"test": "TEST-ASYNC-CONTEXT"} app = GraphQL(schema, context_value=get_context_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": "{ testContext }"}) assert response.json() == {"data": {"testContext": "TEST-ASYNC-CONTEXT"}} @@ -60,7 +60,7 @@ def get_context_value(request): return {"request": request} app = GraphQL(schema, context_value=get_context_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with pytest.deprecated_call(): client.post("/", json={"query": "{ status }"}) @@ -68,14 +68,14 @@ def get_context_value(request): def test_custom_root_value_is_passed_to_query_resolvers(schema): app = GraphQL(schema, root_value={"test": "TEST-ROOT"}) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": "{ testRoot }"}) assert response.json() == {"data": {"testRoot": "TEST-ROOT"}} def test_custom_root_value_is_passed_to_subscription_resolvers(schema): app = GraphQL(schema, root_value={"test": "TEST-ROOT"}) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -101,7 +101,7 @@ def test_custom_root_value_is_passed_to_subscription_resolvers_graphql_transport root_value={"test": "TEST-ROOT"}, websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -121,7 +121,7 @@ def test_custom_root_value_is_passed_to_subscription_resolvers_graphql_transport def test_custom_root_value_function_is_called_by_query(schema): get_root_value = Mock(return_value=True) app = GraphQL(schema, root_value=get_root_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ status }"}) get_root_value.assert_called_once() @@ -135,7 +135,7 @@ def get_root_value(_context, _document): app = GraphQL( schema, context_value={"test": "TEST-CONTEXT"}, root_value=get_root_value ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with pytest.deprecated_call(): client.post("/", json={"query": "{ status }"}) @@ -144,7 +144,7 @@ def get_root_value(_context, _document): def test_custom_root_value_function_is_called_by_subscription(schema): get_root_value = Mock(return_value=True) app = GraphQL(schema, root_value=get_root_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -166,7 +166,7 @@ def get_root_value(_context, _document): return True app = GraphQL(schema, root_value=get_root_value) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with pytest.deprecated_call(): with client.websocket_connect("/", ["graphql-ws"]) as ws: @@ -194,7 +194,7 @@ def test_custom_root_value_function_is_called_by_subscription_graphql_transport_ root_value=get_root_value, websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -223,7 +223,7 @@ def get_root_value(_context, _document): root_value=get_root_value, websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with pytest.deprecated_call(): with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: @@ -248,7 +248,7 @@ def test_custom_root_value_function_is_called_with_context_value(schema): context_value={"test": "TEST-CONTEXT"}, root_value=get_root_value, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ status }"}) get_root_value.assert_called_once_with({"test": "TEST-CONTEXT"}, None, None, ANY) @@ -256,7 +256,7 @@ def test_custom_root_value_function_is_called_with_context_value(schema): def test_custom_query_parser_is_used_for_http_query(schema): mock_parser = Mock(return_value=parse("{ status }")) app = GraphQL(schema, query_parser=mock_parser) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": "{ testContext }"}) assert response.json() == {"data": {"status": True}} mock_parser.assert_called_once() @@ -272,7 +272,7 @@ def test_custom_query_parser_is_used_for_http_query(schema): def test_custom_query_validator_is_used_for_http_query_error(schema, errors): mock_validator = Mock(return_value=errors) app = GraphQL(schema, query_validator=mock_validator) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": "{ testContext }"}) if errors: assert response.json() == {"errors": [{"message": "Nope"}]} @@ -286,7 +286,7 @@ def test_custom_validation_rule_is_called_by_query_validation( ): spy_validation_rule = mocker.spy(validation_rule, "__init__") app = GraphQL(schema, validation_rules=[validation_rule]) - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ status }"}) spy_validation_rule.assert_called_once() @@ -297,7 +297,7 @@ def test_custom_validation_rules_function_is_set_and_called_on_query_execution( spy_validation_rule = mocker.spy(validation_rule, "__init__") get_validation_rules = Mock(return_value=[validation_rule]) app = GraphQL(schema, validation_rules=get_validation_rules) - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ status }"}) get_validation_rules.assert_called_once() spy_validation_rule.assert_called_once() @@ -312,21 +312,21 @@ def test_custom_validation_rules_function_is_called_with_context_value( context_value={"test": "TEST-CONTEXT"}, validation_rules=get_validation_rules, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ status }"}) get_validation_rules.assert_called_once_with({"test": "TEST-CONTEXT"}, ANY, ANY) def test_query_over_get_is_executed_if_enabled(schema): app = GraphQL(schema, execute_get_queries=True) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/?query={status}") assert response.json() == {"data": {"status": True}} def test_query_over_get_is_executed_with_variables(schema): app = GraphQL(schema, execute_get_queries=True) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get( "/?query=query Hello($name:String) {hello(name: $name)}" "&operationName=Hello" @@ -337,7 +337,7 @@ def test_query_over_get_is_executed_with_variables(schema): def test_query_over_get_is_executed_without_operation_name(schema): app = GraphQL(schema, execute_get_queries=True) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get( "/?query=query Hello($name:String) {hello(name: $name)}" '&variables={"name": "John"}' @@ -347,7 +347,7 @@ def test_query_over_get_is_executed_without_operation_name(schema): def test_query_over_get_fails_if_operation_name_is_invalid(schema): app = GraphQL(schema, execute_get_queries=True) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get( "/?query=query Hello($name:String) {hello(name: $name)}" "&operationName=Invalid" @@ -366,7 +366,7 @@ def test_query_over_get_fails_if_operation_name_is_invalid(schema): def test_query_over_get_fails_if_operation_is_mutation(schema): app = GraphQL(schema, execute_get_queries=True) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get( "/?query=mutation Echo($text:String!) {echo(text: $text)}" "&operationName=Echo" @@ -385,7 +385,7 @@ def test_query_over_get_fails_if_operation_is_mutation(schema): def test_query_over_get_fails_if_variables_are_not_json_serialized(schema): app = GraphQL(schema, execute_get_queries=True) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get( "/?query=query Hello($name:String) {hello(name: $name)}" "&operationName=Hello" @@ -397,14 +397,14 @@ def test_query_over_get_fails_if_variables_are_not_json_serialized(schema): def test_query_over_get_is_not_executed_if_not_enabled(schema): app = GraphQL(schema, execute_get_queries=False) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/?query={ status }") assert response.status_code == 200 assert response.headers["CONTENT-TYPE"] == "text/html; charset=utf-8" def execute_failing_query(app): - client = TestClient(app, backend="asyncio") + client = TestClient(app) client.post("/", json={"query": "{ error }"}) @@ -432,7 +432,7 @@ def test_custom_logger_is_used_to_log_query_error(schema, mocker): def test_custom_logger_is_used_to_log_subscription_source_error(schema, mocker): logging_mock = mocker.patch("ariadne.logger.logging") app = GraphQL(schema, logger="custom") - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -459,7 +459,7 @@ def test_custom_logger_is_used_to_log_subscription_source_error_graphql_transpor logger="custom", websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -479,7 +479,7 @@ def test_custom_logger_is_used_to_log_subscription_source_error_graphql_transpor def test_custom_logger_is_used_to_log_subscription_resolver_error(schema, mocker): logging_mock = mocker.patch("ariadne.logger.logging") app = GraphQL(schema, logger="custom") - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -506,7 +506,7 @@ def test_custom_logger_is_used_to_log_subscription_resolver_error_graphql_transp logger="custom", websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -533,7 +533,7 @@ def test_custom_error_formatter_is_used_to_format_query_error(schema): def test_custom_error_formatter_is_used_to_format_subscription_syntax_error(schema): error_formatter = Mock(return_value=True) app = GraphQL(schema, error_formatter=error_formatter) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -561,7 +561,7 @@ def test_custom_error_formatter_is_used_to_format_subscription_syntax_error_grap error_formatter=error_formatter, websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -582,7 +582,7 @@ def test_custom_error_formatter_is_used_to_format_subscription_syntax_error_grap def test_custom_error_formatter_is_used_to_format_subscription_source_error(schema): error_formatter = Mock(return_value=True) app = GraphQL(schema, error_formatter=error_formatter) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -610,7 +610,7 @@ def test_custom_error_formatter_is_used_to_format_subscription_source_error_grap error_formatter=error_formatter, websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -631,7 +631,7 @@ def test_custom_error_formatter_is_used_to_format_subscription_source_error_grap def test_custom_error_formatter_is_used_to_format_subscription_resolver_error(schema): error_formatter = Mock(return_value=True) app = GraphQL(schema, error_formatter=error_formatter) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -659,7 +659,7 @@ def test_custom_error_formatter_is_used_to_format_subscription_resolver_error_gr error_formatter=error_formatter, websocket_handler=websocket_handler, ) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) ws.send_json( @@ -699,7 +699,7 @@ def resolve(self, next_, obj, info, **kwargs): def test_extension_from_option_are_passed_to_query_executor(schema): http_handler = GraphQLHTTPHandler(extensions=[CustomExtension]) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "hello, bob!"}} @@ -710,7 +710,7 @@ def get_extensions(*_): http_handler = GraphQLHTTPHandler(extensions=get_extensions) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "hello, bob!"}} @@ -721,7 +721,7 @@ async def get_extensions(*_): http_handler = GraphQLHTTPHandler(extensions=get_extensions) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "hello, bob!"}} @@ -734,7 +734,7 @@ def middleware(next_fn, *args, **kwargs): def test_middlewares_are_passed_to_query_executor(schema): http_handler = GraphQLHTTPHandler(middleware=[middleware]) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "**Hello, BOB!**"}} @@ -745,7 +745,7 @@ def get_middleware(*_): http_handler = GraphQLHTTPHandler(middleware=get_middleware) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "**Hello, BOB!**"}} @@ -756,7 +756,7 @@ async def get_middleware(*_): http_handler = GraphQLHTTPHandler(middleware=get_middleware) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "**Hello, BOB!**"}} @@ -768,7 +768,7 @@ def test_init_wait_timeout_graphql_transport_ws( connection_init_wait_timeout=timedelta(minutes=0) ) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with pytest.raises(WebSocketDisconnect) as exc_info: with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: @@ -787,7 +787,7 @@ def test_handle_connection_init_timeout_handler_executed_graphql_transport_ws( ) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) diff --git a/tests/asgi/test_explorer.py b/tests/asgi/test_explorer.py index 60b34a212..147095427 100644 --- a/tests/asgi/test_explorer.py +++ b/tests/asgi/test_explorer.py @@ -11,7 +11,7 @@ def test_default_explorer_html_is_served_on_get_request(schema, snapshot): app = GraphQL(schema) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/") assert response.status_code == 200 assert snapshot == response.text @@ -19,7 +19,7 @@ def test_default_explorer_html_is_served_on_get_request(schema, snapshot): def test_apollo_html_is_served_on_get_request(schema, snapshot): app = GraphQL(schema, explorer=ExplorerApollo()) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/") assert response.status_code == 200 assert snapshot == response.text @@ -27,7 +27,7 @@ def test_apollo_html_is_served_on_get_request(schema, snapshot): def test_graphiql_html_is_served_on_get_request(schema, snapshot): app = GraphQL(schema, explorer=ExplorerGraphiQL()) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/") assert response.status_code == 200 assert snapshot == response.text @@ -35,7 +35,7 @@ def test_graphiql_html_is_served_on_get_request(schema, snapshot): def test_playground_html_is_served_on_get_request(schema, snapshot): app = GraphQL(schema, explorer=ExplorerPlayground()) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/") assert response.status_code == 200 assert snapshot == response.text @@ -45,7 +45,7 @@ def test_405_bad_method_is_served_on_get_request_for_disabled_explorer( schema, snapshot ): app = GraphQL(schema, explorer=ExplorerHttp405()) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.get("/") assert response.status_code == 405 assert snapshot == response.text diff --git a/tests/asgi/test_http_methods.py b/tests/asgi/test_http_methods.py index 949950493..dc1302923 100644 --- a/tests/asgi/test_http_methods.py +++ b/tests/asgi/test_http_methods.py @@ -11,7 +11,7 @@ def test_options_method_is_supported(client): def test_options_response_excludes_get_if_introspection_is_disabled(schema): app = GraphQL(schema, introspection=False) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.options("/") assert response.status_code == 200 @@ -38,7 +38,7 @@ def test_delete_is_not_supported(client): def test_unsupported_method_response_excludes_get_if_introspection_is_disabled(schema): app = GraphQL(schema, introspection=False) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.patch("/") assert response.status_code == 405 diff --git a/tests/asgi/test_query_execution.py b/tests/asgi/test_query_execution.py index a8e61b783..910e5bae7 100644 --- a/tests/asgi/test_query_execution.py +++ b/tests/asgi/test_query_execution.py @@ -202,7 +202,7 @@ def test_middleware(next_fn, *args, **kwargs): extensions=[CustomExtension], middleware=[test_middleware] ) app = GraphQL(schema, http_handler=http_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) response = client.post("/", json={"query": '{ hello(name: "BOB") }'}) assert response.json() == {"data": {"hello": "=*Hello, BOB!*="}} diff --git a/tests/asgi/test_websockets_graphql_transport_ws.py b/tests/asgi/test_websockets_graphql_transport_ws.py index 94f48e802..5d8f1ad44 100644 --- a/tests/asgi/test_websockets_graphql_transport_ws.py +++ b/tests/asgi/test_websockets_graphql_transport_ws.py @@ -190,9 +190,7 @@ def test_custom_query_parser_is_used_for_subscription_over_websocket_transport_w websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-transport-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLTransportWSHandler.GQL_CONNECTION_ACK @@ -236,9 +234,7 @@ def test_custom_query_validator_is_used_for_subscription_over_websocket_transpor websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-transport-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLTransportWSHandler.GQL_CONNECTION_ACK @@ -280,9 +276,7 @@ def test_custom_query_parser_is_used_for_query_over_websocket_transport_ws( websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-transport-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLTransportWSHandler.GQL_CONNECTION_ACK @@ -370,7 +364,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLTransportWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -390,7 +384,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLTransportWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json( @@ -415,7 +409,7 @@ async def on_connect(websocket, payload): websocket_handler = GraphQLTransportWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json( @@ -437,7 +431,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLTransportWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -453,7 +447,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLTransportWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -468,7 +462,7 @@ def on_operation(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_operation=on_operation) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -503,7 +497,7 @@ async def on_operation(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_operation=on_operation) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -533,7 +527,7 @@ async def on_operation(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_operation=on_operation) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -564,7 +558,7 @@ def on_complete(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -593,7 +587,7 @@ def on_complete(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -629,7 +623,7 @@ async def on_complete(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -661,7 +655,7 @@ async def on_complete(websocket, operation): websocket_handler = GraphQLTransportWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -693,7 +687,7 @@ def on_disconnect(websocket): websocket_handler = GraphQLTransportWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -713,7 +707,7 @@ def on_disconnect(websocket): websocket_handler = GraphQLTransportWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -732,7 +726,7 @@ async def on_disconnect(websocket): websocket_handler = GraphQLTransportWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -752,7 +746,7 @@ async def on_disconnect(websocket): websocket_handler = GraphQLTransportWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) @@ -766,7 +760,7 @@ def test_too_many_connection_init_messages_graphql_transport_ws( ): handler = GraphQLTransportWSHandler() app = GraphQL(schema, websocket_handler=handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-transport-ws"]) as ws: ws.send_json({"type": GraphQLTransportWSHandler.GQL_CONNECTION_INIT}) diff --git a/tests/asgi/test_websockets_graphql_ws.py b/tests/asgi/test_websockets_graphql_ws.py index 0e1c5823f..abc2e2f01 100644 --- a/tests/asgi/test_websockets_graphql_ws.py +++ b/tests/asgi/test_websockets_graphql_ws.py @@ -146,9 +146,7 @@ def test_custom_query_parser_is_used_for_subscription_over_websocket( websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLWSHandler.GQL_CONNECTION_ACK @@ -188,9 +186,7 @@ def test_custom_query_validator_is_used_for_subscription_over_websocket(schema, websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLWSHandler.GQL_CONNECTION_ACK @@ -230,9 +226,7 @@ def test_custom_query_parser_is_used_for_query_over_websocket( websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLWSHandler.GQL_CONNECTION_ACK @@ -272,9 +266,7 @@ def test_custom_query_validator_is_used_for_query_over_websocket(schema, errors) websocket_handler=websocket_handler, ) - with TestClient(app, backend="asyncio").websocket_connect( - "/", ["graphql-ws"] - ) as ws: + with TestClient(app).websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) response = ws.receive_json() assert response["type"] == GraphQLWSHandler.GQL_CONNECTION_ACK @@ -337,7 +329,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -356,7 +348,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json( @@ -377,7 +369,7 @@ async def on_connect(websocket, payload): websocket_handler = GraphQLWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json( @@ -395,7 +387,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -412,7 +404,7 @@ def on_connect(websocket, payload): websocket_handler = GraphQLWSHandler(on_connect=on_connect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -428,7 +420,7 @@ def on_operation(websocket, operation): websocket_handler = GraphQLWSHandler(on_operation=on_operation) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -460,7 +452,7 @@ async def on_operation(websocket, operation): websocket_handler = GraphQLWSHandler(on_operation=on_operation) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -491,7 +483,7 @@ async def on_operation(websocket, operation): websocket_handler = GraphQLWSHandler(on_operation=on_operation) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -522,7 +514,7 @@ def on_complete(websocket, operation): websocket_handler = GraphQLWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -555,7 +547,7 @@ def on_complete(websocket, operation): websocket_handler = GraphQLWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -588,7 +580,7 @@ def on_complete(websocket, operation): websocket_handler = GraphQLWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -620,7 +612,7 @@ async def on_complete(websocket, operation): websocket_handler = GraphQLWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -653,7 +645,7 @@ async def on_complete(websocket, operation): websocket_handler = GraphQLWSHandler(on_complete=on_complete) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -683,7 +675,7 @@ def on_disconnect(websocket): websocket_handler = GraphQLWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -701,7 +693,7 @@ def on_disconnect(websocket): websocket_handler = GraphQLWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -718,7 +710,7 @@ async def on_disconnect(websocket): websocket_handler = GraphQLWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) @@ -736,7 +728,7 @@ async def on_disconnect(websocket): websocket_handler = GraphQLWSHandler(on_disconnect=on_disconnect) app = GraphQL(schema, websocket_handler=websocket_handler) - client = TestClient(app, backend="asyncio") + client = TestClient(app) with client.websocket_connect("/", ["graphql-ws"]) as ws: ws.send_json({"type": GraphQLWSHandler.GQL_CONNECTION_INIT}) diff --git a/tests_integrations/fastapi/test_http_request.py b/tests_integrations/fastapi/test_http_request.py index e1dba4236..58b9f827f 100644 --- a/tests_integrations/fastapi/test_http_request.py +++ b/tests_integrations/fastapi/test_http_request.py @@ -25,7 +25,7 @@ async def graphql_route(request: Request): app.mount("/mounted", graphql) -client = TestClient(app, backend="asyncio") +client = TestClient(app) def test_run_graphql_query_through_route(): diff --git a/tests_integrations/fastapi/test_websocket_connection.py b/tests_integrations/fastapi/test_websocket_connection.py index 1db1a03af..68537b172 100644 --- a/tests_integrations/fastapi/test_websocket_connection.py +++ b/tests_integrations/fastapi/test_websocket_connection.py @@ -47,7 +47,7 @@ async def graphql_route(websocket: WebSocket): app.mount("/mounted", graphql) -client = TestClient(app, backend="asyncio") +client = TestClient(app) def test_run_graphql_subscription_through_route(): diff --git a/tests_integrations/starlette/test_http_request.py b/tests_integrations/starlette/test_http_request.py index 702e1482d..21301d2f7 100644 --- a/tests_integrations/starlette/test_http_request.py +++ b/tests_integrations/starlette/test_http_request.py @@ -24,7 +24,7 @@ ) -client = TestClient(app, backend="asyncio") +client = TestClient(app) def test_run_graphql_query_through_route(): diff --git a/tests_integrations/starlette/test_websocket_connection.py b/tests_integrations/starlette/test_websocket_connection.py index c0d90a603..4e86b3151 100644 --- a/tests_integrations/starlette/test_websocket_connection.py +++ b/tests_integrations/starlette/test_websocket_connection.py @@ -45,7 +45,7 @@ async def counter_resolve(obj, *_): ], ) -client = TestClient(app, backend="asyncio") +client = TestClient(app) def test_run_graphql_subscription_through_route():