Esempio n. 1
0
def test_db_add(public_bot_with_db):
    yield from add_cmd(public_bot_with_db, 'firemark', 'firesmart')
    yield from add_cmd(public_bot_with_db, 'firemark', 'firesmark')

    with public_bot_with_db.protocol.get_session() as session:
        data = session.query(Message.message).filter_by(
            key='firemark',
            channel='#czarnobyl',
        ).all()

    assert set(o[0] for o in data) == {'firesmart', 'firesmark'}
    assert public_bot_with_db.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]
Esempio n. 2
0
def test_next_meet(public_bot):

    @asyncio.coroutine
    def get_html(url):
        return fromstring('''
            <h2>
                <span id="Najbli.C5.BCsze_spotkania_tematyczne">
                    lol title
                </span>
            </h2>
            <ul>
                <li>14 listopada 2015, 9:00 - 15:00 - Code retreat</li>
                <li>4 listopada 2015, 18:00 - MeetJS</li>
            </ul>
        ''')
    with freeze_time('2015-10-01 12:00:00'),\
            patch('grazyna.plugins.hs_wiki.get_html', get_html):
        yield from next_meet(public_bot)
        yield from next_meet(public_bot, position=2)
        yield from next_meet(public_bot, position=3)

    # position default(1): first newest
    # position 2: second newest
    # position 3: doesnt exist
    assert public_bot.protocol.messages == [
        SayMessage(
            '#czarnobyl',
            'socek: 4 listopada 2015, 18:00 - MeetJS [2 meets]',
        ),
        SayMessage(
            '#czarnobyl',
            'socek: 14 listopada 2015, 9:00 - 15:00 - Code retreat [2 meets]',
        ),
        SayMessage(
            '#czarnobyl',
            'socek: only 2 meets in calendar!',
        ),
    ]
Esempio n. 3
0
def test_admin_reload_config_without_plugins(mock_argv, mock_open, public_bot):
    mock_open.return_value = StringIO('''
[plugins]
ping = grazyna.plugins.ping
new_ping = grazyna.plugins.ping
    ''')
    yield from admin_plugins.reload_config(public_bot, 'no')

    importer = public_bot.protocol.importer
    assert importer.load.not_called
    assert importer.remove.not_called
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]
Esempio n. 4
0
def test_admin_rocket(mock_sleep, public_bot):
    public_bot.config['__nick__'] = 'grazyna'

    @asyncio.coroutine
    def whois_func(enemy):
        whois_data = WhoisData()
        whois_data.realname = 'foo'
        whois_data.host = 'bar'
        return whois_data

    public_bot.protocol.whois = whois_func

    yield from admin_plugins.rocket(public_bot, 'socek', n=2)

    # 2 + 1 to wait for ban
    assert mock_sleep.call_count == 3
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', '2...'),
        SayMessage('#czarnobyl', '1...'),
        SayMessage('#czarnobyl', 'FIRE!'),
        Message('MODE', '#czarnobyl', '+b', '*!foo@bar'),
        Message('KICK', '#czarnobyl', 'socek', ':Kaboom!'),
    ]
Esempio n. 5
0
def test_empty_trash(public_bot):

    @asyncio.coroutine
    def get_html(url):
        return fromstring('''
            <h2>
                <span id="Wyw.C3.B3z_.C5.9Bmieci">lol title</span>
            </h2>
            <ul></ul>
        ''')

    with freeze_time('2016-10-01 12:00:00'),\
            patch('grazyna.plugins.hs_wiki.get_html', get_html):
        yield from trash(public_bot)

    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: czysto i pięknie, uzupełnij wiki.'),
    ]
Esempio n. 6
0
def test_db_delete(public_bot_with_db):
    msg = Message()
    msg.channel = '#czarnobyl'
    msg.key = 'gjm'
    msg.message = '??'
    with public_bot_with_db.protocol.get_session() as session:
        session.add(msg)
        session.add(msg)

    yield from delete_cmd(public_bot_with_db, 'gjm')

    with public_bot_with_db.protocol.get_session() as session:
        obj = session.query(Message).filter_by(key='gjm',
                                               channel='#czarnobyl').first()
    assert obj is None
    assert public_bot_with_db.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]
Esempio n. 7
0
def test_next_meet_no_meets(public_bot):

    @asyncio.coroutine
    def get_html(url):
        return fromstring('''
            <h2>
                <span id="Najbli.C5.BCsze_spotkania_tematyczne">
                    lol title
                </span>
            </h2>
            <ul></ul>
        ''') 
    with freeze_time('2016-10-01 12:00:00'),\
            patch('grazyna.plugins.hs_wiki.get_html', get_html):
        yield from next_meet(public_bot)

    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: ¬_¬ no meetings'),
    ]
