pyircbot/tests/modules/test_nickuser.py

99 lines
3.3 KiB
Python
Raw Normal View History

2017-11-27 19:04:22 -08:00
import pytest
from contextlib import closing
from tests.lib import * # NOQA - fixtures
# TODO:
# - Responds to pms where the dest != the bot's nick
@pytest.fixture
def nickbot(fakebot):
"""
Provide a bot loaded with the Calc module. Clear the database.
"""
fakebot.botconfig["module_configs"]["Calc"] = {
"allowDelete": True,
"delaySubmit": 0,
"delayCalc": 0,
"delayCalcSpecific": 0,
"delayMatch": 0}
fakebot.loadmodule("SQLite")
with closing(fakebot.moduleInstances["SQLite"].opendb("attributes.db")) as db:
2017-12-03 20:54:39 -08:00
for table in ["attribute", "items", "values"]:
db.query("DROP TABLE IF EXISTS `{}`;".format(table))
2017-11-27 19:04:22 -08:00
fakebot.loadmodule("AttributeStorageLite")
fakebot.loadmodule("NickUser")
return fakebot
def pm(nickbot, line):
nickbot.feed_line(line, args=['bot'])
def test_blind_login(nickbot):
pm(nickbot, ".login foobar")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.login: You must first set a password with .setpass')
2017-12-03 20:54:39 -08:00
def test_no_pms(nickbot):
nickbot.feed_line(".login foobar")
nickbot.act_PRIVMSG.assert_not_called()
2017-11-27 19:04:22 -08:00
def test_register(nickbot):
2017-12-03 20:54:39 -08:00
pm(nickbot, ".setpass")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: usage: ".setpass newpass" or ".setpass oldpass newpass"')
nickbot.act_PRIVMSG.reset_mock()
2017-11-27 19:04:22 -08:00
pm(nickbot, ".setpass foobar")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: Your password has been set to "foobar".')
nickbot.act_PRIVMSG.reset_mock()
def test_register_login(nickbot):
test_register(nickbot)
2017-12-03 20:54:39 -08:00
pm(nickbot, ".login")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.login: usage: ".login password"')
nickbot.act_PRIVMSG.reset_mock()
2017-11-27 19:04:22 -08:00
pm(nickbot, ".login foobar")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.login: You have been logged in from: cia.gov')
nickbot.act_PRIVMSG.reset_mock()
def test_badpass(nickbot):
test_register(nickbot)
pm(nickbot, ".login oopsie")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.login: incorrect password.')
2017-12-02 23:48:44 -08:00
def test_change_needspass(nickbot):
test_register(nickbot)
pm(nickbot, ".setpass oopsie")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: You must provide the old password when setting a new one.')
2017-11-27 19:04:22 -08:00
def test_logout(nickbot):
test_register_login(nickbot)
pm(nickbot, ".logout")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.logout: You have been logged out.')
nickbot.act_PRIVMSG.reset_mock()
pm(nickbot, ".logout")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.logout: You must first be logged in')
def test_changepass(nickbot):
test_register_login(nickbot)
pm(nickbot, ".setpass foobar newpass")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: Your password has been set to "newpass".')
nickbot.act_PRIVMSG.reset_mock()
pm(nickbot, ".setpass wrong newpass2")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: Old password incorrect.')
2017-12-02 23:48:44 -08:00
def test_check(nickbot):
test_register_login(nickbot)
mod = nickbot.moduleInstances["NickUser"]
assert mod.check("chatter", "cia.gov")
assert not mod.check("chatter", "not-valid.hostname")
pm(nickbot, ".logout")
assert not mod.check("chatter", "cia.gov")