Skip to content

Commit

Permalink
More imports
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Jul 14, 2023
1 parent 279878f commit 3396022
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 93 deletions.
18 changes: 7 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"-vv",
"--ignore=tests/mypy",
"--ignore=tests/pyright",
# TODO: reintroduce this in its own test session
"--ignore=tests/cli",
"--ignore=tests/experimental/pydantic",
"--ignore=tests/websockets",
]

INTEGRATIONS = [
Expand Down Expand Up @@ -45,10 +49,6 @@ def tests(session: Session) -> None:
"pytest",
*COMMON_PYTEST_OPTIONS,
*markers,
# TODO: reintroduce this
"--ignore=tests/cli",
"--ignore=tests/experimental/pydantic",
"--ignore=tests/websockets",
)


Expand All @@ -60,7 +60,7 @@ def tests_django(session: Session, django: str) -> None:
session._session.install(f"django~={django}") # type: ignore
session._session.install("pytest-django") # type: ignore

session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "django", "-m", "not aiohttp")
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "django")


@session(python=["3.11"], name="Starlette tests", tags=["tests"])
Expand All @@ -70,9 +70,7 @@ def tests_starlette(session: Session, starlette: str) -> None:

session._session.install(f"starlette=={starlette}") # type: ignore

session.run(
"pytest", *COMMON_PYTEST_OPTIONS, "-m", "starlette", "-m", "not aiohttp"
)
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "starlette")


@session(python=["3.11"], name="Test integrations", tags=["tests"])
Expand All @@ -98,9 +96,7 @@ def tests_integrations(session: Session, integration: str) -> None:
elif integration == "flask":
session._session.install("pytest-flask") # type: ignore

session.run(
"pytest", *COMMON_PYTEST_OPTIONS, "-m", integration, "-m", "not aiohttp"
)
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", integration)


@session(python=["3.11"], name="Pydantic tests", tags=["tests"])
Expand Down
18 changes: 14 additions & 4 deletions tests/aiohttp/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from typing import Any
from __future__ import annotations

from asyncio import BaseEventLoop
from typing import TYPE_CHECKING, Awaitable, Callable

import pytest
import pytest_asyncio

from strawberry.aiohttp.test.client import GraphQLTestClient

if TYPE_CHECKING:
from aiohttp.test_utils import TestClient


@pytest_asyncio.fixture
async def aiohttp_app_client(event_loop, aiohttp_client) -> Any:
async def aiohttp_app_client(
event_loop: BaseEventLoop, aiohttp_client: Callable[..., Awaitable[TestClient]]
) -> TestClient:
from tests.aiohttp.app import create_app

app = create_app(graphiql=True)
Expand All @@ -16,7 +24,9 @@ async def aiohttp_app_client(event_loop, aiohttp_client) -> Any:


@pytest_asyncio.fixture
async def aiohttp_app_client_no_get(event_loop, aiohttp_client) -> Any:
async def aiohttp_app_client_no_get(
event_loop: BaseEventLoop, aiohttp_client: Callable[..., Awaitable[TestClient]]
) -> TestClient:
from tests.aiohttp.app import create_app

app = create_app(graphiql=True, allow_queries_via_get=False)
Expand All @@ -25,5 +35,5 @@ async def aiohttp_app_client_no_get(event_loop, aiohttp_client) -> Any:


@pytest.fixture
def graphql_client(aiohttp_app_client) -> GraphQLTestClient:
def graphql_client(aiohttp_app_client: TestClient) -> GraphQLTestClient:
return GraphQLTestClient(aiohttp_app_client, url="/graphql")
37 changes: 31 additions & 6 deletions tests/aiohttp/test_websockets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Awaitable, Callable

from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL

from .app import create_app
if TYPE_CHECKING:
from aiohttp.test_utils import TestClient


async def test_turning_off_graphql_ws(aiohttp_client):
async def test_turning_off_graphql_ws(
aiohttp_client: Callable[..., Awaitable[TestClient]]
) -> None:
from .app import create_app

app = create_app(subscription_protocols=[GRAPHQL_TRANSPORT_WS_PROTOCOL])
aiohttp_app_client = await aiohttp_client(app)

Expand All @@ -17,7 +26,11 @@ async def test_turning_off_graphql_ws(aiohttp_client):
assert data.extra == "Subprotocol not acceptable"


async def test_turning_off_graphql_transport_ws(aiohttp_client):
async def test_turning_off_graphql_transport_ws(
aiohttp_client: Callable[..., Awaitable[TestClient]]
):
from .app import create_app