Esempio n. 8
0
def test_admin_reload_config(mock_argv, mock_open, public_bot):
    mock_open.return_value = StringIO('''
[plugins]
ping = grazyna.plugins.ping
new_ping = grazyna.plugins.ping
    ''')
    importer = public_bot.protocol.importer
    importer.plugins = {
        'ping': None,
        'old_ping': None,
    }

    yield from admin_plugins.reload_config(public_bot)

    importer.remove.assert_called_once_with('old_ping')
    importer.load.assert_called_once_with('new_ping', 'grazyna.plugins.ping')
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]
Esempio n. 9
0
def test_find_message_in_db(manager_with_db: ModuleManager):
    manager_with_db.load_all()
    with manager_with_db.protocol.get_session() as session:
        msg = Message()
        msg.channel = '#czarnobyl'
        msg.key = 'gjm'
        msg.message = '$0: $1gram juz miesiac; $@'
        session.add(msg)

    yield from manager_with_db.find_message_in_db(
        cmd='gjm',
        channel='#czarnobyl',
        text='lol kilo',
    )

    assert manager_with_db.protocol.messages == [
        SayMessage(
            '#czarnobyl',
            'lol: kilogram juz miesiac; lol kilo',
        )
    ]
Esempio n. 10
0
def test_admin_remove(public_bot):
    yield from admin_plugins.remove_plugin(public_bot, 'foobar')
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]
    public_bot.protocol.importer.remove.assert_called_once_with('foobar')
Esempio n. 11
0
def test_private_say(protocol):
    bot = make_bot(protocol)
    bot.private_say('foobar')
    assert protocol.messages == [SayMessage('socek', 'foobar')]
Esempio n. 12
0
def test_quakenet_auth(protocol):
    auth = QuakenetAuth('socek', 'klocek')
    auth.auth(protocol)
    assert protocol.messages == [
        SayMessage('*****@*****.**', 'AUTH socek klocek'),
    ]
Esempio n. 13
0
def test_rpn(public_bot):
    yield from rpn(public_bot, '2 2 +', 2)
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'Result: 4.0'),
    ]
Esempio n. 14
0
def test_pep(public_bot):
    yield from pep(public_bot, 8)
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl',
                   'socek: https://www.python.org/dev/peps/pep-0008/'),
    ]
Esempio n. 15
0
def test_reply(protocol):
    bot = make_bot(protocol)
    bot.reply('foobar')
    assert protocol.messages == [SayMessage('#czarnobyl', 'socek: foobar')]
Esempio n. 16
0
def test_quotes(get_replies_mock, public_bot):
    get_replies_mock.return_value = ['foobar']
    yield from quotes(public_bot)
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: foobar'),
    ]
Esempio n. 17
0
def test_admin_say_public(public_bot):
    yield from admin_plugins.say(public_bot, 'foobar')
    assert public_bot.protocol.messages == [SayMessage('#czarnobyl', 'foobar')]
Esempio n. 18
0
def test_db_delete_doesnt_exist(public_bot_with_db):
    yield from delete_cmd(public_bot_with_db, 'gjm')
    assert public_bot_with_db.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Key doesn\'t exist'),
    ]
Esempio n. 19
0
def test_lmgtfy(public_bot):
    yield from lmgtfy(public_bot, 'socek klocek')
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'http://lmgtfy.com/?q=socek%20klocek'),
    ]
Esempio n. 20
0
def test_admin_say_public_as_reply(public_bot):
    yield from admin_plugins.say(public_bot, 'bar', nick='foo', chan='#lol')
    assert public_bot.protocol.messages == [SayMessage('#lol', 'foo: bar')]
Esempio n. 21
0
def test_onp(public_bot):
    yield from onp(public_bot, '1234 1000 /', 2)
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'Result: 1.23'),
    ]
Esempio n. 22
0
def test_freenode_auth(protocol):
    auth = FreenodeAuth('klocek')
    auth.auth(protocol)
    assert protocol.messages == [
        SayMessage('nickserv', 'identify klocek'),
    ]
Esempio n. 23
0
def test_say(protocol):
    bot = make_bot(protocol)
    bot.say('foobar')
    assert protocol.messages == [SayMessage('#czarnobyl', 'foobar')]