Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for WebSocket in TestClient #487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Randomneo
Copy link

@Randomneo Randomneo commented Mar 15, 2024

Great package. TY for your hard work. I'm really enjoying blacksheep so far. But it feels like its missing a bit of WebSocket testing support.

Added starlette like WebSocket testing.

from blacksheep import Application, WebSocket, ws
from blacksheep.testing import TestClient

app = Application()

@ws('/ws')
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    await websocket.send_text('hello world')

@pytest.mark.asyncio
async def test_test_websocket():
    await app.start()
    client = TestClient(app)
    async with client.websocket_connect('/ws') as websocket:
        received = await websocket.receive_text()
    assert received == 'hello world'

@Randomneo Randomneo force-pushed the feat/add-websocket-support-to-testclient branch from c1d7b62 to c363263 Compare March 15, 2024 20:35
@Randomneo Randomneo force-pushed the feat/add-websocket-support-to-testclient branch from c363263 to 86692e1 Compare March 15, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant