def test_reset(self): limiter = Limiter("names", 10) for i in range(1, 20): limiter.is_reached("dummy1") assert limiter.get_status() == (1, 10, False) limiter.reset() assert limiter.get_status() == (0, 10, False) assert limiter.is_reached("dummy1") is False assert limiter.get_status() == (1, 10, False)
def test_mixed(self): limiter = Limiter("names", 10) for i in range(0, 20): assert limiter.is_reached("dummy1") is False assert limiter.get_status() == (1, 10, False) for i in range(0, 5): assert limiter.is_reached() is False assert limiter.get_status() == (6, 10, False)
def test_with_uid(self): warnings = [] limiter = Limiter("names", 10, warning_func=warnings.append) for i in range(0, 20): assert limiter.is_reached("dummy1") is False assert limiter.get_status() == (1, 10, False) for i in range(0, 20): assert limiter.is_reached("dummy2") is False assert limiter.get_status() == (2, 10, False) assert len(warnings) == 0
def test_no_uid(self): warnings = [] limiter = Limiter("names", 10, warning_func=warnings.append) for i in range(0, 10): assert limiter.is_reached() is False assert limiter.get_status() == (10, 10, False) # Reach limit assert limiter.is_reached() is True assert limiter.get_status() == (11, 10, True) assert warnings == ["Exceeded limit of 10 names, ignoring next ones"] # Make sure warning is only sent once assert limiter.is_reached() is True assert len(warnings) == 1