Skip to content

Commit

Permalink
Revert "add an async context getter for tests which is easily patchab…
Browse files Browse the repository at this point in the history
…le."

This reverts commit 6198007.
  • Loading branch information
kristjanvalur committed Oct 13, 2024
1 parent c074e09 commit 373400f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
4 changes: 2 additions & 2 deletions tests/http/clients/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from strawberry.types import ExecutionResult
from tests.views.schema import Query, schema

from ..context import get_context_async as get_context
from ..context import get_context
from .base import (
JSON,
DebuggableGraphQLTransportWSHandler,
Expand All @@ -39,7 +39,7 @@ async def get_context(
) -> object:
context = await super().get_context(request, response)

return await get_context(context)
return get_context(context)

async def get_root_value(self, request: web.Request) -> Query:
await super().get_root_value(request) # for coverage
Expand Down
4 changes: 2 additions & 2 deletions tests/http/clients/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from strawberry.types import ExecutionResult
from tests.views.schema import Query, schema

from ..context import get_context_async as get_context
from ..context import get_context
from .base import (
JSON,
DebuggableGraphQLTransportWSHandler,
Expand Down Expand Up @@ -45,7 +45,7 @@ async def get_context(
) -> object:
context = await super().get_context(request, response)

return await get_context(context)
return get_context(context)

async def process_result(
self, request: Request, result: ExecutionResult
Expand Down
4 changes: 2 additions & 2 deletions tests/http/clients/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from strawberry.http.typevars import Context, RootValue
from tests.views.schema import Query, schema

from ..context import get_context, get_context_async
from ..context import get_context
from .base import (
JSON,
DebuggableGraphQLTransportWSHandler,
Expand Down Expand Up @@ -78,7 +78,7 @@ async def get_root_value(self, request: ChannelsConsumer) -> Optional[RootValue]
async def get_context(self, request: ChannelsConsumer, response: Any) -> Context:
context = await super().get_context(request, response)

return await get_context_async(context)
return get_context(context)

async def process_result(
self, request: ChannelsConsumer, result: Any
Expand Down
4 changes: 2 additions & 2 deletions tests/http/clients/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from strawberry.types import ExecutionResult
from tests.views.schema import Query, schema

from ..context import get_context_async as get_context
from ..context import get_context
from .asgi import AsgiWebSocketClient
from .base import (
JSON,
Expand All @@ -39,7 +39,7 @@ async def fastapi_get_context(
ws: WebSocket = None, # type: ignore
custom_value: str = Depends(custom_context_dependency),
) -> Dict[str, object]:
return await get_context(
return get_context(
{
"request": request or ws,
"background_tasks": background_tasks,
Expand Down
4 changes: 2 additions & 2 deletions tests/http/clients/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from strawberry.types import ExecutionResult
from tests.views.schema import Query, schema

from ..context import get_context_async as get_context
from ..context import get_context
from .base import (
JSON,
DebuggableGraphQLTransportWSHandler,
Expand All @@ -30,7 +30,7 @@


async def litestar_get_context(request: Request = None):
return await get_context({"request": request})
return get_context({"request": request})


async def get_root_value(request: Request = None):
Expand Down
15 changes: 0 additions & 15 deletions tests/http/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@


def get_context(context: object) -> Dict[str, object]:
return get_context_inner(context)


# a patchable method for unittests
def get_context_inner(context: object) -> Dict[str, object]:
assert isinstance(context, dict)
return {**context, "custom_value": "a value from context"}


# async version for async frameworks
async def get_context_async(context: object) -> Dict[str, object]:
return await get_context_async_inner(context)


# a patchable method for unittests
async def get_context_async_inner(context: object) -> Dict[str, object]:
assert isinstance(context, dict)
return {**context, "custom_value": "a value from context"}

0 comments on commit 373400f

Please sign in to comment.