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")))
def test_the_instance_should_be_able_to_generate_a_redis_key_when_provided_with_a_realm(
):
    driver = RespectfulWebdriver(webdriver=webdriver)

    assert driver._realm_redis_key(
        "TEST") == "%s:REALMS:TEST" % driver.redis_prefix
    assert driver._realm_redis_key(
        "TEST2") == "%s:REALMS:TEST2" % driver.redis_prefix
    assert driver._realm_redis_key(
        "TEST SPACED") == "%s:REALMS:TEST SPACED" % driver.redis_prefix
    assert driver._realm_redis_key(
        "TEST ÉÉÉ") == "%s:REALMS:TEST ÉÉÉ" % driver.redis_prefix
def test_the_instance_should_be_able_to_unregister_a_realm():
    driver = RespectfulWebdriver(webdriver=webdriver)

    driver.register_realm("TEST123", max_requests=100, timespan=300)

    driver.get("http://google.com", realms=["TEST123"])

    driver.unregister_realm("TEST123")

    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")))