gridsmartercities / pywsitest Goto Github PK
View Code? Open in Web Editor NEWPYthon WebSocket Integration TESTing framework
License: MIT License
PYthon WebSocket Integration TESTing framework
License: MIT License
There currently isn't a way to assert that an object with a certain property is present in a list/array of objects.
I'd like to be able to access an object in a list/array with or without an index, and assert that properties are present within that object
An alternative or future feature could be to allow a function that returns True/False on the response object.
Assuming the input json
{
"body": [
{"colour": "red"},
{"colour": "green"},
{"colour": "blue"}
]
}
It could be asserted that the first object has the colour red
with:
WSResponse().with_attribute("body[0]colour", "red")
It could be asserted that any object has the colour blue
with:
WSResponse().with_attribute("body[]colour", "blue")
# or
WSResponse().with_attribute("body[?]colour", "blue")
# or with any other special character
Method signature currently states that it takes a dict as the response, and while it may work for lists with a fixed/known index, the path.lstrip("/")
breaks lists where the index is not pre-defined.
I'd like for get_resolved_values
to be able to handle lists too, as lists are valid json roots, and to be able to handle cases where the index isn't known.
I would expect the following test to pass
def test_resolve_root_level_list(self):
ws_response = WSResponse().with_attribute("//colour", "blue")
test_data = [
{"colour": "red"},
{"colour": "green"},
{"colour": "blue"}
]
self.assertTrue(ws_response.is_match(test_data))
Hi
I need authorization by token in headers. Please add it.
Now I override method 'run' to adding 'extra_headers' to 'websockets.connect(...'
Thanks =)
Is your feature request related to a problem? Please describe.
cuz session save cookie
Describe the solution you'd like
session/cookie support
Is your feature request related to a problem? Please describe.
Currently all functionality is expected to be performed via websockets, however there are cases when a rest call may trigger a websocket response that needs to be tested.
Describe the solution you'd like
I want to be able to trigger rest requests to be sent when websocket responses are received. I would also like to be able to add triggers to the response from a rest request.
Describe alternatives you've considered
An alternative would be to have separate rest requests being made while a websocket test is running asynchronously.
Additional context
No additional context.
I have try with_received_response_logging
but can not see anything in the terminal.
Is it possible to print or log the response on websocket connect and message exchange to terminal with this library?
Thanks
Would be nice to handle and check for responses that aren't json based
E.g. asserting that the websocket tester receives a ping message
(
WSResponse()
.with_value("Ping")
)
Would be nice to be able to configure sleeps in triggered messages, to help with recreating user interactions
(
WSTest("wss://example.com")
.with_response(
WSResponse()
.with_attribute("body")
.with_trigger(
WSMessage()
.with_delay(5)
.with_attribute("message", "Hello")
)
)
)
wss:// works, ws:// doesn't
Set up a simple websocket server locally with python:
import asyncio
import websockets
async def handler(websocket, path):
await websocket.send("Hello")
start_server = websockets.serve(handler, "localhost", 7890)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
Use the WSTest class to connect to the websocket server:
import asyncio
from pywsitest import WSTest
ws_test = WSTest("ws://localhost:7890")
asyncio.get_event_loop().run_until_complete(ws_test.run())
Produces:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "/Users/robanderson/Documents/code/python/temp/env/lib/python3.7/site-packages/pywsitest/ws_test.py", line 169, in run
websocket = await websockets.connect(self._get_connection_string(), ssl=ssl.SSLContext())
File "/Users/robanderson/Documents/code/python/temp/env/lib/python3.7/site-packages/websockets/client.py", line 421, in __init__
"connect() received a ssl argument for a ws:// URI, "
ValueError: connect() received a ssl argument for a ws:// URI, use a wss:// URI to enable TLS
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.