mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Added 'setpriority' and tests.
This commit is contained in:
parent
c1ee1b8c10
commit
8229759769
@ -237,6 +237,33 @@ class Todo(callbacks.Privmsg):
|
|||||||
for item in cursor.fetchall()]
|
for item in cursor.fetchall()]
|
||||||
irc.reply(msg, utils.commaAndify(tasks))
|
irc.reply(msg, utils.commaAndify(tasks))
|
||||||
|
|
||||||
|
def setpriority(self, irc, msg, args):
|
||||||
|
"""<id> <priority>
|
||||||
|
|
||||||
|
Sets the priority of the todo with the given id to the specified value.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
user_id = ircdb.users.getUserId(msg.prefix)
|
||||||
|
except KeyError:
|
||||||
|
irc.error(msg, conf.replyNotRegistered)
|
||||||
|
return
|
||||||
|
(id, priority) = privmsgs.getArgs(args, needed=2)
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("""SELECT userid, priority FROM todo
|
||||||
|
WHERE id = %s""", id)
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
irc.error(msg, 'No note with id %d' % id)
|
||||||
|
return
|
||||||
|
(userid, oldpriority) = cursor.fetchone()
|
||||||
|
if userid != user_id:
|
||||||
|
irc.error(msg, 'Todo #%d does not belong to you.' % id)
|
||||||
|
return
|
||||||
|
# If we make it here, we're okay
|
||||||
|
cursor.execute("""UPDATE todo SET priority = %s
|
||||||
|
WHERE id = %s""", priority, id)
|
||||||
|
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:
|
||||||
|
@ -78,5 +78,15 @@ if sqlite is not None:
|
|||||||
' one and #2: task number two is much longer '
|
' one and #2: task number two is much longer '
|
||||||
'than task number...')
|
'than task number...')
|
||||||
|
|
||||||
|
def testSetPriority(self):
|
||||||
|
self.assertNotError('todo add --priority=1 moo')
|
||||||
|
self.assertRegexp('todo 1', 'moo, priority: 1 \(Added '
|
||||||
|
'at: .*?\)')
|
||||||
|
self.assertNotError('setpriority 1 50')
|
||||||
|
self.assertRegexp('todo 1', 'moo, priority: 50 \(Added '
|
||||||
|
'at: .*?\)')
|
||||||
|
self.assertNotError('setpriority 1 0')
|
||||||
|
self.assertRegexp('todo 1', 'moo \(Added at: .*?\)')
|
||||||
|
|
||||||
# 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