Skip to content

Commit 04ac4c9

Browse files
committed
Clean up testing and make unit tests to work with pytest
1 parent e582a6a commit 04ac4c9

File tree

4 files changed

+33
-47
lines changed

4 files changed

+33
-47
lines changed

tests/_bootstrap_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#Bootstrap
22
import sys, os
3-
if 'websocket-server' in os.getcwd():
3+
if os.getcwd().endswith('tests'):
44
sys.path.insert(0, '..')
5+
elif os.getcwd().endswith('websocket-server'):
6+
sys.path.insert(0, '.')

tests/handshake.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/test_handshake.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import _bootstrap_
2+
from websocket_server import *
3+
4+
class DummyWebsocketHandler(WebSocketHandler):
5+
def __init__(self, *_):
6+
pass
7+
8+
handler = DummyWebsocketHandler()
9+
10+
pairs = [
11+
# Key # Response
12+
('zyjFH2rQwrTtNFk5lwEMQg==', '2hnZADGmT/V1/w1GJYBtttUKASY='),
13+
('XJuxlsdq0QrVyKwA/D9D5A==', 'tZ5RV3pw7nP9cF+HDvTd89WJKj8=')
14+
]
15+
16+
def test_hash_calculations_for_response():
17+
key = 'zyjFH2rQwrTtNFk5lwEMQg=='
18+
resp = handler.calculate_response_key(key)
19+
assert resp == '2hnZADGmT/V1/w1GJYBtttUKASY='
20+
21+
def test_response_messages():
22+
key = 'zyjFH2rQwrTtNFk5lwEMQg=='
23+
expect = \
24+
'HTTP/1.1 101 Switching Protocols\r\n'\
25+
'Upgrade: websocket\r\n' \
26+
'Connection: Upgrade\r\n' \
27+
'Sec-WebSocket-Accept: 2hnZADGmT/V1/w1GJYBtttUKASY=\r\n'\
28+
'\r\n'
29+
resp = handler.make_handshake_response(key)
30+
assert resp == expect

websocket_server/websocket_server.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,3 @@ def try_decode_UTF8(data):
331331
return False
332332
except Exception as e:
333333
raise(e)
334-
335-
336-
# This is only for testing purposes
337-
class DummyWebsocketHandler(WebSocketHandler):
338-
def __init__(self, *_):
339-
pass

0 commit comments

Comments
 (0)