Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #40 from gridsmartercities/bump_version
Browse files Browse the repository at this point in the history
Added docs for  and bumped version number to 0.3.2
  • Loading branch information
jamsidedown authored Mar 26, 2020
2 parents 969ec1a + 329150a commit ad72efd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ WSTest is the main test running class in pywsitest. It currently has the followi
- **with_response_timeout**: set the timeout in seconds for the test runner to wait for a response from the websocket
- **with_message_timeout**: set the timeout in seconds for the test runner to wait while trying to send a message to the websocket
- **with_test_timeout**: set the timeout in seconds for the test runner to run for
- **with_received_response_logging**: enable logging of received responses on response timeout error
- **run**: asyncronously run the test runner, sending all messages and listening for responses
- **is_complete**: check whether all expected responses have been received and messages have been sent

Expand All @@ -38,6 +39,8 @@ WSMessage is a class to represent a message to send to the websocket
- **with_delay**: add a delay to the message to be sent to the websocket host

## Examples

### Response testing
Testing a response with a body is received on connection to a websocket host:
```py
from pywsitest import WSTest, WSResponse
Expand Down Expand Up @@ -137,6 +140,7 @@ await ws_test.run()
assert ws_test.is_complete()
```

### Message sending
Sending a message on connection to a websocket host:
```py
from pywsitest import WSTest, WSMessage
Expand Down Expand Up @@ -183,7 +187,7 @@ await ws_test.run()
assert ws_test.is_complete()
```

Triggering a message to be sent with extracted list data when the following response is received:
Triggering a message to be sent with the first colour extracted from a list when the following response is received:
```json
{
"body": [
Expand Down Expand Up @@ -214,6 +218,59 @@ await ws_test.run()
assert ws_test.is_complete()
```

### Error handling
Force a test to fail is execution takes more than 30 seconds (default 60 seconds)
```py
ws_test = (
WSTest("wss://example.com")
.with_test_timeout(30)
.with_response(
WSResponse()
.with_attribute("body")
)
)

await ws_test.run()

assert ws_test.is_complete()
```

Force a test to fail if no response is received for 15 seconds (default 10 seconds)
- Any responses that haven't been sent will be output along with the `WSTimeoutError`
- Received responses can be output too by calling `with_received_response_logging` on the `WSTest` instance
```py
ws_test = (
WSTest("wss://example.com")
.with_response_timeout(15)
.with_received_response_logging()
.with_response(
WSResponse()
.with_attribute("body")
)
)

await ws_test.run()

assert ws_test.is_complete()
```

Force a test to fail is a message takes longer than 15 seconds to send (default 10 seconds)
- The message that the test runner failed to send will be output along with the `WSTimeoutError`
```py
ws_test = (
WSTest("wss://example.com")
.with_message_timeout(15)
.with_message(
WSMessage()
.with_attribute("body", "Hello, world!")
)
)

await ws_test.run()

assert ws_test.is_complete()
```

## Documentation
Users can get the docstring help by running:
```py
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
LONG_DESCRIPTION = open("README.md").read()

setup(name="pywsitest",
version="0.3.1",
version="0.3.2",
description="PYthon WebSocket Integration TESTing framework",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit ad72efd

Please sign in to comment.