Some bugs were being shadowed for some reason, and there were bugs in the handling of the owner privilege that hadn't been found because those tests had been shadowed.

This commit is contained in:
Jeremy Fincher 2003-10-05 11:42:58 +00:00
parent d5c4b15632
commit 8ef808a039
2 changed files with 35 additions and 24 deletions

View File

@ -141,13 +141,17 @@ class CapabilitySet(sets.Set):
raise KeyError, capability
def __repr__(self):
return '%s([%r])' % (self.__class__.__name__, ', '.join(self))
return '%s([%s])' % (self.__class__.__name__,
', '.join(map(repr, self)))
antiOwner = makeAntiCapability('owner')
class UserCapabilitySet(CapabilitySet):
"""A subclass of CapabilitySet to handle the owner capability correctly."""
def __contains__(self, capability):
capability = ircutils.toLower(capability)
if CapabilitySet.__contains__(self, 'owner'):
if capability == 'owner' or capability == antiOwner:
return True
elif CapabilitySet.__contains__(self, 'owner'):
return True
else:
return CapabilitySet.__contains__(self, capability)
@ -159,12 +163,12 @@ class UserCapabilitySet(CapabilitySet):
appropriately.
"""
capability = ircutils.toLower(capability)
if capability == 'owner':
if capability == 'owner' or capability == antiOwner:
if CapabilitySet.__contains__(self, 'owner'):
return True
return not isAntiCapability(capability)
else:
return False
if 'owner' in self:
return isAntiCapability(capability)
elif CapabilitySet.__contains__(self, 'owner'):
if isAntiCapability(capability):
return False
else:

View File

@ -80,7 +80,7 @@ class FunctionsTestCase(unittest.TestCase):
class CapabilitySetTestCase(unittest.TestCase):
def test(self):
def testGeneral(self):
d = ircdb.CapabilitySet()
self.assertRaises(KeyError, d.check, 'foo')
d = ircdb.CapabilitySet(('foo',))
@ -99,24 +99,12 @@ class CapabilitySetTestCase(unittest.TestCase):
self.assertRaises(KeyError, d.check, '-bar')
self.assertRaises(KeyError, d.check, 'bar')
def testReprEval(self):
s = ircdb.UserCapabilitySet()
s.add('foo')
s.add('bar')
self.assertEqual(s, eval(repr(s), ircdb.__dict__, ircdb.__dict__))
class UserCapabilitySetTestCase(unittest.TestCase):
def testOwnerHasAll(self):
d = ircdb.UserCapabilitySet(('owner',))
self.failIf(d.check('-foo'))
self.failUnless(d.check('foo'))
def testOwnerIsAlwaysPresent(self):
d = ircdb.UserCapabilitySet()
self.failUnless('owner' in d)
self.failUnless('-owner' in d)
self.failIf(d.check('owner'))
d.add('owner')
self.failUnless(d.check('owner'))
class CapabilitySetTestCase(unittest.TestCase):
def testContains(self):
s = ircdb.CapabilitySet()
self.failIf('foo' in s)
@ -160,6 +148,25 @@ class CapabilitySetTestCase(unittest.TestCase):
class UserCapabilitySetTestCase(unittest.TestCase):
def testOwnerHasAll(self):
d = ircdb.UserCapabilitySet(('owner',))
self.failIf(d.check('-foo'))
self.failUnless(d.check('foo'))
def testOwnerIsAlwaysPresent(self):
d = ircdb.UserCapabilitySet()
self.failUnless('owner' in d)
self.failUnless('-owner' in d)
self.failIf(d.check('owner'))
d.add('owner')
self.failUnless(d.check('owner'))
def testReprEval(self):
s = ircdb.UserCapabilitySet()
s.add('foo')
s.add('bar')
self.assertEqual(s, eval(repr(s), ircdb.__dict__, ircdb.__dict__))
def testOwner(self):
s = ircdb.UserCapabilitySet()
s.add('owner')