本文整理汇总了Python中responses.GET属性的典型用法代码示例。如果您正苦于以下问题:Python responses.GET属性的具体用法?Python responses.GET怎么用?Python responses.GET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类responses
的用法示例。
在下文中一共展示了responses.GET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_session_get
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_session_get():
responses.add(
responses.GET,
'http://foo.bar.baz/api/v1.0/test',
body='okay',
status=200)
host = 'foo.bar.baz'
token = '5f1e08b6-38ec-4a99-9d0f-00d29c4e325b'
marker = '40c3eaf6-6a8a-11e7-a4bd-080027ef795a'
def auth_gen():
return [('X-Auth-Token', token)]
dd_ses = dc_session.DrydockSession(host, auth_gen=auth_gen, marker=marker)
resp = dd_ses.get('v1.0/test')
req = resp.request
assert req.headers.get('X-Auth-Token', None) == token
assert req.headers.get('X-Context-Marker', None) == marker
示例2: test_session_get_returns_401
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_session_get_returns_401(*args):
responses.add(
responses.GET,
'http://foo.bar.baz/api/v1.0/test',
body='okay',
status=401)
host = 'foo.bar.baz'
token = '5f1e08b6-38ec-4a99-9d0f-00d29c4e325b'
marker = '40c3eaf6-6a8a-11e7-a4bd-080027ef795a'
def auth_gen():
return [('X-Auth-Token', dc_session.KeystoneClient.get_token())]
dd_ses = dc_session.DrydockSession(host, auth_gen=auth_gen, marker=marker)
resp = dd_ses.get('v1.0/test')
req = resp.request
assert req.headers.get('X-Auth-Token', None) == token
assert req.headers.get('X-Context-Marker', None) == marker
assert dc_session.KeystoneClient.get_token.call_count == 2
示例3: setUp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def setUp(self):
self.client = self.app.test_client()
self.app_context = self.app.app_context()
self.app_context.push()
for table in reversed(self.db.metadata.sorted_tables):
self.db.session.execute(table.delete())
# Mock responses from haveibeenpwned.
responses.add(
responses.GET,
re.compile(
r"^(https:\/\/api\.pwnedpasswords\.com\/range\/836BA).*"),
body=("BDDC66080E01D52B8272AA9461C69EE0496:12145\n"
"00d4f6e8fa6eecad2a3aa415eec418d38ec:2"))
responses.add(
responses.GET,
re.compile(
r"^(https:\/\/api\.pwnedpasswords\.com\/)(?!.*836BA).*"),
body=("BDDC66080E01D52B8272AA9461C69EE0496:12145\n"
"00d4f6e8fa6eecad2a3aa415eec418d38ec:2"))
示例4: test_api_post_haveibeenpwned_not_reachable
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_api_post_haveibeenpwned_not_reachable(self):
payload = {
"secret": "secret message",
"passphrase": "Hello123",
"haveibeenpwned": True
}
with self.client as c:
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
re.compile(r"^(https:\/\/api\.pwnedpasswords\.com\/).*"),
body=Exception)
response = json.loads(
c.post("/api/c", json=payload).get_data())
# haveibeenpwned wasn't reachable, but secret still created if it has
# all mandatory requirements.
r = Parse(response)
self.assertEqual(r.response.status, "created")
示例5: test_list_policies
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_list_policies(nomad_setup):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/sentinel/policies".format(ip=common.IP, port=common.NOMAD_PORT),
status=200,
json=[
{
"Name": "foo",
"Description": "test policy",
"Scope": "submit-job",
"EnforcementLevel": "advisory",
"Hash": "CIs8aNX5OfFvo4D7ihWcQSexEJpHp+Za+dHSncVx5+8=",
"CreateIndex": 8,
"ModifyIndex": 8
}
]
)
policies = nomad_setup.sentinel.get_policies()
assert isinstance(policies, list)
assert "foo" in nomad_setup.sentinel.get_policies()[0]["Name"]
示例6: test_get_policy
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_get_policy(nomad_setup):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/sentinel/policy/foo".format(ip=common.IP, port=common.NOMAD_PORT),
status=200,
json={
"Name": "foo",
"Description": "test policy",
"Scope": "submit-job",
"EnforcementLevel": "advisory",
"Policy": "main = rule { true }\n",
"Hash": "CIs8aNX5OfFvo4D7ihWcQSexEJpHp+Za+dHSncVx5+8=",
"CreateIndex": 8,
"ModifyIndex": 8
}
)
policy = nomad_setup.sentinel.get_policy("foo")
assert "advisory" in policy["EnforcementLevel"]
示例7: test_get_namespaces
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_get_namespaces(nomad_setup):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/namespaces".format(ip=common.IP, port=common.NOMAD_PORT),
status=200,
json=[
{
"CreateIndex": 31,
"Description": "Production API Servers",
"ModifyIndex": 31,
"Name": "api-prod"
},
{
"CreateIndex": 5,
"Description": "Default shared namespace",
"ModifyIndex": 5,
"Name": "default"
}
]
)
assert isinstance(nomad_setup.namespaces.get_namespaces(), list) == True
示例8: test_get_namespaces_prefix
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_get_namespaces_prefix(nomad_setup):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/namespaces?prefix=api-".format(ip=common.IP, port=common.NOMAD_PORT),
status=200,
json=[
{
"CreateIndex": 31,
"Description": "Production API Servers",
"ModifyIndex": 31,
"Name": "api-prod"
},
]
)
assert isinstance(nomad_setup.namespaces.get_namespaces(prefix="api-"), list) == True
示例9: test_namespaces_iter
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_namespaces_iter(nomad_setup):
responses.add(
responses.GET,
"http://{ip}:{port}/v1/namespaces".format(ip=common.IP, port=common.NOMAD_PORT),
status=200,
json=[
{
"CreateIndex": 31,
"Description": "Production API Servers",
"ModifyIndex": 31,
"Name": "api-prod"
},
{
"CreateIndex": 5,
"Description": "Default shared namespace",
"ModifyIndex": 5,
"Name": "default"
}
]
)
assert "api-prod" in nomad_setup.namespaces
示例10: test_cli_dataset_list_features_stdout
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_cli_dataset_list_features_stdout():
id = "cii9dtexw0039uelz7nzk1lq3"
collection='{"type":"FeatureCollection","features":[]}'
responses.add(
responses.GET,
'https://api.mapbox.com/datasets/v1/{0}/{1}/features?access_token={2}'.format(username, id, access_token),
match_querystring=True,
status=200, body=collection,
content_type='application/json'
)
runner = CliRunner()
result = runner.invoke(
main_group,
['--access-token', access_token,
'datasets',
'list-features', id])
assert result.exit_code == 0
assert result.output.strip() == collection.strip()
示例11: test_cli_dataset_list_features_tofile
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_cli_dataset_list_features_tofile(tmpdir):
tmpfile=str(tmpdir.join('test.list-features.json'))
id = "dataset-1"
collection='{"type":"FeatureCollection","features":[]}'
responses.add(
responses.GET,
'https://api.mapbox.com/datasets/v1/{0}/{1}/features?access_token={2}'.format(username, id, access_token),
match_querystring=True,
status=200, body=collection,
content_type='application/json'
)
runner = CliRunner()
result = runner.invoke(
main_group,
['--access-token', access_token,
'datasets',
'list-features', id,
'--output', tmpfile])
assert result.exit_code == 0
assert result.output.strip() == ""
assert open(tmpfile).read().strip() == collection.strip()
示例12: test_cli_static
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_cli_static():
responses.add(
responses.GET,
'https://api.mapbox.com/v4/mapbox.satellite/-61.7,12.1,12/600x600.png256?access_token=bogus',
match_querystring=True,
body='.PNG...',
status=200,
content_type='image/png')
runner = CliRunner()
result = runner.invoke(
main_group,
['--access-token', 'bogus',
'staticmap',
'--lon', '-61.7',
'--lat', '12.1',
'--zoom', '12',
'mapbox.satellite',
'/dev/null'])
assert result.exit_code == 0
示例13: test_cli_geocode_fwd
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_cli_geocode_fwd():
responses.add(
responses.GET,
'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus',
match_querystring=True,
body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
content_type='application/json')
runner = CliRunner()
result = runner.invoke(
main_group,
['--access-token', 'bogus', 'geocoding', '--forward', '1600 pennsylvania ave nw'],
catch_exceptions=False)
print(result.output)
print(result.exception)
print(result.exc_info)
assert result.exit_code == 0
assert result.output == '{"query": ["1600", "pennsylvania", "ave", "nw"]}\n'
示例14: test_cli_geocode_fwd_bbox
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_cli_geocode_fwd_bbox():
responses.add(
responses.GET,
'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus&bbox=-78.3284%2C38.6039%2C-78.0428%2C38.7841',
match_querystring=True,
body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
content_type='application/json')
runner = CliRunner()
result = runner.invoke(
main_group,
['--access-token', 'bogus', 'geocoding', '--forward', '1600 pennsylvania ave nw', '--bbox', '[-78.3284,38.6039,-78.0428,38.7841]'],
catch_exceptions=False)
print(result.output)
print(result.exception)
print(result.exc_info)
assert result.exit_code == 0
assert result.output == '{"query": ["1600", "pennsylvania", "ave", "nw"]}\n'
示例15: test_cli_geocode_fwd_env_token
# 需要导入模块: import responses [as 别名]
# 或者: from responses import GET [as 别名]
def test_cli_geocode_fwd_env_token():
responses.add(
responses.GET,
'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus',
match_querystring=True,
body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
content_type='application/json')
runner = CliRunner()
result = runner.invoke(
main_group,
['geocoding', '--forward', '1600 pennsylvania ave nw'],
env={'MAPBOX_ACCESS_TOKEN': 'bogus'})
assert result.exit_code == 0
assert result.output == '{"query": ["1600", "pennsylvania", "ave", "nw"]}\n'