Browse Source

add RFC1459 4.1.2 Nick message

master
Wayne 5 years ago
parent
commit
f440ce18b7
  1. 8
      src/server.py
  2. 26
      test/test_server.py

8
src/server.py

@ -24,6 +24,14 @@ class Handler_TCPServer(socketserver.BaseRequestHandler):
def command_pass(self, param): def command_pass(self, param):
return param == self.password return param == self.password
def command_nickname(self, nickname):
if nickname not in self.user_list:
self.user_list.append(nickname)
return True
else:
return False
if __name__ == "__main__": if __name__ == "__main__":
HOST, PORT = "localhost", 9999 HOST, PORT = "localhost", 9999

26
test/test_server.py

@ -1,5 +1,9 @@
""" """
tests the server functionality
file: test_server.py
adds server functionality-tests for pytest
date: 11.07.2019
""" """
import pytest import pytest
@ -12,3 +16,23 @@ def test_ping(server):
def test_command_pass(server, test_input, expected): def test_command_pass(server, test_input, expected):
server.password = "password" server.password = "password"
assert server.command_pass(server, test_input) == expected assert server.command_pass(server, test_input) == expected
def create_user_list():
user_list = list()
user_id = "user"
for i in range(0, 9):
user_list.append((user_id + str(i)))
return user_list
@pytest.mark.parametrize("user_list, nickname, expected_result",
[
(create_user_list(), "wayne", True),
(create_user_list(), "user2", False),
(create_user_list(), "christoph", True),
(create_user_list(), "user19", True)])
def test_change_nickname(server, user_list, nickname, expected_result):
server.user_list = create_user_list()
assert server.command_nickname(server, nickname) == expected_result
Loading…
Cancel
Save