Skip to content

Commit 282c56d

Browse files
committed
Refactor tests
1 parent 04ac4c9 commit 282c56d

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

tests/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
Testing
22
--------
33

4-
Run server
4+
Run unit tests
5+
6+
pytest
7+
8+
9+
Run functional tests
510

611
python message_lengths.py
712

tests/test_handshake.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import _bootstrap_
22
from websocket_server import *
3+
import pytest
4+
35

46
class DummyWebsocketHandler(WebSocketHandler):
57
def __init__(self, *_):
68
pass
79

8-
handler = DummyWebsocketHandler()
9-
10-
pairs = [
11-
# Key # Response
12-
('zyjFH2rQwrTtNFk5lwEMQg==', '2hnZADGmT/V1/w1GJYBtttUKASY='),
13-
('XJuxlsdq0QrVyKwA/D9D5A==', 'tZ5RV3pw7nP9cF+HDvTd89WJKj8=')
14-
]
10+
@pytest.fixture
11+
def websocket_handler():
12+
return DummyWebsocketHandler()
1513

16-
def test_hash_calculations_for_response():
14+
def test_hash_calculations_for_response(websocket_handler):
1715
key = 'zyjFH2rQwrTtNFk5lwEMQg=='
18-
resp = handler.calculate_response_key(key)
19-
assert resp == '2hnZADGmT/V1/w1GJYBtttUKASY='
16+
expected_key = '2hnZADGmT/V1/w1GJYBtttUKASY='
17+
assert websocket_handler.calculate_response_key(key) == expected_key
18+
2019

21-
def test_response_messages():
20+
def test_response_messages(websocket_handler):
2221
key = 'zyjFH2rQwrTtNFk5lwEMQg=='
23-
expect = \
22+
expected = \
2423
'HTTP/1.1 101 Switching Protocols\r\n'\
2524
'Upgrade: websocket\r\n' \
2625
'Connection: Upgrade\r\n' \
2726
'Sec-WebSocket-Accept: 2hnZADGmT/V1/w1GJYBtttUKASY=\r\n'\
2827
'\r\n'
29-
resp = handler.make_handshake_response(key)
30-
assert resp == expect
28+
handshake_content = websocket_handler.make_handshake_response(key)
29+
assert handshake_content == expected

0 commit comments

Comments
 (0)