""" file: test_server.py adds server functionality-tests for pytest date: 11.07.2019 """ import pytest def test_ping(server): assert server.ping(server, "tolsun.oulu.fi") == "PONG" @pytest.mark.parametrize("test_input,expected", [("password", True), ("wrong password", False)]) def test_command_pass(server, test_input, expected): """ Command: PASS Parameters: The PASS command is used to set a 'connection password'. The password can and must be set before any attempt to register the connection is made. Currently this requires that clients send a PASS command before sending the NICK/USER combination and servers *must* send a PASS command before any SERVER command. The password supplied must match the one contained in the C/N lines (for servers) or I lines (for clients). It is possible to send multiple PASS commands before registering but only the last one sent is used for verification and it may not be changed once registered. Numeric Replies: ERR_NEEDMOREPARAMS ERR_ALREADYREGISTRED Example: PASS secretpasswordhere """ server.password = "password" 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, user_to_change, nickname, expected_result", [ (create_user_list(), "user2", "wayne", True), (create_user_list(), "user2", "user4", True), (create_user_list(), "user2", "christoph", True), (create_user_list(), "user2", "user19", True)]) def test_change_nickname(server, user_list,user_to_change, nickname, expected_result): """ Command: NICK Parameters: [ ] NICK message is used to give user a nickname or change the previous one. The parameter is only used by servers to indicate how far away a nick is from its home server. A local connection has a hopcount of 0. If supplied by a client, it must be ignored. If a NICK message arrives at a server which already knows about an identical nickname for another client, a nickname collision occurs. As a result of a nickname collision, all instances of the nickname are removed from the server's database, and a KILL command is issued to remove the nickname from all other server's database. If the NICK message causing the collision was a nickname change, then the original (old) nick must be removed as well. If the server recieves an identical NICK from a client which is directly connected, it may issue an ERR_NICKCOLLISION to the local client, drop the NICK command, and not generate any kills. """ server.user_list = create_user_list() assert server.command_nickname(server, user_to_change, nickname) == expected_result assert user_to_change not in server.user_list if nickname not in user_list: assert nickname in server.user_list else: assert nickname not in server.user_list