Skip to content

Commit

Permalink
Fix imports for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn committed Oct 7, 2024
1 parent f5c5c87 commit 846a474
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions tests/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,54 @@
from typing import TYPE_CHECKING, AsyncGenerator

import pytest
from django.test.client import Client
from starlette.testclient import TestClient as AsgiTestClient

import aiohttp.web
from aiohttp.test_utils import TestClient as AiohttpTestClient
from aiohttp.test_utils import TestServer
from strawberry.aiohttp.test import GraphQLTestClient as AiohttpGraphQLTestClient
from strawberry.aiohttp.views import GraphQLView
from strawberry.asgi import GraphQL
from strawberry.asgi.test import GraphQLTestClient as AsgiGraphQLTestClient
from strawberry.django.test import GraphQLTestClient as DjangoGraphQLTestClient

from tests.views.schema import schema

if TYPE_CHECKING:
from strawberry.test import BaseGraphQLTestClient


@asynccontextmanager
async def aiohttp_graphql_client() -> AsyncGenerator[AiohttpGraphQLTestClient]:
async def aiohttp_graphql_client() -> AsyncGenerator[BaseGraphQLTestClient]:
try:
from aiohttp import web
from aiohttp.test_utils import TestClient, TestServer
from strawberry.aiohttp.test import GraphQLTestClient
from strawberry.aiohttp.views import GraphQLView
except ImportError:
pytest.skip("Aiohttp not installed")

view = GraphQLView(schema=schema)
app = aiohttp.web.Application()
app = web.Application()
app.router.add_route("*", "/graphql/", view)

async with AiohttpTestClient(TestServer(app)) as client:
yield AiohttpGraphQLTestClient(client)
async with TestClient(TestServer(app)) as client:
yield GraphQLTestClient(client)


@asynccontextmanager
async def asgi_graphql_client() -> AsyncGenerator[AsgiGraphQLTestClient]:
yield AsgiGraphQLTestClient(AsgiTestClient(GraphQL(schema)))
async def asgi_graphql_client() -> AsyncGenerator[BaseGraphQLTestClient]:
try:
from starlette.testclient import TestClient

from strawberry.asgi import GraphQL
from strawberry.asgi.test import GraphQLTestClient
except ImportError:
pytest.skip("Starlette not installed")

yield GraphQLTestClient(TestClient(GraphQL(schema)))


@asynccontextmanager
async def django_graphql_client() -> AsyncGenerator[DjangoGraphQLTestClient]:
yield DjangoGraphQLTestClient(Client())
async def django_graphql_client() -> AsyncGenerator[BaseGraphQLTestClient]:
try:
from django.test.client import Client

from strawberry.django.test import GraphQLTestClient
except ImportError:
pytest.skip("Django not installed")

yield GraphQLTestClient(Client())


@pytest.fixture(
Expand Down

0 comments on commit 846a474

Please sign in to comment.