mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
Fixed RFE #851183, ircdb.users.numUsers.
This commit is contained in:
parent
71bd9ed41a
commit
e34d9deecd
@ -48,6 +48,8 @@
|
|||||||
* Fixed bug in Gameknot.gkstats when retrieving the stats for
|
* Fixed bug in Gameknot.gkstats when retrieving the stats for
|
||||||
users who haven't yet played a game.
|
users who haven't yet played a game.
|
||||||
|
|
||||||
|
* Added a numUsers() method to ircdb.UsersDB (ircdb.users).
|
||||||
|
|
||||||
2003-11-18 Jeremy Fincher <jemfinch@users.sf.net>
|
2003-11-18 Jeremy Fincher <jemfinch@users.sf.net>
|
||||||
|
|
||||||
* Changed commands so that plugins no longer have to make sure
|
* Changed commands so that plugins no longer have to make sure
|
||||||
|
@ -37,7 +37,7 @@ import os
|
|||||||
import sets
|
import sets
|
||||||
import time
|
import time
|
||||||
import string
|
import string
|
||||||
from itertools import imap
|
from itertools import imap, ilen, ifilter
|
||||||
|
|
||||||
import log
|
import log
|
||||||
import conf
|
import conf
|
||||||
@ -458,6 +458,9 @@ class UsersDB(object):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def numUsers(self):
|
||||||
|
return ilen(ifilter(None, self.users))-1 # -1 is for the bot user.
|
||||||
|
|
||||||
def setUser(self, id, user):
|
def setUser(self, id, user):
|
||||||
"""Sets a user (given its id) to the IrcUser given it."""
|
"""Sets a user (given its id) to the IrcUser given it."""
|
||||||
assert isinstance(id, int), 'setUser takes an integer userId.'
|
assert isinstance(id, int), 'setUser takes an integer userId.'
|
||||||
|
@ -311,6 +311,27 @@ class UsersDBTestCase(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
self.users = ircdb.UsersDB(self.filename)
|
self.users = ircdb.UsersDB(self.filename)
|
||||||
|
|
||||||
|
def testNumUsers(self):
|
||||||
|
self.assertEqual(self.users.numUsers(), 0)
|
||||||
|
(id, u) = self.users.newUser()
|
||||||
|
hostmask = 'foo!bar@baz'
|
||||||
|
banmask = ircutils.banmask(hostmask)
|
||||||
|
u.addHostmask(banmask)
|
||||||
|
u.name = 'foo'
|
||||||
|
self.users.setUser(id, u)
|
||||||
|
self.assertEqual(self.users.numUsers(), 1)
|
||||||
|
(id, u) = self.users.newUser()
|
||||||
|
hostmask = 'biff!fladksfj@blakjdsf'
|
||||||
|
banmask = ircutils.banmask(hostmask)
|
||||||
|
u.addHostmask(banmask)
|
||||||
|
u.name = 'biff'
|
||||||
|
self.users.setUser(id, u)
|
||||||
|
self.assertEqual(self.users.numUsers(), 2)
|
||||||
|
self.users.delUser(2)
|
||||||
|
self.assertEqual(self.users.numUsers(), 1)
|
||||||
|
self.users.delUser(1)
|
||||||
|
self.assertEqual(self.users.numUsers(), 0)
|
||||||
|
|
||||||
def testGetSetDelUser(self):
|
def testGetSetDelUser(self):
|
||||||
self.assertRaises(KeyError, self.users.getUser, 'foo')
|
self.assertRaises(KeyError, self.users.getUser, 'foo')
|
||||||
self.assertRaises(KeyError, self.users.getUser, 'foo!bar@baz')
|
self.assertRaises(KeyError, self.users.getUser, 'foo!bar@baz')
|
||||||
|
Loading…
Reference in New Issue
Block a user