Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Feb 20, 2024
1 parent a7ce0c6 commit 615c0b0
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 117 deletions.
8 changes: 4 additions & 4 deletions tests/asgi/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
92 changes: 46 additions & 46 deletions tests/asgi/test_configuration.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tests/asgi/test_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@

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


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


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


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
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/asgi/test_http_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/asgi/test_query_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!*="}}

Expand Down
46 changes: 20 additions & 26 deletions tests/asgi/test_websockets_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand Down
Loading

0 comments on commit 615c0b0

Please sign in to comment.