本文整理汇总了Python中responses.POST属性的典型用法代码示例。如果您正苦于以下问题:Python responses.POST属性的具体用法?Python responses.POST怎么用?Python responses.POST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类responses
的用法示例。
在下文中一共展示了responses.POST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_client_get_nodes_for_filter_post
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_client_get_nodes_for_filter_post():
node_list = ['node1', 'node2']
host = 'foo.bar.baz'
responses.add(
responses.POST,
"http://%s/api/v1.0/nodefilter" % (host),
json=node_list,
status=200)
dd_ses = dc_session.DrydockSession(host)
dd_client = dc_client.DrydockClient(dd_ses)
design_ref = {'ref': 'hello'}
validation_resp = dd_client.get_nodes_for_filter(design_ref)
assert 'node1' in validation_resp
assert 'node2' in validation_resp
示例2: test_client_validate_design_post
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_client_validate_design_post():
validation = {'status': 'success'}
host = 'foo.bar.baz'
responses.add(
responses.POST,
"http://%s/api/v1.0/validatedesign" % (host),
json=validation,
status=200)
dd_ses = dc_session.DrydockSession(host)
dd_client = dc_client.DrydockClient(dd_ses)
validation_resp = dd_client.validate_design('href-placeholder')
assert validation_resp['status'] == validation['status']
示例3: test_post
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_post(patch1, patch2):
"""
Test post functionality
"""
responses.add(
responses.POST,
'http://promhost:80/api/v1.0/node-label/n1',
body='{"key1":"label1"}',
status=200)
prom_session = PromenadeSession()
result = prom_session.post(
'v1.0/node-label/n1', body='{"key1":"label1"}', timeout=(60, 60))
assert PROM_HOST == prom_session.host
assert result.status_code == 200
示例4: test_invalid_confidentials_should_raise
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_invalid_confidentials_should_raise():
responses.add(
responses.POST,
"https://api.twitter.com/oauth2/token",
json={
"errors": [
{
"code": 99,
"message": "Unable to verify your credentials",
"label": "authenticity_token_error",
}
]
},
status=403,
)
with pytest.raises(e.BearerTokenNotFetchedError):
_ = twt_img.Downloader("my api key", "my api secret")
示例5: test_cli_mapmatching
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_cli_mapmatching():
responses.add(
responses.POST,
'https://api.mapbox.com/matching/v4/mapbox.cycling.json?gps_precision=4&access_token=bogus',
match_querystring=True,
body="", status=200,
content_type='application/json')
runner = CliRunner()
result = runner.invoke(
main_group,
['--access-token', 'bogus',
"mapmatching",
"--gps-precision", "4",
"--profile", "mapbox.cycling",
"tests/line_feature.geojson"])
assert result.exit_code == 0
示例6: mock_response
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def mock_response(command, **kvargs):
resp = RAIBIRD_COMMANDS["ControllerResponses"][command]
data = command + ("00" * (resp["length"] - 1))
for k in resp:
if k in ["type", "length"]:
continue
param_template = "%%0%dX" % (resp[k]["length"])
start_ = resp[k]["position"]
end_ = start_ + resp[k]["length"]
data = "%s%s%s" % (
data[:start_],
(param_template % kvargs[k]),
data[end_:],
)
responses.add(
responses.POST,
"http://%s/stick" % MOCKED_RAINBIRD_URL,
body=encrypt(
(u'{"jsonrpc": "2.0", "result": {"data":"%s"}, "id": 1} ' % data),
MOCKED_PASSWORD,
),
content_type="application/octet-stream",
)
示例7: test_simple_geolocate
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_simple_geolocate(self):
responses.add(
responses.POST,
"https://www.googleapis.com/geolocation/v1/geolocate",
body='{"location": {"lat": 51.0,"lng": -0.1},"accuracy": 1200.4}',
status=200,
content_type="application/json",
)
results = self.client.geolocate()
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://www.googleapis.com/geolocation/v1/geolocate?" "key=%s" % self.key,
responses.calls[0].request.url,
)
示例8: test_request_sources_error
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_request_sources_error(status_code, error, error_body, caplog):
responses.add(
responses.POST,
'{}/api/v1/requests'.format(CACHITO_URL),
content_type='application/json',
body=error_body,
status=status_code,
)
with pytest.raises(error):
CachitoAPI(CACHITO_URL).request_sources(CACHITO_REQUEST_REPO, CACHITO_REQUEST_REF)
try:
response_data = json.loads(error_body)
except ValueError: # json.JSONDecodeError in py3
assert 'Cachito response' not in caplog.text
else:
response_json = 'Cachito response:\n{}'.format(json.dumps(response_data, indent=4))
# Since Python 3.7 logger adds additional whitespaces by default -> checking without them
assert re.sub(r'\s+', " ", response_json) in re.sub(r'\s+', " ", caplog.text)
示例9: test_create_identity
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_create_identity(self):
"""
The create_identity method should make the correct request to create an identity with the correct details in the
identity store.
"""
identity_store = IdentityStore("http://identitystore.org/", "auth-token", "msisdn")
url = "http://identitystore.org/api/v1/identities/"
responses.add_callback(
responses.POST,
url,
callback=self.create_identity_callback,
match_querystring=True,
content_type="application/json",
)
identity = identity_store.create_identity(["tel:+1234"], name="Test identity", language="eng")
self.assertEqual(identity["details"], {"addresses": {"msisdn": {"+1234": {}}}, "default_addr_type": "msisdn"})
示例10: test_okta_auth_value_error
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_okta_auth_value_error(
self,
mock_print_tty,
mock_makedirs
):
responses.add(
responses.POST,
'https://organization.okta.com/api/v1/authn',
body="NOT JSON",
status=500
)
with self.assertRaises(SystemExit):
Okta(
user_name="user_name",
user_pass="user_pass",
organization="organization.okta.com"
)
print_tty_calls = [
call("Error: Status Code: 500"),
call("Error: Invalid JSON")
]
mock_print_tty.assert_has_calls(print_tty_calls)
示例11: test_okta_connection_timeout
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_okta_connection_timeout(
self,
mock_print_tty,
mock_makedirs,
mock_open,
mock_chmod
):
responses.add(
responses.POST,
'https://organization.okta.com/api/v1/authn',
body=ConnectTimeout()
)
with self.assertRaises(SystemExit):
Okta(
user_name="user_name",
user_pass="user_pass",
organization="organization.okta.com"
)
print_tty_calls = [
call("Error: Timed Out")
]
mock_print_tty.assert_has_calls(print_tty_calls)
示例12: test_should_post_changelog
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_should_post_changelog(self, mock_token):
def request_callback(request):
payload = json.loads(request.body)
self.assertEqual(payload["tag_name"], "v1.0.0")
self.assertEqual(payload["body"], "text")
self.assertEqual(payload["draft"], False)
self.assertEqual(payload["prerelease"], False)
self.assertEqual("token super-token", request.headers["Authorization"])
return 201, {}, json.dumps({})
responses.add_callback(
responses.POST,
self.url,
callback=request_callback,
content_type="application/json",
)
status = Github.post_release_changelog("relekang", "rmoq", "1.0.0", "text")
self.assertTrue(status)
示例13: test_should_return_false_status_if_it_failed
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_should_return_false_status_if_it_failed(self):
responses.add(
responses.POST,
self.url,
status=400,
body="{}",
content_type="application/json",
)
responses.add(
responses.GET,
self.get_url,
status=200,
body='{"id": 1}',
content_type="application/json",
)
responses.add(
responses.POST,
self.edit_url,
status=400,
body="{}",
content_type="application/json",
)
self.assertFalse(
Github.post_release_changelog("relekang", "rmoq", "1.0.0", "text")
)
示例14: test_add_txt_record
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_add_txt_record(dnspod):
responses.add(
responses.POST, "https://dnsapi.cn/Record.Create",
json={"status": {"code": "1"}}
)
dnspod.add_txt_record(RECORD_NAME, RECORD_VALUE)
expected = get_params({
"record_type": "TXT",
"record_line": "默认",
"ttl": str(TTL),
"domain": DOMAIN,
"sub_domain": SUB_DOMAIN,
"value": RECORD_VALUE
})
assert len(responses.calls) == 1
assert parse_data(responses.calls[0].request.body) == expected
示例15: test_remove_txt_record
# 需要导入模块: import responses [as 别名]
# 或者: from responses import POST [as 别名]
def test_remove_txt_record(dnspod):
responses.add(
responses.POST, "https://dnsapi.cn/Record.List",
json={
"status": {"code": "1"},
"records": [
{"id": "err-0", "type": "A", "value": RECORD_VALUE},
{"id": "err-1", "type": "TXT", "value": "some-value"},
{"id": RECORD_ID, "type": "TXT", "value": RECORD_VALUE}
]
}
)
responses.add(
responses.POST, "https://dnsapi.cn/Record.Remove",
json={"status": {"code": "1"}}
)
dnspod.remove_txt_record(RECORD_NAME, RECORD_VALUE)
assert len(responses.calls) == 2
expected_list = get_params({"domain": DOMAIN, "sub_domain": SUB_DOMAIN})
assert parse_data(responses.calls[0].request.body) == expected_list
expected_remove = get_params({"domain": DOMAIN, "record_id": RECORD_ID})
assert parse_data(responses.calls[1].request.body), expected_remove