def test_whois_user_without_trigger(protocol): data = [ ':server', '311', 'bot', 'socek', 'realsocek', 'onet.pl', '*', 'the socketor', ] execute_message(protocol, data) assert 'socek' not in protocol.whois_heap
def test_command_no_such_nick(protocol): data = [ ':server', '401', 'bot', 'socek', ':No such nick/channel', ] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert protocol.whois_heap == {} assert future.exception() == NoSuchNickError('socek')
def test_start_if_is_not_started(protocol): yield from [] # noqa - turn on global event_loop protocol.ready = False protocol.config['main']['channels'] = '#foo, #baar' execute_message(protocol, data) assert protocol.ready is True assert protocol.messages == [ Message('JOIN', '#foo'), Message('JOIN', '#baar'), ]
def test_whois_user(protocol): data = [ ':server', '311', 'bot', 'socek', 'realsocek', 'onet.pl', '*', 'the socketor', ] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert future.data.nick == 'socek' assert future.data.ircname == 'the socketor' assert future.data.host == 'onet.pl' assert future.data.realname == 'realsocek'
def test_command_no_such_nick(protocol): data = [ ':server', '401', 'bot', 'socek', ':No such nick/channel', ] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert protocol.whois_heap == {} assert future.exception() == NoSuchNickError('socek')
def test_notice(protocol_with_importer, event_loop): yield from [] # noqa - turn on global event_loop data = [':socek!a@b', 'NOTICE', '#czarnobyl', 'message'] ctrl = execute_message(protocol_with_importer, data) def check(ctrl): # wait for another coroutines importer = protocol_with_importer.importer assert protocol_with_importer.messages == [] assert importer.execute.assert_called_once_with( '#czarnobyl', User('socek!a@b'), 'message' ) ctrl.log.assert_called_once_with('#czarnobyl', '<socek> message') event_loop.call_soon(check, ctrl)
def test_notice(protocol_with_importer, event_loop): yield from [] # noqa - turn on global event_loop data = [':socek!a@b', 'NOTICE', '#czarnobyl', 'message'] ctrl = execute_message(protocol_with_importer, data) def check(ctrl): # wait for another coroutines importer = protocol_with_importer.importer assert protocol_with_importer.messages == [] assert importer.execute.assert_called_once_with( '#czarnobyl', User('socek!a@b'), 'message') ctrl.log.assert_called_once_with('#czarnobyl', '<socek> message') event_loop.call_soon(check, ctrl)
def test_kick_another_person(protocol): protocol.config['main']['nick'] = 'firemark' data = [':socek!a@b', 'KICK', '#czarnobyl', 'dimmur'] ctrl = execute_message(protocol, data) assert protocol.messages == [] ctrl.log.assert_called_once_with('#czarnobyl', 'socek KICK dimmur')
def test_part_with_reason(protocol): data = [':socek!a@b', 'PART', '#czarnobyl', 'dunno lol'] ctrl = execute_message(protocol, data) assert protocol.messages == [] ctrl.log.assert_called_once_with('#czarnobyl', 'socek::PART[dunno lol]')
def test_part_without_reason(protocol): ctrl = execute_message(protocol, [':socek!a@b', 'PART', '#czarnobyl']) assert protocol.messages == [] ctrl.log.assert_called_once_with('#czarnobyl', 'socek::PART')
def test_join(protocol): ctrl = execute_message(protocol, [':socek!a@b', 'JOIN', '#czarnobyl']) assert protocol.messages == [] ctrl.log.assert_called_once_with('#czarnobyl', 'socek(a@b)::JOIN')
def test_start_if_is_started(protocol): protocol.ready = True execute_message(protocol, data) assert protocol.messages == []
def test_whois_server(protocol): data = [':server', '312', 'bot', 'socek', 'banana server'] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert future.data.server == 'banana server'
def test_whois_idle(protocol): data = [':server', '317', 'bot', 'socek', '30', 'seconds idle'] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert future.data.idle == 30
def test_error(protocol): execute_message(protocol, ['ERROR']) assert protocol.messages == []
def test_ping(protocol): execute_message(protocol, ['PING', 'foobar']) assert protocol.messages == [Message('PONG', 'foobar')]
def test_whois_end(protocol): data = [':server', '318', 'bot', 'socek', 'End of /WHOIS list'] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert future.result() is future.data
def test_whois_account(protocol): data = [':server', '330', 'bot', 'socek', 'socketor'] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert future.data.account == 'socketor'
def test_whois_channels(protocol): data = [':server', '319', 'bot', 'socek', '#foo #bar'] future = protocol.whois_heap['socek'] = WhoisFuture() execute_message(protocol, data) assert future.data.channels == ['#foo', '#bar']
def test_pong(protocol): execute_message(protocol, ['PONG', 'foobar']) assert protocol.messages == [] assert protocol.ping_counter == 0
def test_kick_bot(protocol): protocol.config['main']['nick'] = 'firemark' data = [':socek!a@b', 'KICK', '#czarnobyl', 'firemark'] ctrl = execute_message(protocol, data) assert protocol.messages == [Message('JOIN', '#czarnobyl')] ctrl.log.assert_called_once_with('#czarnobyl', 'socek KICK firemark')