This commit is contained in:
dave 2017-12-02 23:48:44 -08:00
parent 8606561074
commit f4c9f5fb92
9 changed files with 52 additions and 27 deletions

2
.gitignore vendored
View File

@ -7,3 +7,5 @@ __pycache__
/dist
/build
/pyircbot.egg-info
/.coverage
/htmlcov/

View File

@ -24,8 +24,6 @@ class LMGTFY(ModuleBase):
def createLink(self, message):
finalUrl = BASE_URL
if type(message) == str:
message = message.split(" ")
for word in message:
finalUrl += urllib.parse.quote(word)

View File

@ -9,11 +9,7 @@
from pyircbot.modulebase import ModuleBase
import sys
try:
import MySQLdb # python 2.x
except:
import pymysql as MySQLdb # python 3.x
import pymysql as MySQLdb # python 3.x
class MySQL(ModuleBase):

View File

@ -72,10 +72,11 @@ class Tell(ModuleBase):
recip = cmd.args[0]
message = ' '.join(cmd.args[1:]).strip()
if not message:
self.bot.act_PRIVMSG(msg.args[0], "%s: .tell <person> <message> - Tell someone something the next time "
"they're seen. Example: .tell antiroach Do your homework!" %
msg.prefix.nick)
c = self.db.query("SELECT COUNT(*) as `cnt` FROM `tells` WHERE `recip`=?;", (recip, ))
user_total = c.fetchall()[0]['cnt']
c.close()
if user_total >= self.config.get("max", 3):
return
self.db.query("INSERT INTO `tells` (`sender`, `channel`, `when`, `recip`, `message`) VALUES "

View File

@ -3,6 +3,7 @@ certifi==2017.4.17
chardet==3.0.4
cheroot==5.9.1
CherryPy==12.0.1
coverage==4.4.2
decorator==4.0.11
idna==2.5
ipdb==0.10.3
@ -10,6 +11,7 @@ ipython==6.0.0
ipython-genutils==0.2.0
jaraco.classes==1.4.3
jedi==0.10.2
lxml==4.1.1
mock==2.0.0
msgbus==0.0.1
packaging==16.8
@ -27,6 +29,7 @@ PyJWT==1.5.3
pyparsing==2.2.0
PySocks==1.6.7
pytest==3.2.5
pytest-cov==2.5.1
pytz==2017.3
pyzmq==16.0.2
requests==2.18.1

View File

@ -3,4 +3,4 @@
export PYTHONUNBUFFERED=1
export PYTHONPATH=.
py.test -s tests/
py.test --cov=pyircbot --cov-report html -s tests/

View File

@ -16,10 +16,10 @@ def calcbot(fakebot):
"delayMatch": 0}
fakebot.loadmodule("SQLite")
with closing(fakebot.moduleInstances["SQLite"].opendb("calc.db")) as db:
for q in ["DELETE FROM calc_addedby;",
"DELETE FROM calc_channels;",
"DELETE FROM calc_definitions;",
"DELETE FROM calc_words;"]:
for q in ["DROP TABLE calc_addedby;",
"DROP TABLE calc_channels;",
"DROP TABLE calc_definitions;",
"DROP TABLE calc_words;"]:
db.query(q)
fakebot.loadmodule("Calc")
return fakebot

View File

@ -1,19 +1,29 @@
import pytest
from tests.lib import * # NOQA - fixtures
from unittest.mock import call
@pytest.fixture
def bot(fakebot):
def helpbot(fakebot):
"""
Provide a bot loaded with the ModInfo module
"""
fakebot.loadmodule("ModInfo")
return fakebot
def test_help(bot):
bot.feed_line(".help")
bot.act_PRIVMSG.assert_called_once_with('#test',
'ModInfo: .help [command] show the manual for all or [commands]')
def test_helpindex(helpbot):
helpbot.feed_line(".helpindex")
helpbot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: commands: .help, .helpindex')
def test_helpindex(bot):
bot.feed_line(".helpindex")
bot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: commands: .help')
def test_help(helpbot):
helpbot.feed_line(".help")
helpbot.act_PRIVMSG.assert_has_calls([call('#test', 'ModInfo: .help [command] show the manual for all or [commands]'),
call('#test', 'ModInfo: .helpindex show a short list of all commands')],
any_order=True)
def test_help_one(helpbot):
helpbot.feed_line(".help .helpindex")
helpbot.act_PRIVMSG.assert_called_once_with('#test', 'RTFM: .helpindex: helpindex show a short list of all commands')

View File

@ -19,9 +19,9 @@ def nickbot(fakebot):
"delayMatch": 0}
fakebot.loadmodule("SQLite")
with closing(fakebot.moduleInstances["SQLite"].opendb("attributes.db")) as db:
for q in ["DELETE FROM attribute;",
"DELETE FROM items;",
"DELETE FROM `values`;"]:
for q in ["DROP TABLE attribute;",
"DROP TABLE items;",
"DROP TABLE `values`;"]:
db.query(q)
fakebot.loadmodule("AttributeStorageLite")
fakebot.loadmodule("NickUser")
@ -56,6 +56,12 @@ def test_badpass(nickbot):
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.login: incorrect password.')
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.')
def test_logout(nickbot):
test_register_login(nickbot)
pm(nickbot, ".logout")
@ -72,3 +78,12 @@ def test_changepass(nickbot):
nickbot.act_PRIVMSG.reset_mock()
pm(nickbot, ".setpass wrong newpass2")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: Old password incorrect.')
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")