From d5e915934066c77a59d211efafca10c117b73d05 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 16 Sep 2020 21:31:15 +0100 Subject: Tests: migrated to the pytest. --- test/unit/applications/websockets.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test/unit/applications/websockets.py') diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index e0dd2c0d..f1ddf630 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -1,6 +1,7 @@ import base64 import hashlib import itertools +import pytest import random import re import select @@ -21,9 +22,6 @@ class TestApplicationWebsocket(TestApplicationProto): OP_PONG = 0x0A CLOSE_CODES = [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011] - def __init__(self, preinit=False): - self.preinit = preinit - def key(self): raw_key = bytes(random.getrandbits(8) for _ in range(16)) return base64.b64encode(raw_key).decode() @@ -56,7 +54,7 @@ class TestApplicationWebsocket(TestApplicationProto): while True: rlist = select.select([sock], [], [], 60)[0] if not rlist: - self.fail('Can\'t read response from server.') + pytest.fail('Can\'t read response from server.') resp += sock.recv(4096).decode() @@ -84,7 +82,7 @@ class TestApplicationWebsocket(TestApplicationProto): # For all current cases if the "read_timeout" was changed # than test do not expect to get a response from server. if read_timeout == 60: - self.fail('Can\'t read response from server.') + pytest.fail('Can\'t read response from server.') break data += sock.recv(bytes - len(data)) @@ -130,19 +128,19 @@ class TestApplicationWebsocket(TestApplicationProto): code, = struct.unpack('!H', data[:2]) reason = data[2:].decode('utf-8') if not (code in self.CLOSE_CODES or 3000 <= code < 5000): - self.fail('Invalid status code') + pytest.fail('Invalid status code') frame['code'] = code frame['reason'] = reason elif length == 0: frame['code'] = 1005 frame['reason'] = '' else: - self.fail('Close frame too short') + pytest.fail('Close frame too short') frame['data'] = data if frame['mask']: - self.fail('Received frame with mask') + pytest.fail('Received frame with mask') return frame -- cgit From dc49c561e204fd70008aa6af8c6171ef7d227db1 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 22 Sep 2020 12:40:35 +0300 Subject: Tests: improved response receiving while upgrade. The patch required to process non-101 response. --- test/unit/applications/websockets.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test/unit/applications/websockets.py') diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index f1ddf630..cb9f40aa 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -58,10 +58,7 @@ class TestApplicationWebsocket(TestApplicationProto): resp += sock.recv(4096).decode() - if ( - re.search('101 Switching Protocols', resp) - and resp[-4:] == '\r\n\r\n' - ): + if (resp.startswith('HTTP/') and '\r\n\r\n' in resp): resp = self._resp_to_dict(resp) break -- cgit From d97e3a3296db77f6a33ce010a66d2a0b2d4bac49 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 1 Oct 2020 23:55:35 +0300 Subject: Tests: added ASGI WebSocket. --- test/unit/applications/websockets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/applications/websockets.py') diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index cb9f40aa..bae40620 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -40,7 +40,7 @@ class TestApplicationWebsocket(TestApplicationProto): 'Upgrade': 'websocket', 'Connection': 'Upgrade', 'Sec-WebSocket-Key': key, - 'Sec-WebSocket-Protocol': 'chat', + 'Sec-WebSocket-Protocol': 'chat, phone, video', 'Sec-WebSocket-Version': 13, } -- cgit From 6ec0ff35964c7805712d978625949f72ff5a63bc Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 7 Oct 2020 23:18:43 +0100 Subject: Tests: minor fixes. --- test/unit/applications/websockets.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/unit/applications/websockets.py') diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index bae40620..cc720a98 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -1,12 +1,11 @@ import base64 import hashlib import itertools -import pytest import random -import re import select import struct +import pytest from unit.applications.proto import TestApplicationProto GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" -- cgit