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


Python RespectfulRequester.configure_default方法代码示例

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


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

示例1: test_the_class_should_validate_provided_configuration_values

# 需要导入模块: from requests_respectful import RespectfulRequester [as 别名]
# 或者: from requests_respectful.RespectfulRequester import configure_default [as 别名]
def test_the_class_should_validate_provided_configuration_values():
    with pytest.raises(RequestsRespectfulConfigError):
        RespectfulRequester.configure(redis="REDIS")

    with pytest.raises(RequestsRespectfulConfigError):
        RespectfulRequester.configure(redis=dict())

    with pytest.raises(RequestsRespectfulConfigError):
        RespectfulRequester.configure(redis={"host": "localhost", "port": 6379})

    RespectfulRequester.configure(redis={"host": "localhost", "port": 6379, "database": 0})

    with pytest.raises(RequestsRespectfulConfigError):
        RespectfulRequester.configure(safety_threshold="SAFETY")

    with pytest.raises(RequestsRespectfulConfigError):
        RespectfulRequester.configure(safety_threshold=-15)

    RespectfulRequester.configure(safety_threshold=10)

    with pytest.raises(RequestsRespectfulConfigError):
        RespectfulRequester.configure(requests_module_name=100)

    RespectfulRequester.configure(requests_module_name="requests")

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

示例2: test_the_requests_module_name_configuration_value_should_have_the_expected_effect

# 需要导入模块: from requests_respectful import RespectfulRequester [as 别名]
# 或者: from requests_respectful.RespectfulRequester import configure_default [as 别名]
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,代码行数:12,代码来源:test_respectful_requester.py

示例3: test_the_class_should_be_able_to_restore_the_default_configuration_values

# 需要导入模块: from requests_respectful import RespectfulRequester [as 别名]
# 或者: from requests_respectful.RespectfulRequester import configure_default [as 别名]
def test_the_class_should_be_able_to_restore_the_default_configuration_values():
    rr = RespectfulRequester()

    RespectfulRequester.configure(safety_threshold=20)
    RespectfulRequester.configure(requests_module_name="r")
    RespectfulRequester.configure(redis={"host": "0.0.0.0", "port": 6379, "database": 1})

    RespectfulRequester.configure_default()

    assert rr._config()["safety_threshold"] == 10
    assert rr._config()["requests_module_name"] == "requests"
    assert rr._config()["redis"]["host"] == "localhost"
    assert rr._config()["redis"]["database"] == 0
开发者ID:bag-of-projects,项目名称:requests-respectful,代码行数:15,代码来源:test_respectful_requester.py

示例4: test_the_instance_should_be_able_to_wait_for_a_request_to_be_allowed_on_a_registered_realm

# 需要导入模块: from requests_respectful import RespectfulRequester [as 别名]
# 或者: from requests_respectful.RespectfulRequester import configure_default [as 别名]
def test_the_instance_should_be_able_to_wait_for_a_request_to_be_allowed_on_a_registered_realm():
    rr = RespectfulRequester()

    RespectfulRequester.configure(safety_threshold=0)

    rr.register_realm("TEST123", max_requests=1, timespan=2)

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

    rr.request(request_func, "TEST123", wait=True)
    rr.request(request_func, "TEST123", wait=True)
    rr.request(request_func, "TEST123", wait=True)

    rr.unregister_realm("TEST123")

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

示例5: test_the_safety_threshold_configuration_value_should_have_the_expected_effect

# 需要导入模块: from requests_respectful import RespectfulRequester [as 别名]
# 或者: from requests_respectful.RespectfulRequester import configure_default [as 别名]
def test_the_safety_threshold_configuration_value_should_have_the_expected_effect():
    rr = RespectfulRequester()

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

    RespectfulRequester.configure(safety_threshold=10)

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

    rr.request(request_func, "TEST123")

    with pytest.raises(RequestsRespectfulRateLimitedError):
        rr.request(request_func, "TEST123")

    RespectfulRequester.configure_default()

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

示例6: test_setup

# 需要导入模块: from requests_respectful import RespectfulRequester [as 别名]
# 或者: from requests_respectful.RespectfulRequester import configure_default [as 别名]
def test_setup():
    rr = RespectfulRequester()
    rr.unregister_realm("TEST123")

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


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