本文整理汇总了Python中mimic.test.helpers.json_request函数的典型用法代码示例。如果您正苦于以下问题:Python json_request函数的具体用法?Python json_request怎么用?Python json_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_request函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_check_domains
def test_check_domains(self):
"""
``GET/service/{service_id}/version/{version_id}/domain/check_all`` against
Fastly mock returns an array with the status of all domain DNS records
for a service version.
"""
uri = self.uri + '/service/{0}/version/{1}/domain' \
'?name=llamallama&comment=redpajama'.format(
self.service_id, self.version_id)
(response, json_body) = self.successResultOf(json_request(
self, self.root, b"POST", uri))
uri = self.uri + '/service/{0}/version/{1}/domain/check_all' \
'?name=llamallama&comment=redpajama'.format(
self.service_id, self.version_id)
(response, json_body) = self.successResultOf(json_request(
self, self.root, b"GET", uri))
domain_details = self.fastly_response.check_domains(
service_id=self.service_id,
service_version=self.version_id)
self.assertEqual(200, response.code)
self.assertEqual(sorted(json_body), sorted(domain_details))
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:25,代码来源:test_fastly.py
示例2: test_check_existing_username_is_true
def test_check_existing_username_is_true(self):
"""
Checking a username that exists gets a true response.
"""
(resp, _) = self.successResultOf(json_request(
self, self.root, b"POST", '{0}/yo/'.format(self.uri),
json.dumps({'username': 'TESTUSER4',
'api_key': 'A1234567890'}).encode("utf-8")))
self.assertEquals(resp.code, 200)
(resp, data) = self.successResultOf(json_request(
self, self.root, b"GET", '{0}/check_username/?username=TESTUSER4'.format(self.uri)))
self.assertEquals(resp.code, 200)
self.assertEquals(data['exists'], True)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:13,代码来源:test_yo.py
示例3: test_create_then_get_node_with_mimimum_attributes
def test_create_then_get_node_with_mimimum_attributes(self):
"""
Test create node then get the node and verify attributes
"""
(response, content) = self.successResultOf(json_request(
self, self.root, "POST", self.url, body=json.dumps({})))
self.assertEqual(response.code, 201)
node_id = str(content['uuid'])
self.assertFalse(content['properties']['memory_mb'])
# get node
(response, get_content) = self.successResultOf(json_request(
self, self.root, "GET", self.url + '/' + node_id))
self.assertEqual(200, response.code)
self.assertEqual(content, get_content)
开发者ID:ayersek64,项目名称:mimic,代码行数:15,代码来源:test_ironic.py
示例4: test_invalid_template_id
def test_invalid_template_id(self):
"""
PUT requires the endpoint template id to match an existing endpoint
template, otherwise results in 404.
"""
self.core.add_api(self.eeapi)
id_key = get_template_id(self, self.eeapi)
self.eeapi.remove_template(id_key)
data = {
'id': id_key,
'name': self.eeapi_name,
'type': self.eeapi.type_key,
'region': 'some-region'
}
self.headers[b'serviceid'] = [self.eeapi.uuid_key.encode('utf8')]
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
body=data,
headers=self.headers))
self.assertEqual(response.code, 404)
self.assertEqual(json_body['itemNotFound']['code'], 404)
self.assertEqual(
json_body['itemNotFound']['message'],
"Unable to update non-existent template. Template must "
"first be added before it can be updated.",
)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:31,代码来源:test_identity_oskscatalog.py
示例5: test_test_alarm_clearing_response
def test_test_alarm_clearing_response(self):
"""
Sending HTTP DELETE to the entity's test-alarm response
causes the response to be cleared and not returned later.
"""
resp = self.successResultOf(
request(self, self.root, "PUT",
'{0}/entities/{1}/alarms/test_response'.format(
self.ctl_uri, self.entity_id),
json.dumps([{'state': 'OK',
'status': 'test-alarm working OK'}])))
self.assertEquals(resp.code, 204)
resp = self.successResultOf(request(self, self.root, "DELETE",
'{0}/entities/{1}/alarms/test_response'.format(
self.ctl_uri, self.entity_id)))
self.assertEquals(resp.code, 204)
(resp, data) = self.successResultOf(
json_request(self, self.root, "POST",
self.uri + '/entities/' + self.entity_id + '/test-alarm',
json.dumps({'criteria': 'return new AlarmStatus(OK);',
'check_data': [{}]})))
self.assertEquals(resp.code, 200)
self.assertEquals(1, len(data))
self.assertNotEquals('test-alarm working OK', data[0]['status'])
开发者ID:raghav3259,项目名称:mimic,代码行数:26,代码来源:test_maas.py
示例6: test_new_endpoint_template_wrong_service_type
def test_new_endpoint_template_wrong_service_type(self):
"""
PUT requires that the service matches, otherwise results in 409.
"""
self.core.add_api(self.eeapi)
data = {
'id': self.ept_template_id,
'name': self.eeapi_name,
'type': 'some-type',
'region': 'some-region'
}
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
body=data,
headers=self.headers))
self.assertEqual(response.code, 409)
self.assertEqual(json_body['conflict']['code'], 409)
self.assertEqual(
json_body['conflict']['message'],
"Endpoint already exists and service id or service type does not "
"match."
)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:25,代码来源:test_identity_oskscatalog.py
示例7: test_json_body_missing_required_field_name
def test_json_body_missing_required_field_name(self, remove_field):
"""
PUT - required fields must be present otherwise 400 is generated.
"""
data = {
'id': self.ept_template_id,
'name': 'some-name',
'type': 'some-type',
'region': 'some-region'
}
del data[remove_field]
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
body=data,
headers=self.headers))
self.assertEqual(response.code, 400)
self.assertEqual(json_body['badRequest']['code'], 400)
self.assertTrue(
json_body['badRequest']['message'].startswith(
"JSON body does not contain the required parameters:"
)
)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:25,代码来源:test_identity_oskscatalog.py
示例8: test_send_yo_to_same_username_gets_same_userid
def test_send_yo_to_same_username_gets_same_userid(self):
"""
Sending a Yo to the same username twice causes the same user ID
to come back in the response.
"""
(resp, data1) = self.successResultOf(json_request(
self, self.root, b"POST", '{0}/yo/'.format(self.uri),
json.dumps({'username': 'TESTUSER2',
'api_key': 'A1234567890'}).encode("utf-8")))
self.assertEquals(resp.code, 200)
(resp, data2) = self.successResultOf(json_request(
self, self.root, b"POST", '{0}/yo/'.format(self.uri),
json.dumps({'username': 'TESTUSER2',
'api_key': 'A1234567890'}).encode("utf-8")))
self.assertEquals(resp.code, 200)
self.assertEquals(data1['recipient']['user_id'], data2['recipient']['user_id'])
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:16,代码来源:test_yo.py
示例9: test_get_token_and_catalog_for_api_credentials
def test_get_token_and_catalog_for_api_credentials(self):
"""
The response returned should include the credentials that were supplied
during authentication
"""
core = MimicCore(Clock(), [ExampleAPI()])
root = MimicRoot(core).app.resource()
(response, json_body) = self.successResultOf(json_request(
self, root, "POST", "/identity/v2.0/tokens",
{
"auth": {
"RAX-KSKEY:apiKeyCredentials": {
"username": "demoauthor",
"apiKey": "jhgjhghg-nhghghgh-12222"
},
"tenantName": "12345"
}
}
))
self.assertEqual(response.code, 200)
tenant_id = json_body["access"]["token"]["tenant"]["id"]
self.assertEqual(tenant_id, "12345")
tenant_name = json_body["access"]["token"]["tenant"]["name"]
self.assertEqual(tenant_name, tenant_id)
user_name = json_body["access"]["user"]["name"]
self.assertEqual(user_name, "demoauthor")
开发者ID:isaacm,项目名称:mimic,代码行数:27,代码来源:test_auth.py
示例10: register_behavior
def register_behavior(test_case, root, uri, behavior_name, parameters,
criteria):
"""
Register a particular behavior.
:param test_case: the test case with which to make assertions
:param root: A mimic root API object
:param str uri: The uri fo the behavior resource to register.
:param str behavior_name: The name of the behavior
:param dict parameters: A dictionary of parameters to pass to the behavior
:param list criteria: The criteria for which this behavior should be
applied.
:return: The behavior ID of the registered behavior.
"""
behavior_json = {"name": behavior_name,
"parameters": parameters,
"criteria": criteria}
response, body = test_case.successResultOf(json_request(
test_case, root, "POST", uri, json.dumps(behavior_json)))
test_case.assertEqual(response.code, 201)
behavior_id = body.get("id")
test_case.assertIsInstance(behavior_id, string_types)
test_case.assertEqual(UUID(behavior_id).version, 4)
return behavior_id
开发者ID:raghav3259,项目名称:mimic,代码行数:26,代码来源:behavior_tests.py
示例11: test_multiple_external_apis
def test_multiple_external_apis(self):
"""
GET can retrieve numerous External APIs that have External API Templates.
"""
api_list = [
make_example_external_api(
self,
name=self.eeapi_name + text_type(uuid.uuid4()),
service_type='service-' + text_type(uuid.uuid4())
)
for ignored in range(10)
]
# eeapi needs to be the first in the list
api_list.insert(0, self.eeapi)
for api in api_list:
self.core.add_api(api)
self.assertEqual(len(self.core._uuid_to_api_external),
len(api_list))
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
headers=self.headers))
self.assertEqual(response.code, 200)
self.assertEqual(len(json_body['OS-KSCATALOG']),
len(api_list))
self.assertEqual(
len(json_body['OS-KSCATALOG:endpointsTemplates_links']),
0)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:32,代码来源:test_identity_oskscatalog.py
示例12: test_json_body_missing_required_field
def test_json_body_missing_required_field(self, remove_field):
"""
POST requires 'name' field otherwise 400 is generated.
"""
# normal JSON body
data = {
'type': 'some-type',
'name': 'some-name'
}
# remove a portion of the body per the DDT data
del data[remove_field]
# POST the resulting JSON to the REST API
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
body=data,
headers=self.headers))
# API should return 400 since a required field is missing
self.assertEqual(response.code, 400)
self.assertEqual(json_body['badRequest']['code'], 400)
self.assertEqual(json_body['badRequest']['message'],
"Invalid Content. 'name' and 'type' fields are "
"required.")
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:25,代码来源:test_identity_osksadm.py
示例13: test_response_service_catalog_has_base_uri
def test_response_service_catalog_has_base_uri(self):
"""
The JSON response's service catalog whose endpoints all begin with
the same base URI as the request.
"""
core = MimicCore(Clock(), [ExampleAPI()])
root = MimicRoot(core).app.resource()
(response, json_body) = self.successResultOf(json_request(
self, root, "POST", "http://mybase/identity/v2.0/tokens",
{
"auth": {
"passwordCredentials": {
"username": "demoauthor",
"password": "theUsersPassword"
}
}
}
))
self.assertEqual(200, response.code)
services = json_body['access']['serviceCatalog']
self.assertEqual(1, len(services))
urls = [
endpoint['publicURL'] for endpoint in services[0]['endpoints']
]
self.assertEqual(1, len(urls))
self.assertTrue(urls[0].startswith('http://mybase/'),
'{0} does not start with "http://mybase"'
.format(urls[0]))
开发者ID:lvh,项目名称:mimic,代码行数:31,代码来源:test_auth.py
示例14: test_auth_accepts_tenant_name
def test_auth_accepts_tenant_name(self):
"""
If "tenantName" is passed, the tenant specified is used instead of a
generated tenant ID.
"""
core = MimicCore(Clock(), [])
root = MimicRoot(core).app.resource()
(response, json_body) = self.successResultOf(json_request(
self, root, "POST", "/identity/v2.0/tokens",
{
"auth": {
"passwordCredentials": {
"username": "demoauthor",
"password": "theUsersPassword"
},
"tenantName": "turtlepower"
}
}
))
self.assertEqual(200, response.code)
self.assertEqual("turtlepower",
json_body['access']['token']['tenant']['id'])
token = json_body['access']['token']['id']
session = core.sessions.session_for_token(token)
self.assertEqual(token, session.token)
self.assertEqual("turtlepower", session.tenant_id)
开发者ID:lvh,项目名称:mimic,代码行数:28,代码来源:test_auth.py
示例15: test_response_has_auth_token
def test_response_has_auth_token(self):
"""
The JSON response has a access.token.id key corresponding to its
MimicCore session, and therefore access.token.tenant.id should match
that session's tenant_id.
"""
core = MimicCore(Clock(), [])
root = MimicRoot(core).app.resource()
(response, json_body) = self.successResultOf(json_request(
self, root, "POST", "/identity/v2.0/tokens",
{
"auth": {
"passwordCredentials": {
"username": "demoauthor",
"password": "theUsersPassword"
}
}
}
))
self.assertEqual(200, response.code)
token = json_body['access']['token']['id']
tenant_id = json_body['access']['token']['tenant']['id']
session = core.sessions.session_for_token(token)
self.assertEqual(token, session.token)
self.assertEqual(tenant_id, session.tenant_id)
开发者ID:lvh,项目名称:mimic,代码行数:28,代码来源:test_auth.py
示例16: test_get_token_and_catalog_for_token_credentials
def test_get_token_and_catalog_for_token_credentials(self):
"""
The response returned should include the credentials that were supplied
during authentication
"""
core = MimicCore(Clock(), [ExampleAPI()])
root = MimicRoot(core).app.resource()
(response, json_body) = self.successResultOf(json_request(
self, root, "POST", "/identity/v2.0/tokens",
{
"auth": {
"tenantId": "12345",
"token": {
"id": "iuyiuyiuy-uyiuyiuy-1987878"
}
}
}
))
self.assertEqual(response.code, 200)
tenant_id = json_body["access"]["token"]["tenant"]["id"]
self.assertEqual(tenant_id, "12345")
tenant_name = json_body["access"]["token"]["tenant"]["name"]
self.assertEqual(tenant_name, tenant_id)
user_name = json_body["access"]["user"]["name"]
self.assertTrue(user_name)
开发者ID:isaacm,项目名称:mimic,代码行数:26,代码来源:test_auth.py
示例17: test_multiple_external_apis
def test_multiple_external_apis(self):
"""
GET will list multiple external APIs.
"""
api_list = [
make_example_external_api(
self,
name=self.eeapi_name + text_type(uuid.uuid4()),
service_type='service-' + text_type(uuid.uuid4()),
set_enabled=True
)
for ignored in range(10)
]
# eeapi should be the first entry in the list
api_list.insert(0, self.eeapi)
for api in api_list:
self.core.add_api(api)
self.assertEqual(len(self.core._uuid_to_api_external),
len(api_list))
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
headers=self.headers))
def get_header(header_name):
return response.headers.getRawHeaders(header_name)[0].decode("utf-8")
self.assertEqual(response.code, 200)
self.assertEqual(len(json_body['endpoints']),
len(api_list))
self.assertEqual(len(json_body['endpoints_links']), 0)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:35,代码来源:test_identity_oskscatalog_per_tenant.py
示例18: test_create_condition
def test_create_condition(self):
"""
``POST /service/{service_id}/version/{version_id}/condition`` against
Fastly mock creates a condition (rule) for a particular service and
version and returns JSON-serialized response.
"""
uri = self.uri + '/service/{0}/version/{1}/condition' \
'?name=testcondition&statement=req.url~+"index.html"&priority=10'.format(
self.service_id, self.version_id)
(response, json_body) = self.successResultOf(json_request(
self, self.root, b"POST", uri))
url_data = [
('name', ['testcondition']),
('statement', ['req.url~+"index.html"']),
('priority', [10])
]
condition = self.fastly_response.create_condition(
url_data=url_data,
service_id=self.service_id,
service_version=self.version_id)
self.assertEqual(200, response.code)
self.assertEqual(sorted(json_body), sorted(condition))
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:25,代码来源:test_fastly.py
示例19: test_create_response_object
def test_create_response_object(self):
"""
``POST /service/{service_id}/version/{version_id}/response_object`` against
Fastly mock creates a response_object for a particular service and
version and returns JSON-serialized response.
"""
uri = self.uri + '/service/{0}/version/{1}/response_object' \
'?status=200&response=Ok&name=testresponse&content=this+message+means+all+is+okay'.format(
self.service_id, self.version_id)
(response, json_body) = self.successResultOf(json_request(
self, self.root, b"POST", uri))
url_data = [
('status', ['200']),
('response', ['Ok']),
('cache_condition', [""]),
('request_condition', [""]),
('name', ['testresponse']),
('content', ['this+message+means+all+is+okay']),
('content_type', ["text/plain"]),
('service_id', [self.service_id])
]
response_object = self.fastly_response.create_response_object(
url_data=url_data,
service_id=self.service_id,
service_version=self.version_id)
self.assertEqual(200, response.code)
self.assertEqual(sorted(json_body), sorted(response_object))
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:31,代码来源:test_fastly.py
示例20: test_invalid_service_id_in_json_body
def test_invalid_service_id_in_json_body(self):
"""
POST - Service ID must be valid, otherwise results in 404.
"""
# Add a second API
eeapi2 = make_example_external_api(
self,
name='d' + self.eeapi_name + text_type(uuid.uuid4()),
service_type='service-' + text_type(uuid.uuid4())
)
eeapi2.id_key = '0'
# ensure only one instance of the API has the endpoint template
eeapi2.remove_template(get_template_id(self, eeapi2))
self.core.add_api(eeapi2)
self.core.add_api(self.eeapi)
data = {
'id': text_type(uuid.uuid4()),
'name': 'some-name',
'type': 'some-type',
'region': 'some-region'
}
(response, json_body) = self.successResultOf(
json_request(self, self.root, self.verb,
self.uri,
body=data,
headers=self.headers))
self.assertEqual(response.code, 404)
self.assertEqual(json_body['itemNotFound']['code'], 404)
self.assertEqual(
json_body['itemNotFound']['message'],
"Service API for endoint template not found"
)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:35,代码来源:test_identity_oskscatalog.py
注:本文中的mimic.test.helpers.json_request函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论