More tests
parent
585efb2c18
commit
e8652c37c8
@ -0,0 +1,41 @@
|
||||
import pytest
|
||||
from contextlib import closing
|
||||
from tests.lib import * # NOQA - fixtures
|
||||
from time import sleep
|
||||
import datetime
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rbot(fakebot):
|
||||
"""
|
||||
Provide a bot loaded with the Calc module. Clear the database.
|
||||
"""
|
||||
fakebot.botconfig["module_configs"]["Remind"] = {"mytimezone": "US/Pacific", "precision": 0.2}
|
||||
fakebot.loadmodule("SQLite")
|
||||
with closing(fakebot.moduleInstances["SQLite"].opendb("remind.db")) as db:
|
||||
db.query("DROP TABLE IF EXISTS `reminders`;")
|
||||
fakebot.loadmodule("Remind")
|
||||
return fakebot
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_remind_in(rbot):
|
||||
rbot.feed_line(".in 3s frig off")
|
||||
rbot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: Ok, talk to you in approx 0h0m')
|
||||
rbot.act_PRIVMSG.reset_mock()
|
||||
sleep(2.5)
|
||||
rbot.act_PRIVMSG.assert_not_called()
|
||||
sleep(1)
|
||||
rbot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: Reminder: frig off')
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_remind_at(rbot):
|
||||
then = datetime.datetime.now() + datetime.timedelta(seconds=3)
|
||||
rbot.feed_line(".at {} frig off".format(then.strftime("%H:%M:%SPDT")))
|
||||
rbot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: Ok, will do. Approx 0h0m to go.')
|
||||
rbot.act_PRIVMSG.reset_mock()
|
||||
sleep(2)
|
||||
rbot.act_PRIVMSG.assert_not_called()
|
||||
sleep(2)
|
||||
rbot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: Reminder: frig off')
|
@ -0,0 +1,87 @@
|
||||
from tests.lib import * # NOQA - fixtures
|
||||
|
||||
from unittest.mock import MagicMock, call
|
||||
from pyircbot.rpc import BotRPC
|
||||
from pyircbot.rpcclient import connect
|
||||
from random import randint
|
||||
from time import sleep
|
||||
|
||||
|
||||
def test_rpc(monkeypatch):
|
||||
port = randint(40000, 65000)
|
||||
m = MagicMock()
|
||||
m.botconfig = {"bot": {"rpcbind": "127.0.0.1", "rpcport": port}}
|
||||
server = BotRPC(m)
|
||||
sleep(0.05)
|
||||
|
||||
calltrack = MagicMock()
|
||||
|
||||
def fake(*args):
|
||||
calltrack(*args)
|
||||
return args
|
||||
|
||||
for k, v in server.server.funcs.items():
|
||||
server.server.funcs[k] = fake
|
||||
|
||||
methods = [["importModule", "foo"],
|
||||
["deportModule", "foo"],
|
||||
["loadModule", "foo"],
|
||||
["unloadModule", "foo"],
|
||||
["reloadModule", "foo"],
|
||||
["redoModule", "foo"],
|
||||
["getLoadedModules"],
|
||||
["pluginCommand", "foo", "foo", "foo"],
|
||||
["setPluginVar", "foo", "foo"],
|
||||
["getPluginVar", "foo", "foo", "foo"],
|
||||
["eval", "foo"],
|
||||
["exec", "foo"],
|
||||
["quit", "foo"]]
|
||||
|
||||
client = connect("127.0.0.1", port)
|
||||
|
||||
for test in methods:
|
||||
method = test[0]
|
||||
args = test[1:]
|
||||
server.server.funcs[method] = fake
|
||||
print("Calling {} with: {}".format(method, args))
|
||||
getattr(client, method)(*args)
|
||||
calltrack.assert_called_once_with(*args)
|
||||
calltrack.reset_mock()
|
||||
|
||||
|
||||
def test_rpc_internal(monkeypatch):
|
||||
port = randint(40000, 65000)
|
||||
m = MagicMock()
|
||||
m.botconfig = {"bot": {"rpcbind": "127.0.0.1", "rpcport": port}}
|
||||
server = BotRPC(m)
|
||||
|
||||
methods = [["importModule", "foo"],
|
||||
["deportModule", "foo"],
|
||||
["loadModule", "foo"],
|
||||
["unloadModule", "foo"],
|
||||
["redoModule", "foo"],]
|
||||
|
||||
for test in methods:
|
||||
method = test[0]
|
||||
args = test[1:]
|
||||
getattr(server, method)(*args)
|
||||
getattr(m, method.lower()).assert_called_once_with(*args)
|
||||
getattr(m, method.lower()).reset_mock()
|
||||
|
||||
m.moduleInstances = {"Foo": None, "Bar": None}
|
||||
assert server.getLoadedModules() == ["Foo", "Bar"]
|
||||
|
||||
m.reset_mock()
|
||||
|
||||
server.reloadModule("Foo")
|
||||
m.unloadmodule.assert_called_once_with("Foo")
|
||||
m.loadmodule.assert_called_once_with("Foo")
|
||||
|
||||
m.reset_mock()
|
||||
|
||||
# ["pluginCommand", "foo", "foo", "foo"],
|
||||
# ["setPluginVar", "foo", "foo"],
|
||||
# ["getPluginVar", "foo", "foo", "foo"]
|
||||
# ["eval", "foo"],
|
||||
# ["exec", "foo"],
|
||||
# ["quit", "foo"]]
|
Loading…
Reference in New Issue