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_return_the_max_requests_value_of_a_registered_realm(
):
    driver = RespectfulWebdriver(webdriver=webdriver)

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

    driver.unregister_realm("TEST123")
def test_the_instance_should_be_able_to_register_a_realm():
    driver = RespectfulWebdriver(webdriver=webdriver)

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

    assert driver.realm_max_requests("TEST123") == 100
    assert driver.realm_timespan("TEST123") == 300
    assert driver.redis.sismember("%s:REALMS" % driver.redis_prefix, "TEST123")

    driver.unregister_realm("TEST123")
def test_the_instance_should_not_overwrite_when_registering_a_realm():
    driver = RespectfulWebdriver(webdriver=webdriver)

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

    assert driver.realm_max_requests("TEST123") == 100
    assert driver.realm_timespan("TEST123") == 300

    driver.unregister_realm("TEST123")
def test_the_instance_should_ignore_invalid_values_when_updating_a_realm():
    driver = RespectfulWebdriver(webdriver=webdriver)

    driver.register_realm("TEST123", max_requests=100, timespan=300)
    driver.update_realm("TEST123",
                        max_requests="FOO",
                        timespan="BAR",
                        fake=True)

    assert driver.realm_max_requests("TEST123") == 100
    assert driver.realm_timespan("TEST123") == 300

    driver.unregister_realm("TEST123")