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 /dist
/build /build
/pyircbot.egg-info /pyircbot.egg-info
/.coverage
/htmlcov/

View File

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

View File

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

View File

@ -72,10 +72,11 @@ class Tell(ModuleBase):
recip = cmd.args[0] recip = cmd.args[0]
message = ' '.join(cmd.args[1:]).strip() message = ' '.join(cmd.args[1:]).strip()
if not message: c = self.db.query("SELECT COUNT(*) as `cnt` FROM `tells` WHERE `recip`=?;", (recip, ))
self.bot.act_PRIVMSG(msg.args[0], "%s: .tell <person> <message> - Tell someone something the next time " user_total = c.fetchall()[0]['cnt']
"they're seen. Example: .tell antiroach Do your homework!" % c.close()
msg.prefix.nick)
if user_total >= self.config.get("max", 3):
return return
self.db.query("INSERT INTO `tells` (`sender`, `channel`, `when`, `recip`, `message`) VALUES " 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 chardet==3.0.4
cheroot==5.9.1 cheroot==5.9.1
CherryPy==12.0.1 CherryPy==12.0.1
coverage==4.4.2
decorator==4.0.11 decorator==4.0.11
idna==2.5 idna==2.5
ipdb==0.10.3 ipdb==0.10.3
@ -10,6 +11,7 @@ ipython==6.0.0
ipython-genutils==0.2.0 ipython-genutils==0.2.0
jaraco.classes==1.4.3 jaraco.classes==1.4.3
jedi==0.10.2 jedi==0.10.2
lxml==4.1.1
mock==2.0.0 mock==2.0.0
msgbus==0.0.1 msgbus==0.0.1
packaging==16.8 packaging==16.8
@ -27,6 +29,7 @@ PyJWT==1.5.3
pyparsing==2.2.0 pyparsing==2.2.0
PySocks==1.6.7 PySocks==1.6.7
pytest==3.2.5 pytest==3.2.5
pytest-cov==2.5.1
pytz==2017.3 pytz==2017.3
pyzmq==16.0.2 pyzmq==16.0.2
requests==2.18.1 requests==2.18.1

View File

@ -3,4 +3,4 @@
export PYTHONUNBUFFERED=1 export PYTHONUNBUFFERED=1
export PYTHONPATH=. 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} "delayMatch": 0}
fakebot.loadmodule("SQLite") fakebot.loadmodule("SQLite")
with closing(fakebot.moduleInstances["SQLite"].opendb("calc.db")) as db: with closing(fakebot.moduleInstances["SQLite"].opendb("calc.db")) as db:
for q in ["DELETE FROM calc_addedby;", for q in ["DROP TABLE calc_addedby;",
"DELETE FROM calc_channels;", "DROP TABLE calc_channels;",
"DELETE FROM calc_definitions;", "DROP TABLE calc_definitions;",
"DELETE FROM calc_words;"]: "DROP TABLE calc_words;"]:
db.query(q) db.query(q)
fakebot.loadmodule("Calc") fakebot.loadmodule("Calc")
return fakebot return fakebot

View File

@ -1,19 +1,29 @@
import pytest import pytest
from tests.lib import * # NOQA - fixtures from tests.lib import * # NOQA - fixtures
from unittest.mock import call
@pytest.fixture @pytest.fixture
def bot(fakebot): def helpbot(fakebot):
"""
Provide a bot loaded with the ModInfo module
"""
fakebot.loadmodule("ModInfo") fakebot.loadmodule("ModInfo")
return fakebot return fakebot
def test_help(bot): def test_helpindex(helpbot):
bot.feed_line(".help") helpbot.feed_line(".helpindex")
bot.act_PRIVMSG.assert_called_once_with('#test', helpbot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: commands: .help, .helpindex')
'ModInfo: .help [command] show the manual for all or [commands]')
def test_helpindex(bot): def test_help(helpbot):
bot.feed_line(".helpindex") helpbot.feed_line(".help")
bot.act_PRIVMSG.assert_called_once_with('#test', 'chatter: commands: .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} "delayMatch": 0}
fakebot.loadmodule("SQLite") fakebot.loadmodule("SQLite")
with closing(fakebot.moduleInstances["SQLite"].opendb("attributes.db")) as db: with closing(fakebot.moduleInstances["SQLite"].opendb("attributes.db")) as db:
for q in ["DELETE FROM attribute;", for q in ["DROP TABLE attribute;",
"DELETE FROM items;", "DROP TABLE items;",
"DELETE FROM `values`;"]: "DROP TABLE `values`;"]:
db.query(q) db.query(q)
fakebot.loadmodule("AttributeStorageLite") fakebot.loadmodule("AttributeStorageLite")
fakebot.loadmodule("NickUser") fakebot.loadmodule("NickUser")
@ -56,6 +56,12 @@ def test_badpass(nickbot):
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.login: incorrect password.') 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): def test_logout(nickbot):
test_register_login(nickbot) test_register_login(nickbot)
pm(nickbot, ".logout") pm(nickbot, ".logout")
@ -72,3 +78,12 @@ def test_changepass(nickbot):
nickbot.act_PRIVMSG.reset_mock() nickbot.act_PRIVMSG.reset_mock()
pm(nickbot, ".setpass wrong newpass2") pm(nickbot, ".setpass wrong newpass2")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: Old password incorrect.') 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")