mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added "todo change" and tests for it.
This commit is contained in:
parent
f9d97c91f5
commit
05f8d6a2f8
@ -295,6 +295,36 @@ class Todo(callbacks.Privmsg):
|
|||||||
self.db.commit()
|
self.db.commit()
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
|
def change(self, irc, msg, args):
|
||||||
|
"""<task id> <regexp>
|
||||||
|
|
||||||
|
Modify the task with the given id using the supplied regexp.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
userid = ircdb.users.getUserId(msg.prefix)
|
||||||
|
except KeyError:
|
||||||
|
irc.error(msg, conf.replyNotRegistered)
|
||||||
|
return
|
||||||
|
taskid, regexp = privmsgs.getArgs(args, needed=2)
|
||||||
|
# Check the regexp first, it's easier and doesn't require a db query
|
||||||
|
try:
|
||||||
|
replacer = utils.perlReToReplacer(regexp)
|
||||||
|
except ValueError:
|
||||||
|
irc.error(msg, '%r is not a valid regexp' % regexp)
|
||||||
|
return
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("""SELECT task FROM todo
|
||||||
|
WHERE userid = %s AND id = %s
|
||||||
|
AND active = 1""", userid, taskid)
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
irc.error(msg, '%r is not a valid task id' % taskid)
|
||||||
|
return
|
||||||
|
newtext = replacer(cursor.fetchone()[0])
|
||||||
|
cursor.execute("""UPDATE todo SET task = %s
|
||||||
|
WHERE id = %s""", newtext, taskid)
|
||||||
|
self.db.commit()
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
Class = Todo
|
Class = Todo
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
@ -96,5 +96,12 @@ if sqlite is not None:
|
|||||||
self.assertNotError('setpriority 1 0')
|
self.assertNotError('setpriority 1 0')
|
||||||
self.assertRegexp('todo 1', 'moo \(Added at .*?\)')
|
self.assertRegexp('todo 1', 'moo \(Added at .*?\)')
|
||||||
|
|
||||||
|
def testChangeTodo(self):
|
||||||
|
self.assertNotError('todo add moo')
|
||||||
|
self.assertError('todo change 1 asdfas')
|
||||||
|
self.assertError('todo change 1 m/asdfaf//')
|
||||||
|
self.assertNotError('todo change 1 s/moo/foo/')
|
||||||
|
self.assertRegexp('todo 1', 'Todo for tester: foo \(Added .*?\)')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user