本文整理汇总了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()
示例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()
示例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
示例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()
示例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")
示例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()