本文整理汇总了Python中httpretty.enable方法的典型用法代码示例。如果您正苦于以下问题:Python httpretty.enable方法的具体用法?Python httpretty.enable怎么用?Python httpretty.enable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httpretty
的用法示例。
在下文中一共展示了httpretty.enable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setup(self):
httpretty.enable()
self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
def jwks(_request, _uri, headers): # noqa: E306
ks = KEYS()
ks.add(self.key.serialize())
return 200, headers, ks.dump_jwks()
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)
httpretty.register_uri(
httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
body=json.dumps({
'id_token': self.generate_jws(), 'access_token': 'accesstoken',
'refresh_token': 'refreshtoken', }),
content_type='text/json')
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT,
body=json.dumps({'sub': '1234', 'email': 'test@example.com', }),
content_type='text/json')
yield
httpretty.disable()
示例2: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
"""
Initialize the configuration
"""
Cache.last_updated[APIURL] = {'__oldest': '2016-12-18T11:49:37Z'}
httpretty.reset()
httpretty.enable(allow_net_connect=False)
oscrc = os.path.join(FIXTURES, 'oscrc')
osc.core.conf.get_config(override_conffile=oscrc,
override_no_keyring=True,
override_no_gnome_keyring=True)
#osc.conf.config['debug'] = 1
#osc.conf.config['http_debug'] = 1
logging.basicConfig()
self.logger = logging.getLogger(__file__)
self.logger.setLevel(logging.DEBUG)
self.checker = FactorySourceChecker(apiurl = APIURL,
user = 'factory-source',
logger = self.logger)
self.checker.override_allow = False # Test setup cannot handle.
示例3: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
"""
Initialize the configuration
"""
httpretty.reset()
httpretty.enable()
oscrc = os.path.join(FIXTURES, 'oscrc')
osc.core.conf.get_config(override_conffile=oscrc,
override_no_keyring=True,
override_no_gnome_keyring=True)
#osc.conf.config['debug'] = 1
logging.basicConfig()
self.logger = logging.getLogger(__file__)
self.logger.setLevel(logging.DEBUG)
self.checker = MaintenanceChecker(apiurl = APIURL,
user = 'maintbot',
logger = self.logger)
self.checker.override_allow = False # Test setup cannot handle.
示例4: configure_httpretty
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def configure_httpretty(sitedir):
httpretty.enable()
dir = Path(f"tests/test_sites/data/test_{sitedir}/")
data_file = dir / 'data.json'
data = None
with open(data_file) as f:
data = json.load(f)
for obj in data:
method = httpretty.POST
if obj['method'] == 'GET':
method = httpretty.GET
with open(dir / obj['file']) as f:
httpretty.register_uri(
method,
obj['url'],
f.read(),
)
示例5: endpoints
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def endpoints():
httpretty.enable()
with open(os.path.join(TESTS_DIR, 'endpoints.json')) as resource:
test_data = json.load(resource)
endpoints = test_data['endpoints']
for endpoint, options in endpoints.items():
if isinstance(options.get('body'), (dict, list, tuple)):
body = json.dumps(options.get('body'))
else:
body = options.get('body')
httpretty.register_uri(method=options.get('method', 'GET'),
status=options.get('status', 200),
uri=API_URL + endpoint,
body=body)
yield endpoints
httpretty.disable()
示例6: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
httpretty.enable()
httpretty.register_uri(
httpretty.GET, "http://test.gf/users",
body=ujson.dumps([
sam_profile,
jack_profile,
]),
content_type="application/json"
)
httpretty.register_uri(
httpretty.GET, "http://test.gf/blog/sam",
body=ujson.dumps(sams_articles),
content_type="application/json"
)
httpretty.register_uri(
httpretty.GET, "http://test.gf/blog/jack",
body=ujson.dumps(jacks_articles),
content_type="application/json"
)
示例7: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self) -> None:
# https://github.com/gabrielfalcao/HTTPretty/issues/368
import warnings
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*")
warnings.filterwarnings("ignore", category=PendingDeprecationWarning, message="isAlive*")
httpretty.enable()
httpretty.reset()
conf = influxdb_client.configuration.Configuration()
conf.host = "http://localhost"
conf.debug = False
self.influxdb_client = InfluxDBClient(url=conf.host, token="my-token")
self.write_options = WriteOptions(batch_size=2, flush_interval=5_000, retry_interval=3_000)
self._write_client = WriteApi(influxdb_client=self.influxdb_client, write_options=self.write_options)
示例8: test_config_zipa
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def test_config_zipa():
t.config.host = 'random'
t.config.prefix = 'prefix'
t.config.append_slash = True
t.config.secure = False
t.config.headers = {
'x-custom-header': 'custom-value'
}
assert t.config['host'] == 'random'
assert t.config['prefix'] == 'prefix'
assert t.config['append_slash']
assert t.config['headers']['x-custom-header'] == 'custom-value'
httpretty.enable()
httpretty.register_uri(httpretty.GET, 'http://randomprefix/a/', status=200,
content_type='application/json', body=u'{"name": "a"}')
assert t.a().name == 'a'
assert httpretty.last_request().headers['x-custom-header'] == 'custom-value'
示例9: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
httpretty.enable()
self.geocoder = OpenCageGeocode('abcde')
示例10: setup
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setup(self):
httpretty.enable()
self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
def jwks(_request, _uri, headers): # noqa: E306
ks = KEYS()
ks.add(self.key.serialize())
return 200, headers, ks.dump_jwks()
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)
yield
httpretty.disable()
示例11: test_request_timeout
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def test_request_timeout():
timeout = 0.1
http_scheme = "http"
host = "coordinator"
port = 8080
url = http_scheme + "://" + host + ":" + str(port) + constants.URL_STATEMENT_PATH
def long_call(request, uri, headers):
time.sleep(timeout * 2)
return (200, headers, "delayed success")
httpretty.enable()
for method in [httpretty.POST, httpretty.GET]:
httpretty.register_uri(method, url, body=long_call)
# timeout without retry
for request_timeout in [timeout, (timeout, timeout)]:
req = PrestoRequest(
host=host,
port=port,
user="test",
http_scheme=http_scheme,
max_attempts=1,
request_timeout=request_timeout,
)
with pytest.raises(requests.exceptions.Timeout):
req.get(url)
with pytest.raises(requests.exceptions.Timeout):
req.post("select 1")
httpretty.disable()
httpretty.reset()
示例12: patch_get
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def patch_get():
httpretty.enable()
yield partial(httpretty.register_uri, httpretty.GET)
httpretty.disable()
httpretty.reset()
示例13: test_it_works_with_remote_files
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def test_it_works_with_remote_files(datapackage_zip):
httpretty.enable()
datapackage_zip.seek(0)
url = 'http://someplace.com/datapackage.zip'
httpretty.register_uri(
httpretty.GET, url, body=datapackage_zip.read(), content_type='application/zip')
package = Package(url)
assert package.descriptor['name'] == 'proverbs'
assert len(package.resources) == 1
assert package.resources[0].data == b'foo\n'
httpretty.disable()
示例14: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
"""Set up the test case."""
super(APIWithIDsTestCase, self).setUp()
self.base_uri = self.get_api_url('{}/'.format(self.endpoint))
self.client_class = getattr(self.client, self.endpoint)()
httpretty.enable()
示例15: setUp
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import enable [as 别名]
def setUp(self):
super(ModulesTests, self).setUp()
httpretty.enable()
self.course_id = 'edX/TestX/TestCourse'
self.module_id = 'i4x://TestCourse/block1/module2/abcd1234'
self.module = self.client.modules(self.course_id, self.module_id)