def test_clear(xon_server): pm = PlayerManager() pm.join(Player(xon_server, b'test', 1, 2, '127.0.0.1')) pm.join(Player(xon_server, b'bot1', 2, 3, 'bot')) pm.join(Player(xon_server, b'bot2', 3, 4, 'bot')) pm.clear() assert len(pm.players_by_number2) == 0 assert len(pm.players_by_number1) == 0
def test_clear_bots(xon_server): pm = PlayerManager() pm.join(Player(xon_server, b'test', 1, 2, '127.0.0.1')) pm.join(Player(xon_server, b'bot1', 2, 3, 'bot')) pm.join(Player(xon_server, b'bot2', 3, 4, 'bot')) assert len(pm.players_by_number2) == 3 assert len(pm.players_by_number1) == 3 pm.clear_bots() assert len(pm.players_by_number2) == 1 assert len(pm.players_by_number1) == 1 assert pm.players_by_number1[1].nickname == b'test'
def test_chat_message_handler_cmd(xanmel, xon_module, xon_server, mocked_coro): xon_server.players.join( Player(xon_server, b'meme police ', 1, 2, '127.0.0.1')) xon_server.players.join(Player(xon_server, b'test ', 3, 4, '127.0.0.1')) msg = b'^3meme police ^7: xanmel: excuse' h = xanmel.handlers[ChatMessage][0] xon_server.local_cmd_root.run = mocked_coro() ev = ChatMessage(xon_module, message=msg, server=xon_server) xanmel.loop.run_until_complete(h.handle(ev)) assert xon_server.local_cmd_root.run.call_count == 1 assert xon_server.local_cmd_root.run.call_args[0][0].name == 'meme police ' assert xon_server.local_cmd_root.run.call_args[0][1] == ' excuse'
def test_scores_clear_zombies(log_parser, mocker, xon_server, example_scores): mocker.patch.object(GameEnded, '__init__', return_value=None) mocker.patch.object(GameEnded, 'fire') mocker.patch.object(Part, '__init__', return_value=None) mocker.patch.object(Part, 'fire', return_value=None) p = Player(xon_server, b'test', 1, 2, '127.0.0.1') xon_server.players.join(p) xon_server.players.join(Player(xon_server, b'FPM', 4, 7, '127.0.0.1')) xon_server.players.join( Player(xon_server, b'^x26FDarth Silvius^7', 7, 3, '127.0.0.1')) log_parser.feed(example_scores) assert Part.fire.call_count == 1 assert Part.__init__.call_args[1]['player'] == p
def test_part_handler(xanmel, xon_module, xon_server, mocked_coro): xon_server.config['show_geolocation_for'] = 'all' xon_server.players.max = 12 xon_server.players.join( Player(xon_server, b'meme police ', 1, 2, '127.0.0.1')) p = Player(xon_server, b'test ', 3, 4, '45.32.238.255') ev = Part(xon_module, player=p, server=xon_server) h = xanmel.handlers[Part][0] h.run_action = mocked_coro() xanmel.loop.run_until_complete(h.handle(ev)) assert h.run_action.called msg = h.run_action.call_args[1]['message'] assert '[\x03041\x0f/\x030412\x0f]' in msg assert 'Netherlands' in msg assert 'test' in msg
def test_who(xanmel, xon_module, xon_server, dummy_chat_user, irc_module): xon_server.players.join(Player(xon_server, b'test', 1, 2, '127.0.0.1')) xon_server.players.join(Player(xon_server, b'test2', 2, 3, '127.0.0.1')) chat_user = dummy_chat_user(module=irc_module, name=''.join( random.sample(string.ascii_letters, 10))) chat_user.user_type = 'irc' xanmel.loop.run_until_complete( xanmel.cmd_root.run(chat_user, 'xon who', is_private=False)) assert chat_user.public_reply.call_args[0][ 0] == 'exe > test\x0f | test2\x0f' xon_server.players.join(Player(xon_server, b'[BOT] Eureka', 3, 4, 'bot')) xanmel.loop.run_until_complete( xanmel.cmd_root.run(chat_user, 'xon who', is_private=False)) assert chat_user.public_reply.call_args[0][ 0] == 'exe > test\x0f | test2\x0f | 1 bots'
def test_part(xon_server): pm = PlayerManager() pm.join(Player(xon_server, b'test', 1, 2, '127.0.0.1')) pm.part(1) assert len(pm.players_by_number2) == 0 assert len(pm.players_by_number1) == 0 pm.part(10) assert len(pm.players_by_number2) == 0 assert len(pm.players_by_number1) == 0
def test_part(log_parser, mocker): srv = log_parser.rcon_server mocker.patch.object(Part, '__init__', return_value=None) mocker.patch.object(Part, 'fire', return_value=None) p = Player(srv, b'test', 1, 2, '127.0.0.1') srv.players.join(p) log_parser.feed(b':part:1\n') assert Part.fire.call_count == 1 assert Part.__init__.call_args[1]['player'] is p
def test_part_bot(log_parser, mocker): srv = log_parser.rcon_server mocker.patch.object(Part, '__init__', return_value=None) mocker.patch.object(Part, 'fire', return_value=None) p = Player(srv, b'test', 1, 2, 'bot') srv.players.join(p) log_parser.feed(b':part:1\n') assert Part.fire.call_count == 0 assert len(srv.players.players_by_number1) == 0
def test_game_started_handler(xanmel, xon_module, xon_server, mocked_coro, mocker): mocker.patch.object(xon_server, 'send') xon_server.players.max = 12 xon_server.players.join( Player(xon_server, b'meme police ', 1, 2, '127.0.0.1')) xon_server.players.join(Player(xon_server, b'test ', 3, 4, '127.0.0.1')) ev = GameStarted(xon_module, server=xon_server, gt='dm', map='darkzone') for i in xanmel.handlers[GameStarted]: if isinstance(i, GameStartedHandler): h = i h.run_action = mocked_coro() xanmel.loop.run_until_complete(h.handle(ev)) assert h.run_action.called assert h.run_action.call_args[0][0] is ChannelMessage msg = h.run_action.call_args[1]['message'] assert '[2/12]' in msg assert 'darkzone' in msg assert 'deathmatch' in msg
def test_name_change(log_parser, mocker): srv = log_parser.rcon_server mocker.patch.object(NameChange, '__init__', return_value=None) mocker.patch.object(NameChange, 'fire', return_value=None) p = Player(srv, b'test', 1, 2, '127.0.0.1') srv.players.join(p) log_parser.feed(b':name:1:barbaz\n') assert NameChange.fire.call_count == 1 assert NameChange.__init__.call_args[1]['old_nickname'] == b'test' assert srv.players.players_by_number1[1].nickname == b'barbaz' log_parser.feed(b':name:5:barbaz\n') assert NameChange.fire.call_count == 1
def test_join_handler(xanmel, xon_module, xon_server, mocked_coro, mocker): xon_server.config['show_geolocation_for'] = 'all' xon_server.players.max = 12 mocker.patch.object(xon_server, 'send') xon_server.players.join( Player(xon_server, b'meme police ', 1, 2, '127.0.0.1')) p = Player(xon_server, b'test ', 3, 4, '45.32.238.255') xon_server.players.join(p) ev = Join(xon_module, player=p, server=xon_server) h = xanmel.handlers[Join][0] h.run_action = mocked_coro() xanmel.loop.run_until_complete(h.handle(ev)) assert h.run_action.called assert h.run_action.call_args[0][0] is ChannelMessage msg = h.run_action.call_args[1]['message'] assert '[\x03042\x0f/\x030412\x0f]' in msg assert 'Netherlands' in msg assert 'test' in msg p = Player(xon_server, b'test123', 5, 6, '127.0.0.1') xon_server.players.join(p) ev = Join(xon_module, player=p, server=xon_server) xanmel.loop.run_until_complete(h.handle(ev)) msg = h.run_action.call_args[1]['message'] assert 'Unknown' in msg
def test_name_change_handler(xanmel, xon_module, xon_server, mocked_coro): p = Player(xon_server, b'meme police ', 1, 2, '127.0.0.1') xon_server.players.join(p) xon_server.players.name_change(1, b'foobar') ev = NameChange(xon_module, player=p, old_nickname=b'meme police ', server=xon_server) h = xanmel.handlers[NameChange][0] h.run_action = mocked_coro() xanmel.loop.run_until_complete(h.handle(ev)) assert h.run_action.called msg = h.run_action.call_args[1]['message'] assert 'meme police' in msg assert 'is known as' in msg assert 'foobar' assert msg.index('meme police') < msg.index('foobar')
def test_repr(xon_server): pm = PlayerManager() p = Player(xon_server, b'test', 1, 2, '127.0.0.1') assert str(p) == "b'test'" pm.join(p) assert str(pm) == '1: test'
def test_name_change(xon_server): pm = PlayerManager() pm.join(Player(xon_server, b'test', 1, 2, '127.0.0.1')) pm.name_change(1, b'barbaz') assert pm.players_by_number1[1].nickname == b'barbaz' assert pm.players_by_number2[2].nickname == b'barbaz'
def test_join_override(xon_server): pm = PlayerManager() pm.join(Player(xon_server, b'test', 1, 2, '127.0.0.1')) pm.join(Player(xon_server, b'test', 3, 2, '127.0.0.1')) assert pm.players_by_number1[3].nickname == b'test' assert 1 not in pm.players_by_number1
def test_get_elo(xon_server): pm = PlayerManager() pm.join(Player(xon_server, b'test', 1, 2, '127.0.0.1'))