def test_reloadevery(self): self.rotate = False def allowed(ctx): self.rotate = not self.rotate return self.rotate and [1] or [0] filter_ = tweebot.UsersFilter(allowed, reload_every=2) self.assertTrue(filter_(self.context, self.entity_ok)) self.assertFalse(filter_(self.context, self.entity_ok)) self.assertTrue(filter_(self.context, self.entity_fail)) self.assertFalse(filter_(self.context, self.entity_fail))
def test_reloadwaserror(self): self.rotate = False def allowed(ctx): self.rotate = not self.rotate if self.rotate: return [1, 2] raise Exception() filter_ = tweebot.UsersFilter(allowed, reload_every=1) self.assertTrue(filter_(self.context, self.entity_ok)) self.assertTrue(filter_(self.context, self.entity_ok)) self.assertTrue(filter_.was_error) self.assertFalse(filter_(self.context, self.entity_fail)) self.assertFalse(filter_.was_error) self.assertTrue(filter_(self.context, self.entity_ok))
def test_allowedlist(self): filter_ = tweebot.UsersFilter([1, 2]) self.assertFalse(filter_(self.context, self.entity_fail))
def test_allowedfunc(self): filter_ = tweebot.UsersFilter(OneTwo) self.assertTrue(filter_(self.context, self.entity_ok)) self.assertFalse(filter_(self.context, self.entity_fail))
def test_validuser(self): filter_ = tweebot.UsersFilter([1, 2]) self.assertTrue(filter_(self.context, self.entity_ok))