def after_setUp(self): self.prefix = "test_notification:" for key in redis.keys(self.prefix + "*"): redis.delete(key) self.q = KeyedSet(self.prefix)
class TestKeyedSet(CanvasTestCase): def after_setUp(self): self.prefix = "test_notification:" for key in redis.keys(self.prefix + "*"): redis.delete(key) self.q = KeyedSet(self.prefix) def test_add_to_queue(self): key = self.q.add('foo_bar') self.assertEqual(self.q.get(), {key: 'foo_bar'}) def test_add_multiple_items_to_queue(self): expected = {} for value in ["one", "two", "three"]: key = self.q.add(value) expected[key] = value self.assertEqual(self.q.get(), expected) def test_remove_from_queue(self): key = self.q.add('frooba') self.q.remove(key) self.assertEqual(self.q.get(), {}) def test_add_multiple_items_and_remove_one_from_queue(self): expected = {} remove_key = self.q.add("flux") for value in ["one", "two", "three"]: key = self.q.add(value) expected[key] = value self.q.remove(remove_key) self.assertEqual(self.q.get(), expected) def test_delete_twice_from_queue(self): key = self.q.add("foo") self.assertEqual(self.q.remove(key), True) self.assertEqual(self.q.remove(key), False)