-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver_test.py
51 lines (39 loc) · 2.24 KB
/
server_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from server import create_response
def test_create_response_hello():
message_json = {"message": "/hello", "username": "sauceboss"}
fake_client = ("fake", "client")
response, clients = create_response(message_json, None, [fake_client])
assert clients == [fake_client]
assert response["username"] == "server"
assert response["message"] == "sauceboss joined the chat"
def test_create_response_who():
message_json = {"message": "/who", "username": "sauceboss"}
fake_sender = ("fakesender", "fakesenderport")
fake_clients = [("fake", "client"), ("fake2", "client2")]
response, clients = create_response(message_json, fake_sender, fake_clients)
assert clients == [fake_sender]
assert response["username"] == "server"
assert response["message"] == "people in room: fake, fake2"
def test_create_response_goodbye():
message_json = {"message": "/goodbye", "username": "sauceboss"}
fake_clients = [("fake", "client"), ("fake2", "client2")]
response, clients = create_response(message_json, fake_clients[0], fake_clients)
assert clients == [fake_clients[0]] # we removed the first client; the only client left is the 2nd one
assert response["message"] == "sauceboss left the chat"
assert response["username"] == "server"
def test_create_response_emote():
message_json = {"message": "/me waves", "username": "sauceboss", "color": 420}
fake_clients = [("fake", "client"), ("fake2", "client2")]
response, clients = create_response(message_json, fake_clients[0], fake_clients)
assert clients == fake_clients # we removed the first client; the only client left is the 2nd one
assert response["message"] == "sauceboss waves"
assert response["username"] == None
assert response["color"] == 420
def test_message():
message_json = {"message": "this is a test", "username": "sauceboss", "color": 420}
fake_clients = [("fake", "client"), ("fake2", "client2")]
response, clients = create_response(message_json, fake_clients[0], fake_clients)
assert clients == fake_clients # we removed the first client; the only client left is the 2nd one
assert response["message"] == "this is a test"
assert response["username"] == "sauceboss"
assert response["color"] == 420