-
Notifications
You must be signed in to change notification settings - Fork 43
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
Question: Can I test websocket things? #61
Comments
Any protocol based on socket can be tested with it. |
I can not find about this. Where I can see docs? |
I have never experimented with WebSockets, just saying it's something you can achieve with Mocket. |
OK. I'll read code of Mocket and try test websocket things. Regardless how it ends up, I will write after story at this issue. |
Of course feel free to ask for help, and I will do my best to support you. |
from aiohttp.http import WS_KEY
from mocket.mocket import Mocket, Mocketizer
from mocket.mockhttp import Entry, Request, Response
class WebsocketResponse(Response):
def __init__(
self,
body: bytes=b'',
status: int=101,
headers: dict=None,
match_querystring: bool=True
) -> None:
import pdb
pdb.set_trace()
self.body = body
self.headers = headers or {}
self.status = status
self.match_querystring = match_querystring
self.set_base_headers()
@property
def data(self):
req: Request = Mocket.last_request()
req_headers = {k: v for k, v in req.headers.items()}
sec_accept = base64.b64encode(hashlib.sha1(
req_headers['Sec-Websocket-Key'].encode() + WS_KEY
).digest()).decode()
headers = {
'upgrade': 'websocket',
'connection': 'upgrade',
'sec-websocket-accept': sec_accept,
}
self.set_extra_headers(headers)
return self.get_protocol_data()
class WebsecketEntry(Entry):
response_cls = WebsocketResponse
@pytest.mark.asyncio
async def test_receive():
token = 'asdf1234'
sec_key = base64.b64encode(os.urandom(16))
with Mocketizer(None):
WebsecketEntry.single_register(
Entry.GET,
'http://slack.websocket.io',
status=101,
)
await websocket_things() I was defeated. |
I am not sure I got the purpose of your implementation of |
websocket require handshaking with client. without mocking os.urandom, I can not get |
I will have a look at it, since I'll be on holiday for the next two weeks. |
If you'd like to try something before I'll have a look, I suggest you to start recording a client/server session with |
I need to make dynamic result.
|
|
Sorry but it's been a tough period at home and I had no chance to look into it. It's true that |
What's the status of this? I'm interested on a WebSocket animal too. How can we move this forward? |
Hi @piranna, I believe you are more interested in the feature than the example shared above. |
Can I test websocket things such as aiohttp websocket client?
The text was updated successfully, but these errors were encountered: