Added "todo change" and tests for it.

This commit is contained in:
Daniel DiPaolo 2003-10-28 18:43:43 +00:00
parent f9d97c91f5
commit 05f8d6a2f8
2 changed files with 37 additions and 0 deletions

View File

@ -295,6 +295,36 @@ class Todo(callbacks.Privmsg):
self.db.commit()
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
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -96,5 +96,12 @@ if sqlite is not None:
self.assertNotError('setpriority 1 0')
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: