当前位置: 首页>>代码示例>>Python>>正文


Python requests_respectful.RespectfulRequester类代码示例

本文整理汇总了Python中requests_respectful.RespectfulRequester的典型用法代码示例。如果您正苦于以下问题:Python RespectfulRequester类的具体用法?Python RespectfulRequester怎么用?Python RespectfulRequester使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RespectfulRequester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_the_instance_should_not_allow_a_request_to_be_made_on_an_unregistered_realm

def test_the_instance_should_not_allow_a_request_to_be_made_on_an_unregistered_realm():
    rr = RespectfulRequester()

    request_func = lambda: requests.get("http://google.com")

    with pytest.raises(RequestsRespectfulError):
        rr.request(request_func, "TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:7,代码来源:test_respectful_requester.py

示例2: test_the_instance_should_be_able_to_generate_a_redis_key_when_provided_with_a_realm

def test_the_instance_should_be_able_to_generate_a_redis_key_when_provided_with_a_realm():
    rr = RespectfulRequester()

    assert rr._realm_redis_key("TEST") == "%s:REALMS:TEST" % rr.redis_prefix
    assert rr._realm_redis_key("TEST2") == "%s:REALMS:TEST2" % rr.redis_prefix
    assert rr._realm_redis_key("TEST SPACED") == "%s:REALMS:TEST SPACED" % rr.redis_prefix
    assert rr._realm_redis_key("TEST ÉÉÉ") == "%s:REALMS:TEST ÉÉÉ" % rr.redis_prefix
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:7,代码来源:test_respectful_requester.py

示例3: test_the_instance_should_be_able_to_unregister_multiple_realms

def test_the_instance_should_be_able_to_unregister_multiple_realms():
    rr = RespectfulRequester()

    realm_tuples = [
        ["TEST123", 100, 300],
        ["TEST234", 200, 600],
        ["TEST345", 300, 900],
    ]

    rr.register_realms(realm_tuples)

    request_func = lambda: requests.get("http://google.com")
    rr._perform_request(request_func, realms=["TEST123", "TEST234", "TEST345"])

    rr.unregister_realms(["TEST123", "TEST234", "TEST345"])

    assert rr.redis.get(rr._realm_redis_key("TEST123")) is None
    assert not rr.redis.sismember("%s:REALMS" % rr.redis_prefix, "TEST123")
    assert not len(rr.redis.keys("%s:REQUESTS:%s:*" % (rr.redis_prefix, "TEST123")))

    assert rr.redis.get(rr._realm_redis_key("TEST234")) is None
    assert not rr.redis.sismember("%s:REALMS" % rr.redis_prefix, "TEST234")
    assert not len(rr.redis.keys("%s:REQUESTS:%s:*" % (rr.redis_prefix, "TEST234")))

    assert rr.redis.get(rr._realm_redis_key("TEST345")) is None
    assert not rr.redis.sismember("%s:REALMS" % rr.redis_prefix, "TEST345")
    assert not len(rr.redis.keys("%s:REQUESTS:%s:*" % (rr.redis_prefix, "TEST345")))
开发者ID:nbrochu,项目名称:requests-respectful,代码行数:27,代码来源:test_respectful_requester.py

示例4: RespectfulRequester

def test_the_instance_should_get_the_same_results_by_using_the_requests_proxy_as_when_using_the_request_method():
    rr = RespectfulRequester()

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

    assert type(rr.get("http://google.com", realm="TEST123")) == requests.Response

    rr.update_realm("TEST123", max_requests=0)

    with pytest.raises(RequestsRespectfulRateLimitedError):
        rr.get("http://google.com", realm="TEST123")

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:13,代码来源:test_respectful_requester.py

示例5: test_the_instance_should_ignore_invalid_values_when_updating_a_realm

def test_the_instance_should_ignore_invalid_values_when_updating_a_realm():
    rr = RespectfulRequester()

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

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

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:10,代码来源:test_respectful_requester.py

示例6: test_the_instance_should_be_able_to_update_a_registered_realm

def test_the_instance_should_be_able_to_update_a_registered_realm():
    rr = RespectfulRequester()

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

    assert rr.realm_max_requests("TEST123") == 1000
    assert rr.realm_timespan("TEST123") == 3000

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:10,代码来源:test_respectful_requester.py

示例7: test_the_instance_should_not_overwrite_when_registering_a_realm

def test_the_instance_should_not_overwrite_when_registering_a_realm():
    rr = RespectfulRequester()

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

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

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:10,代码来源:test_respectful_requester.py

示例8: test_the_instance_should_be_able_to_determine_if_it_can_perform_a_request_for_a_registered_realm

def test_the_instance_should_be_able_to_determine_if_it_can_perform_a_request_for_a_registered_realm():
    rr = RespectfulRequester()

    rr.register_realm("TEST123", max_requests=1000, timespan=5)

    assert rr._can_perform_request("TEST123")

    rr.update_realm("TEST123", max_requests=0)

    assert not rr._can_perform_request("TEST123")

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:12,代码来源:test_respectful_requester.py

示例9: test_the_instance_should_be_able_to_fetch_the_information_of_a_registered_realm

def test_the_instance_should_be_able_to_fetch_the_information_of_a_registered_realm():
    rr = RespectfulRequester()

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

    assert b"max_requests" in rr._fetch_realm_info("TEST123")
    assert rr._fetch_realm_info("TEST123")[b"max_requests"] == b"100"

    assert b"timespan" in rr._fetch_realm_info("TEST123")
    assert rr._fetch_realm_info("TEST123")[b"timespan"] == b"300"

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:12,代码来源:test_respectful_requester.py

示例10: test_the_instance_should_validate_that_the_request_lambda_is_actually_a_requests_call

def test_the_instance_should_validate_that_the_request_lambda_is_actually_a_requests_call():
    rr = RespectfulRequester()

    with pytest.raises(RequestsRespectfulError):
        rr._validate_request_func(lambda: 1 + 1)

    rr._validate_request_func(lambda: requests.get("http://google.com"))
    rr._validate_request_func(lambda: getattr(requests, "get")("http://google.com"))
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:8,代码来源:test_respectful_requester.py

示例11: test_the_instance_should_be_able_to_unregister_a_realm

def test_the_instance_should_be_able_to_unregister_a_realm():
    rr = RespectfulRequester()

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

    request_func = lambda: requests.get("http://google.com")
    rr._perform_request(request_func, "TEST123")

    rr.unregister_realm("TEST123")

    assert rr.redis.get(rr._realm_redis_key("TEST123")) is None
    assert not rr.redis.sismember("%s:REALMS" % rr.redis_prefix, "TEST123")
    assert not len(rr.redis.keys("%s:REQUESTS:%s:*" % (rr.redis_prefix, "TEST123")))
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:13,代码来源:test_respectful_requester.py

示例12: test_the_requests_module_name_configuration_value_should_have_the_expected_effect

def test_the_requests_module_name_configuration_value_should_have_the_expected_effect():
    rr = RespectfulRequester()

    RespectfulRequester.configure(requests_module_name="r")

    request_func = lambda: r.get("http://google.com")

    rr._validate_request_func(request_func)

    RespectfulRequester.configure_default()
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:10,代码来源:test_respectful_requester.py

示例13: test_the_instance_should_be_able_to_register_a_realm

def test_the_instance_should_be_able_to_register_a_realm():
    rr = RespectfulRequester()

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

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

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:10,代码来源:test_respectful_requester.py

示例14: test_the_instance_should_be_able_to_return_the_timespan_value_of_a_registered_realm

def test_the_instance_should_be_able_to_return_the_timespan_value_of_a_registered_realm():
    rr = RespectfulRequester()

    rr.register_realm("TEST123", max_requests=100, timespan=300)
    assert rr.realm_timespan("TEST123") == 300

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:7,代码来源:test_respectful_requester.py

示例15: test_the_instance_should_be_able_to_fetch_a_list_of_registered_realms

def test_the_instance_should_be_able_to_fetch_a_list_of_registered_realms():
    rr = RespectfulRequester()

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

    assert "TEST123" in rr.fetch_registered_realms()

    rr.unregister_realm("TEST123")
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:8,代码来源:test_respectful_requester.py


注:本文中的requests_respectful.RespectfulRequester类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。