Skip to content

Commit

Permalink
adding typing to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Massakera committed Feb 14, 2024
1 parent 1b0ba84 commit 817715e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from starlette.responses import Response
from starlette.routing import WebSocketRoute
from starlette.testclient import TestClient, WebSocketDenialResponse
from starlette.types import Message, Receive, Scope, Send
from starlette.types import ASGIApp, Message, Receive, Scope, Send
from starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketState

TestClientFactory = Callable[..., TestClient]
Expand Down Expand Up @@ -638,8 +638,8 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:


@pytest.fixture
def test_app():
async def websocket_endpoint(websocket):
def test_app() -> ASGIApp:
async def websocket_endpoint(websocket: WebSocket) -> None:
await websocket.accept()
await websocket.send_text("This should not be reached")
await websocket.close()
Expand All @@ -653,15 +653,15 @@ async def websocket_endpoint(websocket):
return app


def test_websocket_request_invalid_host(test_app):
def test_websocket_request_invalid_host(test_app: ASGIApp) -> None:
client = TestClient(test_app)
with pytest.raises(WebSocketDisconnect) as exc_info:
with client.websocket_connect("/ws", headers={"Host": "invalidhost.com"}):
pass
assert exc_info.value.code == 4001


def test_websocket_request_without_host_header(test_app):
def test_websocket_request_without_host_header(test_app: ASGIApp) -> None:
client = TestClient(test_app)
with pytest.raises(WebSocketDisconnect) as exc_info:
with client.websocket_connect("/ws", headers={}):
Expand Down

0 comments on commit 817715e

Please sign in to comment.