class KeysTest(unittest.TestCase): """Test subscription keys mapping without a ZODB fixture""" def setUp(self): self.subkeys = SubscriptionKeys() assert len(self.subkeys) == 0 def test_iface(self): assert ISubscriptionKeys.providedBy(self.subkeys) for name in ('add', 'get', '__getitem__', '__contains__', '__delitem__', '__len__'): assert hasattr(getattr(self.subkeys, name, None), '__call__') def test_validation(self): # key must be string, not (for example) an integer self.assertRaises(KeyError, self.subkeys.__setitem__, 123, VALID) # test invalid values: for badvalue in INVALID: self.assertRaises(ValueError, self.subkeys.__setitem__, 'abc', badvalue) def test_generation(self): key = self.subkeys.generate(NAME, SUB.signature(), UID) assert key == EXPECTED assert key == self.subkeys.add(NAME, SUB.signature(), UID) def test_add_remove(self): key = self.subkeys.add(NAME, SUB.signature(), UID) assert key in self.subkeys assert key in self.subkeys.keys() assert self.subkeys[key] == (NAME, SUB.signature(), UID) del(self.subkeys[key]) assert key not in self.subkeys def tearDown(self): for key in list(self.subkeys): del(self.subkeys[key]) self.assertEquals(len(self.subkeys), 0)
def setUp(self): self.subkeys = SubscriptionKeys() assert len(self.subkeys) == 0