本文整理汇总了Python中mimic.test.helpers.request函数的典型用法代码示例。如果您正苦于以下问题:Python request函数的具体用法?Python request怎么用?Python request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_balancer_goes_into_pending_update_state
def test_load_balancer_goes_into_pending_update_state(self):
"""
Test to verify a load balancer goes into PENDING-UPDATE state, for
the given time in seconds when any action other than DELETE is performed
on the lb.
Adding a node to a loadbalancer in PENDING-UPDATE state results in 422.
And such a load balancer can be deleted.
"""
metadata = [{"key": "lb_pending_update", "value": 30}]
create_response = self._create_loadbalancer_for_given_metadata(metadata)
self.assertEqual(create_response.code, 202)
create_lb_response_body = self.successResultOf(treq.json_content(create_response))
lb = create_lb_response_body["loadBalancer"]
self.assertEqual(lb["status"], "ACTIVE")
create_node_response = self._add_node_to_lb(lb["id"])
self.assertEqual(create_node_response.code, 200)
# get loadbalncer after adding node and verify its in PENDING-UPDATE state
errored_lb = self._get_loadbalancer(lb["id"])
self.assertEqual(errored_lb["loadBalancer"]["status"], "PENDING-UPDATE")
# Trying to add/list/delete node on a lb in PENDING-UPDATE state, results in 422
create_node_response = self._add_node_to_lb(lb["id"])
self.assertEqual(create_node_response.code, 422)
delete_nodes = request(
self, self.root, "DELETE", self.uri + '/loadbalancers/' +
str(lb["id"]) + '/nodes/123')
self.assertEqual(self.successResultOf(delete_nodes).code, 422)
# An lb in PENDING-UPDATE state can be deleted
delete_lb = request(self, self.root, "DELETE", self.uri + '/loadbalancers/' +
str(lb["id"]))
delete_lb_response = self.successResultOf(delete_lb)
self.assertEqual(delete_lb_response.code, 202)
示例2: test_test_check_clears_metrics
def test_test_check_clears_metrics(self):
"""
The test-check control API can clear metrics.
..note: Randomly generated string metrics are between 12 and 30
characters long.
"""
options = {'data': 'really great forty-three character sentence'}
resp = self.successResultOf(
request(self, self.root, "PUT",
'{0}/entities/{1}/checks/test_responses/{2}'.format(
self.ctl_uri, self.entity_id, 'agent.filesystem'),
json.dumps([{'metrics': {'options': options}}])))
self.assertEquals(resp.code, 204)
resp = self.successResultOf(
request(self, self.root, "DELETE",
'{0}/entities/{1}/checks/test_responses/{2}'.format(
self.ctl_uri, self.entity_id, 'agent.filesystem')))
self.assertEquals(resp.code, 204)
(resp, data) = self.successResultOf(
json_request(self, self.root, "POST",
self.uri + '/entities/' + self.entity_id + '/test-check',
json.dumps({'type': 'agent.filesystem'})))
self.assertEquals(resp.code, 200)
self.assertTrue(len(data[0]['metrics']['options']['data']) < 43)
示例3: 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'])
示例4: test_agenthostinfo
def test_agenthostinfo(self):
"""
fetch agent host info
"""
for q in range(4):
req = request(self, self.root, "GET",
self.uri + '/views/agent_host_info?entityId=' + self.entity_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 400)
data = self.get_responsebody(resp)
self.assertEquals(True, 'Agent does not exist' in json.dumps(data))
req = request(self, self.root, "GET",
self.uri + '/views/agent_host_info?entityId=' + self.entity_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 200)
data = self.get_responsebody(resp)
self.assertEquals(True, self.entity_id == data['values'][0]['entity_id'])
req = request(self, self.root, "GET",
self.uri + '/views/agent_host_info')
resp = self.successResultOf(req)
self.assertEquals(resp.code, 400)
data = self.get_responsebody(resp)
self.assertEquals(True, data['type'] == 'badRequest')
req = request(self, self.root, "GET",
self.uri + '/views/agent_host_info?entityId=enDoesNotExist')
resp = self.successResultOf(req)
self.assertEquals(resp.code, 404)
data = self.get_responsebody(resp)
self.assertEquals(data['type'], 'notFoundError')
示例5: test_delete_server_fails_specified_number_of_times
def test_delete_server_fails_specified_number_of_times(self):
"""
Test to verify :func: `delete_server` does not delete the server,
and returns the given response code, the number of times specified
in the metadata
"""
deletefail = {"times": 1, "code": 500}
metadata = {"delete_server_failure": json.dumps(deletefail)}
# create server and verify it was successful
create_server_response = self.create_server(metadata=metadata)
self.assertEquals(create_server_response.code, 202)
create_server_response_body = self.successResultOf(
treq.json_content(create_server_response))
# delete server and verify the response
delete_server = request(self, self.root, "DELETE", self.uri + '/servers/'
+ create_server_response_body["server"]["id"])
delete_server_response = self.successResultOf(delete_server)
self.assertEqual(delete_server_response.code, 500)
# get server and verify the server was not deleted
get_server = request(self, self.root, "GET", self.uri + '/servers/' +
create_server_response_body["server"]["id"])
get_server_response = self.successResultOf(get_server)
self.assertEquals(get_server_response.code, 200)
# delete server again and verify the response
delete_server = request(self, self.root, "DELETE", self.uri + '/servers/'
+ create_server_response_body["server"]["id"])
delete_server_response = self.successResultOf(delete_server)
self.assertEqual(delete_server_response.code, 204)
self.assertEqual(self.successResultOf(treq.content(delete_server_response)),
b"")
# get server and verify the server was deleted this time
get_server = request(self, self.root, "GET", self.uri + '/servers/' +
create_server_response_body["server"]["id"])
get_server_response = self.successResultOf(get_server)
self.assertEquals(get_server_response.code, 404)
示例6: setUp
def setUp(self):
"""
Create a :obj:`MimicCore` with :obj:`QueueApi` as the only plugin,
and create a queue
"""
self.clock = Clock()
self.core = MimicCore(self.clock, [QueueApi()])
self.root = MimicRoot(self.core).app.resource()
self.response = request(
self, self.root, b"POST", "/identity/v2.0/tokens",
json.dumps({
"auth": {
"passwordCredentials": {
"username": "testQueue",
"password": "testQueuePassword",
},
}
}).encode("utf-8")
)
self.auth_response = self.successResultOf(self.response)
self.json_body = self.successResultOf(
treq.json_content(self.auth_response))
self.uri = self.json_body['access']['serviceCatalog'][0]['endpoints'][0]['publicURL']
self.queue_name = "test_queue"
self.create_queue = request(
self, self.root, b"PUT", self.uri + '/queues/' + self.queue_name)
self.create_queue_response = self.successResultOf(self.create_queue)
示例7: test_server_in_building_state_for_specified_time
def test_server_in_building_state_for_specified_time(self):
"""
Test to verify :func:`create_server` creates a server in BUILD
status for the time specified in the metadata.
"""
metadata = {"server_building": 1}
# create server with metadata to keep the server in building state for
# 3 seconds
create_server_response = self.create_server(metadata=metadata)
# verify the create server was successful
self.assertEquals(create_server_response.code, 202)
create_server_response_body = self.successResultOf(
treq.json_content(create_server_response))
# get server and verify status is BUILD
get_server = request(self, self.root, "GET", self.uri + '/servers/' +
create_server_response_body["server"]["id"])
get_server_response = self.successResultOf(get_server)
get_server_response_body = self.successResultOf(
treq.json_content(get_server_response))
self.assertEquals(get_server_response_body['server']['status'], "BUILD")
# Time Passes...
self.helper.clock.advance(2.0)
# get server and verify status changed to active
get_server = request(self, self.root, "GET", self.uri + '/servers/' +
create_server_response_body["server"]["id"])
get_server_response = self.successResultOf(get_server)
get_server_response_body = self.successResultOf(
treq.json_content(get_server_response))
self.assertEquals(get_server_response_body['server']['status'], "ACTIVE")
示例8: setUp
def setUp(self):
"""
Create a :obj:`MimicCore` with :obj:`LoadBalancerApi` as the only plugin.
And create a load balancer and add nodes to the load balancer.
"""
helper = APIMockHelper(self, [LoadBalancerApi()])
self.root = helper.root
self.uri = helper.uri
create_lb = request(
self, self.root, "POST", self.uri + '/loadbalancers',
json.dumps({
"loadBalancer": {
"name": "test_lb",
"protocol": "HTTP",
"virtualIps": [{"type": "PUBLIC"}]
}
})
)
create_lb_response = self.successResultOf(create_lb)
self.create_lb_response_body = self.successResultOf(treq.json_content(
create_lb_response))
create_node = request(
self, self.root, "POST", self.uri + '/loadbalancers/' +
str(self.create_lb_response_body["loadBalancer"]["id"]) + '/nodes',
json.dumps({"nodes": [{"address": "127.0.0.1",
"port": 80,
"condition": "ENABLED",
"type": "PRIMARY",
"weight": 10}]})
)
self.create_node_response = self.successResultOf(create_node)
self.create_node_response_body = self.successResultOf(treq.json_content(
self.create_node_response))
self.node = self.create_node_response_body["nodes"]
示例9: test_get_container
def test_get_container(self):
"""
Creating a container and immediately retrieving it yields an empty list
(since there are no objects) and several headers indicating that no
objects are in the container and they consume no space.
"""
self.createSwiftService()
# create a container
uri = (self.json_body['access']['serviceCatalog'][0]['endpoints'][0]
['publicURL'] + '/testcontainer').encode("ascii")
create_container = request(self, self.root, b"PUT", uri)
self.successResultOf(create_container)
container_response = self.successResultOf(
request(self, self.root, b"GET", uri)
)
self.assertEqual(container_response.code, 200)
container_contents = self.successResultOf(
treq.json_content(container_response)
)
self.assertEqual(container_contents, [])
self.assertEqual(
container_response.headers.getRawHeaders(
b"X-Container-Object-Count")[0], b"0"
)
self.assertEqual(
container_response.headers.getRawHeaders(
b"X-Container-Bytes-Used")[0], b"0"
)
示例10: test_delete_alarm
def test_delete_alarm(self):
"""
delete alarm
"""
req = request(self, self.root, "DELETE",
self.uri + '/entities/' + self.entity_id + '/alarms/' + self.alarm_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 204)
req = request(self, self.root, "GET", self.uri + '/views/overview')
resp = self.successResultOf(req)
self.assertEquals(resp.code, 200)
self.assertEquals(0, len(self.get_responsebody(resp)['values'][0]['alarms']))
示例11: test_delete_image
def test_delete_image(self):
"""
Create and then delete Image and validate response
"""
new_image = self.create_image()
response = self.successResultOf(request(
self, self.root, b"DELETE", self.uri + '/' + new_image['id']))
self.assertEqual(204, response.code)
response = self.successResultOf(request(
self, self.root, b"GET", self.uri + '/' + new_image['id']))
self.assertEqual(404, response.code)
示例12: test_delete_entity
def test_delete_entity(self):
"""
delete entity
"""
req = request(self, self.root, "DELETE",
self.uri + '/entities/' + self.entity_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 204)
req = request(self, self.root, "GET", self.uri + '/views/overview')
resp = self.successResultOf(req)
self.assertEquals(resp.code, 200)
data = self.get_responsebody(resp)
self.assertEquals(0, len(data['values']))
self.assertEquals(0, data['metadata']['count'])
示例13: test_delete_check
def test_delete_check(self):
"""
delete check
"""
req = request(self, self.root, "DELETE",
self.uri + '/entities/' + self.entity_id + '/checks/' + self.check_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 204)
req = request(self, self.root, "GET", self.uri + '/views/overview')
resp = self.successResultOf(req)
self.assertEquals(resp.code, 200)
data = self.get_responsebody(resp)
self.assertEquals(0, len(data['values'][0]['checks']))
self.assertEquals(0, len(data['values'][0]['alarms']))
示例14: test_partial_update_entity
def test_partial_update_entity(self):
"""
Update an entity, fields not specified in the body don't change.
"""
data = {'agent_id': 'ag13378901234'}
req = request(self, self.root, "PUT", self.uri + '/entities/' + self.entity_id, json.dumps(data))
resp = self.successResultOf(req)
self.assertEquals(resp.code, 204)
req = request(self, self.root, "GET", self.uri + '/entities/' + self.entity_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 200)
data = self.get_responsebody(resp)
self.assertEquals('ag13378901234', data['agent_id'])
self.assertEquals('ItsAnEntity', data['label'])
示例15: test_update_suppression
def test_update_suppression(self):
"""
Update an suppression
"""
postdata = {'id': self.sp_id, 'label': 'changed'}
req = request(self, self.root, "PUT", self.uri + '/suppressions/' + self.sp_id,
json.dumps(postdata))
resp = self.successResultOf(req)
self.assertEquals(resp.code, 204)
req = request(self, self.root, "GET", self.uri + '/suppressions/' + self.sp_id)
resp = self.successResultOf(req)
self.assertEquals(resp.code, 200)
data = self.get_responsebody(resp)
self.assertEquals('changed', data['label'])