def test_the_instance_should_be_able_to_register_multiple_realms(): driver = RespectfulWebdriver(webdriver=webdriver) driver.register_realm("TEST123", max_requests=100, timespan=300) realm_tuples = [ ["TEST123", 100, 300], ["TEST234", 200, 600], ["TEST345", 300, 900], ] driver.register_realms(realm_tuples) assert driver.realm_max_requests("TEST123") == 100 assert driver.realm_timespan("TEST123") == 300 assert driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST123") assert driver.realm_max_requests("TEST234") == 200 assert driver.realm_timespan("TEST234") == 600 assert driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST234") assert driver.realm_max_requests("TEST345") == 300 assert driver.realm_timespan("TEST345") == 900 assert driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST345") driver.unregister_realm("TEST123") driver.unregister_realm("TEST234") driver.unregister_realm("TEST345")
def test_the_instance_should_be_able_to_unregister_multiple_realms(): driver = RespectfulWebdriver(webdriver=webdriver) realm_tuples = [ ["TEST123", 100, 300], ["TEST234", 200, 600], ["TEST345", 300, 900], ] driver.register_realms(realm_tuples) driver.get("http://google.com", realms=["TEST123", "TEST234", "TEST345"]) driver.unregister_realms(["TEST123", "TEST234", "TEST345"]) assert driver.redis.get(driver._realm_redis_key("TEST123")) is None assert not driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST123") assert not len( driver.redis.keys("%s:REQUESTS:%s:*" % (driver.redis_prefix, "TEST123"))) assert driver.redis.get(driver._realm_redis_key("TEST234")) is None assert not driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST234") assert not len( driver.redis.keys("%s:REQUESTS:%s:*" % (driver.redis_prefix, "TEST234"))) assert driver.redis.get(driver._realm_redis_key("TEST345")) is None assert not driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST345") assert not len( driver.redis.keys("%s:REQUESTS:%s:*" % (driver.redis_prefix, "TEST345")))