Skip to main content

PYthon WebSocket Integration TESTing framework

Project description

Grid Smarter Cities

Build Status License: MIT

pywsitest

PYthon WebSocket Integration TESTing framework

A python API to assist with automated websocket integration testing.

Installation

pip install pywsitest

Package contents

Examples

Testing a reponse with a body is received on connection to a websocket:

from pywsitest import WSTest, WSResponse

ws_test = (
    WSTest("wss://example.com")
    .with_response(
        WSResponse()
        .with_attribute("body")
    )
)

await ws_test.run()

assert ws_test.is_complete()

Testing a more complex set of responses and messages:

from pywsitest import WSTest, WSResponse, WSMessage

ws_test = (
    WSTest("wss://example.com")
    .with_parameter("Authorization", "eyJra...")
    .with_response_timeout(15) # 15 seconds
    .with_message_timeout(7.5)
    .with_test_timeout(45)
    .with_message(
        WSMessage()
        .with_attribute("type", "connect")
        .with_attribute("body", {"chatroom": "general"})
    )
    .with_response(
        WSResponse()
        .with_attribute("type", "connected")
        .with_trigger(
            WSMessage()
            .with_attribute("type", "message")
            .with_attribute("body", "Hello, world!")
        )
    )
    .with_response(
        WSResponse()
        .with_attribute("type", "message")
        .with_attribute("body", "Hello, world!")
    )
)

await ws_test.run()

assert ws_test.is_complete()

Documentation

Links

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

pywsitest-0.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

pywsitest-0.1-py3-none-any.whl (6.4 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