Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Oct 13, 2024
1 parent 373400f commit c4d0b05
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
3 changes: 1 addition & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Release type: patch

Operations over `graphql-transport-ws` now create the Context and perform validation on
the worker `Task`, thus not blocking the websocket from accepting messages.
Fix error handling for query operations over graphql-transport-ws
4 changes: 4 additions & 0 deletions tests/http/clients/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
)


def custom_context_dependency() -> str:
return "Hi!"


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

Expand Down
14 changes: 7 additions & 7 deletions tests/views/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DebugInfo:
@strawberry.type
class Query:
@strawberry.field
def greetings(self) -> str: # pragma: no cover
def greetings(self) -> str:
return "hello"

@strawberry.field
Expand All @@ -91,13 +91,13 @@ async def async_hello(self, name: Optional[str] = None, delay: float = 0) -> str

@strawberry.field(permission_classes=[AlwaysFailPermission])
def always_fail(self) -> Optional[str]:
return "Hey" # pragma: no cover
return "Hey"

@strawberry.field(permission_classes=[ConditionalFailPermission])
def conditional_fail(
self, sleep: Optional[float] = None, fail: bool = False
) -> str:
return "Hey" # pragma: no cover
return "Hey"

Check warning on line 100 in tests/views/schema.py

View check run for this annotation

Codecov / codecov/patch

tests/views/schema.py#L100

Added line #L100 was not covered by tests

@strawberry.field
async def error(self, message: str) -> AsyncGenerator[str, None]:
Expand All @@ -108,7 +108,7 @@ async def exception(self, message: str) -> str:
raise ValueError(message)

@strawberry.field
def teapot(self, info: strawberry.Info[Any, None]) -> str: # pragma: no cover
def teapot(self, info: strawberry.Info[Any, None]) -> str:
info.context["response"].status_code = 418

return "🫖"
Expand Down Expand Up @@ -142,7 +142,7 @@ def set_header(self, info: strawberry.Info, name: str) -> str:
@strawberry.type
class Mutation:
@strawberry.mutation
def echo(self, string_to_echo: str) -> str: # pragma: no cover
def echo(self, string_to_echo: str) -> str:
return string_to_echo

@strawberry.mutation
Expand All @@ -162,7 +162,7 @@ def read_folder(self, folder: FolderInput) -> List[str]:
return list(map(_read_file, folder.files))

@strawberry.mutation
def match_text(self, text_file: Upload, pattern: str) -> str: # pragma: no cover
def match_text(self, text_file: Upload, pattern: str) -> str:
text = text_file.read().decode()
return pattern if pattern in text else ""

Expand Down Expand Up @@ -199,7 +199,7 @@ async def exception(self, message: str) -> AsyncGenerator[str, None]:
raise ValueError(message)

# Without this yield, the method is not recognised as an async generator
yield "Hi" # pragma: no cover
yield "Hi"

@strawberry.subscription
async def flavors(self) -> AsyncGenerator[Flavor, None]:
Expand Down
20 changes: 4 additions & 16 deletions tests/websockets/test_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,8 @@
from tests.http.clients.base import DebuggableGraphQLTransportWSHandler
from tests.views.schema import MyExtension, Schema

from ..http.clients.base import WebSocketClient

try:
from ..http.clients.fastapi import FastAPIHttpClient
except ImportError: # pragma: no cover
FastAPIHttpClient = None
try:
from ..http.clients.starlite import StarliteHttpClient
except ImportError: # pragma: no cover
StarliteHttpClient = None
try:
from ..http.clients.litestar import LitestarHttpClient
except ImportError: # pragma: no cover
LitestarHttpClient = None

if TYPE_CHECKING:
from ..http.clients.base import HttpClient
from ..http.clients.base import HttpClient, WebSocketClient


@pytest_asyncio.fixture
Expand Down Expand Up @@ -913,6 +898,9 @@ async def test_error_handler_for_timeout(http_client: HttpClient):
if isinstance(http_client, ChannelsHttpClient):
pytest.skip("Can't patch on_init for this client")

if not AsyncMock:
pytest.skip("Don't have AsyncMock")

ws = ws_raw
handler = None
errorhandler = AsyncMock()
Expand Down

0 comments on commit c4d0b05

Please sign in to comment.