Skip to main content

Websocket server for testing

Project description

Fake Websocket Server

Fake in the sense that it's actually a working server (created using websockets library) but one that that exists briefly to allow integration testing.

Installation

pip install fakewsserver

Usage

One message sent, one received, everything is as expected

from fakewsserver import assert_communication

async with assert_communication(
        port=12345,
        communication=[('hello', 'there')],
        ):
    async with websockets.connect('ws://localhost:12345') as client:
        await client.send('hello')
        response = await client.recv()

assert response == 'there'

Expected communication pattern does not match

communication = [
    ('hello', 'there'),
    ('general', 'Kenobi'),
]

async with assert_communication(
        port=12345,
        communication=communication,
        ):
    async with websockets.connect('ws://localhost:12345') as client:
        await client.send('hello')
        response = await client.recv()
        assert response == 'there'
        await client.send('admiral')
        await client.recv()

And there's a feedback what went wrong:

    AssertionError: Failed 2nd step:
    Expected: "general"
    Got: "admiral"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fakewsserver-0.2.1.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

fakewsserver-0.2.1-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page