app = create_app(subscription_protocols=[GRAPHQL_WS_PROTOCOL])
aiohttp_app_client = await aiohttp_client(app)

Expand All @@ -31,7 +44,11 @@ async def test_turning_off_graphql_transport_ws(aiohttp_client):
assert data.extra == "Subprotocol not acceptable"


async def test_turning_off_all_ws_protocols(aiohttp_client):
async def test_turning_off_all_ws_protocols(
aiohttp_client: Callable[..., Awaitable[TestClient]]
):
from .app import create_app

app = create_app(subscription_protocols=[])
aiohttp_app_client = await aiohttp_client(app)

Expand All @@ -54,7 +71,11 @@ async def test_turning_off_all_ws_protocols(aiohttp_client):
assert data.extra == "Subprotocol not acceptable"


async def test_unsupported_ws_protocol(aiohttp_client):
async def test_unsupported_ws_protocol(
aiohttp_client: Callable[..., Awaitable[TestClient]]
):
from .app import create_app

app = create_app(subscription_protocols=[])
aiohttp_app_client = await aiohttp_client(app)

Expand All @@ -68,7 +89,11 @@ async def test_unsupported_ws_protocol(aiohttp_client):
assert data.extra == "Subprotocol not acceptable"


async def test_clients_can_prefer_protocols(aiohttp_client):
async def test_clients_can_prefer_protocols(
aiohttp_client: Callable[..., Awaitable[TestClient]]
):
from .app import create_app

app = create_app(
subscription_protocols=[GRAPHQL_WS_PROTOCOL, GRAPHQL_TRANSPORT_WS_PROTOCOL]
)
Expand Down
19 changes: 13 additions & 6 deletions tests/asgi/test_async.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import typing
from __future__ import annotations

from typing import TYPE_CHECKING, Optional

import pytest
from starlette.testclient import TestClient

import strawberry
from strawberry.asgi import GraphQL

if TYPE_CHECKING:
from starlette.testclient import TestClient


@pytest.fixture
def test_client() -> TestClient:
from starlette.testclient import TestClient

from strawberry.asgi import GraphQL

@strawberry.type
class Query:
@strawberry.field
async def hello(self, name: typing.Optional[str] = None) -> str:
async def hello(self, name: Optional[str] = None) -> str:
return f"Hello {name or 'world'}"

async_schema = strawberry.Schema(Query)
app = GraphQL(async_schema)
app = GraphQL[None, None](async_schema)
return TestClient(app)


def test_simple_query(test_client):
def test_simple_query(test_client: TestClient):
response = test_client.post("/", json={"query": "{ hello }"})

assert response.json() == {"data": {"hello": "Hello world"}}
27 changes: 24 additions & 3 deletions tests/asgi/test_websockets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import pytest
from starlette.testclient import TestClient
from starlette.websockets import WebSocketDisconnect

from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL
from tests.asgi.app import create_app


def test_turning_off_graphql_ws():
from starlette.testclient import TestClient
from starlette.websockets import WebSocketDisconnect

from tests.asgi.app import create_app

app = create_app(subscription_protocols=[GRAPHQL_TRANSPORT_WS_PROTOCOL])
test_client = TestClient(app)

Expand All @@ -18,6 +20,11 @@ def test_turning_off_graphql_ws():


def test_turning_off_graphql_transport_ws():
from starlette.testclient import TestClient
from starlette.websockets import WebSocketDisconnect

from tests.asgi.app import create_app

app = create_app(subscription_protocols=[GRAPHQL_WS_PROTOCOL])
test_client = TestClient(app)

Expand All @@ -29,6 +36,11 @@ def test_turning_off_graphql_transport_ws():


def test_turning_off_all_ws_protocols():
from starlette.testclient import TestClient
from starlette.websockets import WebSocketDisconnect

from tests.asgi.app import create_app

app = create_app(subscription_protocols=[])
test_client = TestClient(app)

Expand All @@ -46,6 +58,11 @@ def test_turning_off_all_ws_protocols():


def test_unsupported_ws_protocol():
from starlette.testclient import TestClient
from starlette.websockets import WebSocketDisconnect

from tests.asgi.app import create_app

app = create_app(subscription_protocols=[])
test_client = TestClient(app)

Expand All @@ -57,6 +74,10 @@ def test_unsupported_ws_protocol():


def test_clients_can_prefer_protocols():
from starlette.testclient import TestClient

from tests.asgi.app import create_app

app = create_app(
subscription_protocols=[GRAPHQL_WS_PROTOCOL, GRAPHQL_TRANSPORT_WS_PROTOCOL]
)
Expand Down
Loading

0 comments on commit 3396022

Please sign in to comment.