• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python helpers.request函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mimic.test.helpers.request函数的典型用法代码示例。如果您正苦于以下问题:Python request函数的具体用法?Python request怎么用?Python request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了request函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:lvh,项目名称:mimic,代码行数:31,代码来源:test_loadbalancer.py


示例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)
开发者ID:raghav3259,项目名称:mimic,代码行数:28,代码来源:test_maas.py


示例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'])
开发者ID:raghav3259,项目名称:mimic,代码行数:26,代码来源:test_maas.py


示例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')
开发者ID:ayersek64,项目名称:mimic,代码行数:29,代码来源:test_maas.py


示例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)
开发者ID:lvh,项目名称:mimic,代码行数:35,代码来源:test_nova.py


示例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)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:27,代码来源:test_queue.py


示例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")
开发者ID:lvh,项目名称:mimic,代码行数:29,代码来源:test_nova.py


示例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"]
开发者ID:lvh,项目名称:mimic,代码行数:34,代码来源:test_loadbalancer.py


示例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"
     )
开发者ID:derwolfe,项目名称:mimic,代码行数:28,代码来源:test_swift.py


示例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']))
开发者ID:ayersek64,项目名称:mimic,代码行数:12,代码来源:test_maas.py


示例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)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:13,代码来源:test_glance.py


示例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'])
开发者ID:ayersek64,项目名称:mimic,代码行数:14,代码来源:test_maas.py


示例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']))
开发者ID:ayersek64,项目名称:mimic,代码行数:14,代码来源:test_maas.py


示例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'])
开发者ID:ayersek64,项目名称:mimic,代码行数:14,代码来源:test_maas.py


示例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'])
开发者ID:ayersek64,项目名称:mimic,代码行数:14,代码来源:test_maas.py


示例16: test_get_notification_plan

 def test_get_notification_plan(self):
     """
     Get a specific notification plan
     """
     req = request(self, self.root, "GET", self.uri + '/notification_plans/' + self.np_id)
     resp = self.successResultOf(req)
     self.assertEquals(resp.code, 200)
     data = self.get_responsebody(resp)
     self.assertEquals(data['id'], self.np_id)
     req = request(self, self.root, "GET",
                   self.uri + '/notification_plans/npTechnicalContactsEmail')
     resp = self.successResultOf(req)
     self.assertEquals(resp.code, 200)
     data = self.get_responsebody(resp)
     self.assertEquals(data['id'], 'npTechnicalContactsEmail')
开发者ID:ayersek64,项目名称:mimic,代码行数:15,代码来源:test_maas.py


示例17: test_session_created_for_token

    def test_session_created_for_token(self):
        """
        A session is created for the token provided
        """
        core, root = core_and_root([])

        token = '1234567890'

        request(
            self, root, "GET",
            "/identity/v2.0/tokens/{0}/endpoints".format(token)
        )

        session = core.sessions.session_for_token(token)
        self.assertEqual(token, session.token)
开发者ID:raghav3259,项目名称:mimic,代码行数:15,代码来源:test_auth.py


示例18: test_delete_load_balancer_and_pending_delete_state

    def test_delete_load_balancer_and_pending_delete_state(self):
        """
        Test to verify a load balancer goes into PENDING-DELETE state, for
        the given time in seconds and then goes into a DELETED status.
        Also, verify when a load balancer in PENDING-DELETE or DELETED status
        is deleted, response code 400 is returned.
        """
        metadata = [{"key": "lb_pending_delete", "value": 1}]
        lb = self._create_loadbalancer(metadata)

        # Verify the lb status goes into PENDING-DELETE
        del_lb_response = self._delete_loadbalancer(lb["id"])
        self.assertEqual(del_lb_response.code, 202)
        del_lb_content = self.successResultOf(treq.content(del_lb_response))
        self.assertEqual(del_lb_content, '')
        deleted_lb = self._get_loadbalancer(lb["id"])
        self.assertEqual(deleted_lb["loadBalancer"]["status"], "PENDING-DELETE")

        # Trying to delete a lb in PENDING-DELETE status results in 400
        self.assertEqual(self._delete_loadbalancer(lb["id"]).code, 400)
        self.helper.clock.advance(1.0000001)

        # Lb goes into DELETED status after time specified in metadata
        deleted_lb = self._get_loadbalancer(lb["id"])
        self.assertEqual(deleted_lb["loadBalancer"]["status"], "DELETED")

        # Trying to delete a lb in DELETED status results in 400
        self.assertEqual(self._delete_loadbalancer(lb["id"]).code, 400)

        # GET node on load balancer in DELETED status results in 410
        get_node = request(
            self, self.root, "GET", self.uri + '/loadbalancers/' +
            str(lb["id"]) + '/nodes/123')
        get_node_response = self.successResultOf(get_node)
        self.assertEqual(get_node_response.code, 410)

        # List node on load balancer in DELETED status results in 410
        list_nodes = request(
            self, self.root, "GET", self.uri + '/loadbalancers/' + str(lb["id"])
            + '/nodes')
        self.assertEqual(self.successResultOf(list_nodes).code, 410)

        # Progress past "deleting now"
        self.helper.clock.advance(4000)
        list_nodes = request(
            self, self.root, "GET", self.uri + '/loadbalancers/' + str(lb["id"])
            + '/nodes')
        self.assertEqual(self.successResultOf(list_nodes).code, 404)
开发者ID:reaperhulk,项目名称:mimic,代码行数:48,代码来源:test_loadbalancer.py


示例19: test_template_validate

    def test_template_validate(self):
        """
        Test template validation, ensuring correct JSON response.
        """
        req_bodies = {'url': {'template_url': "http://bogus.url/here"},
                      'inline': {'template': "http://bogus.url/here"},
                      'wrong': {}}

        requests = dict(
            (key, request(self, self.root, b"POST", self.uri + '/validate',
                          body=json.dumps(body).encode("utf-8")))
            for (key, body) in req_bodies.items()
        )

        responses = dict(
            (key, self.successResultOf(req)) for (key, req) in requests.items()
        )

        resp_bodies = dict(
            (key, self.get_responsebody(resp))
            for (key, resp) in responses.items() if key != 'wrong')

        self.assertEqual(responses['url'].code, 200)
        self.assertEqual(responses['inline'].code, 200)
        self.assertEqual(responses['wrong'].code, 400)

        self.assertTrue('Parameters' in resp_bodies['url'])
        self.assertTrue('Parameters' in resp_bodies['inline'])
开发者ID:derwolfe,项目名称:mimic,代码行数:28,代码来源:test_heat.py


示例20: test_load_balancer_goes_into_error_state_when_adding_node

 def test_load_balancer_goes_into_error_state_when_adding_node(self):
     """
     Test to verify a load balancer goes into error state when adding a node.
     Adding a node to a loadbalancer in ERROR state results in 422.
     And such a load balancer can only be deleted.
     """
     metadata = [{"key": "lb_error_state", "value": "error"}]
     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 error state
     errored_lb = self._get_loadbalancer(lb["id"])
     self.assertEqual(errored_lb["loadBalancer"]["status"], "ERROR")
     # adding another node to a lb in ERROR state, results in 422
     create_node_response = self._add_node_to_lb(lb["id"])
     self.assertEqual(create_node_response.code, 422)
     # An lb in ERROR 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)
开发者ID:lvh,项目名称:mimic,代码行数:25,代码来源:test_loadbalancer.py



注:本文中的mimic.test.helpers.request函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helper.invalid_resource函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.json_request函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap