当前位置: 首页>>代码示例>>Python>>正文


Python fake_http.fake_http_response函数代码示例

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


在下文中一共展示了fake_http_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_auth

    def test_auth(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None, status=201,
        )
        body = {'access': {'token': 'fake_token'}}

        with mock.patch.object(token_client_v3, 'post') as post_mock:
            post_mock.return_value = response, body
            resp = token_client_v3.auth(username='fake_user',
                                        password='fake_pass')

        self.assertIsInstance(resp, rest_client.ResponseBody)
        req_dict = json.dumps({
            'auth': {
                'identity': {
                    'methods': ['password'],
                    'password': {
                        'user': {
                            'name': 'fake_user',
                            'password': 'fake_pass',
                        }
                    }
                },
            }
        }, sort_keys=True)
        post_mock.assert_called_once_with('fake_url/auth/tokens',
                                          body=req_dict)
开发者ID:bigswitch,项目名称:tempest,代码行数:28,代码来源:test_token_client.py

示例2: _fake_v3_response

def _fake_v3_response(self, uri, method="GET", body=None, headers=None,
                      redirections=5, connection_type=None):
    fake_headers = {
        "x-subject-token": TOKEN
    }
    return (fake_http.fake_http_response(fake_headers, status=201),
            json.dumps(IDENTITY_V3_RESPONSE))
开发者ID:Tesora,项目名称:tesora-tempest,代码行数:7,代码来源:fake_identity.py

示例3: raw_request

 def raw_request(*args, **kwargs):
     self.assertIn("X-OpenStack-Nova-API-Version", kwargs["headers"])
     self.assertEqual("2.2", kwargs["headers"]["X-OpenStack-Nova-API-Version"])
     return (
         fake_http.fake_http_response(headers={self.client.api_microversion_header_name: "2.2"}, status=200),
         "",
     )
开发者ID:mshalamov,项目名称:tempest,代码行数:7,代码来源:test_base_compute_client.py

示例4: test_no_microverion_header_in_response

 def test_no_microverion_header_in_response(self, mock_request):
     response = fake_http.fake_http_response(
         headers={},
     )
     mock_request.return_value = response, ''
     self.assertRaises(exceptions.InvalidHTTPResponseHeader,
                       self.client.get, 'fake_url')
开发者ID:Juniper,项目名称:tempest,代码行数:7,代码来源:test_base_compute_client.py

示例5: raw_request

 def raw_request(*args, **kwargs):
     self.assertIn('X-OpenStack-Nova-API-Version', kwargs['headers'])
     self.assertEqual('2.2',
                      kwargs['headers']['X-OpenStack-Nova-API-Version'])
     return (fake_http.fake_http_response(
         headers={self.client.api_microversion_header_name: '2.2'},
         status=200), '')
开发者ID:Juniper,项目名称:tempest,代码行数:7,代码来源:test_base_compute_client.py

示例6: create_response

 def create_response(self, body, to_utf=False, status=200, headers=None):
     json_body = {}
     if body:
         json_body = json.dumps(body)
         if to_utf:
             json_body = json_body.encode('utf-8')
     resp = fake_http.fake_http_response(headers, status=status), json_body
     return resp
开发者ID:Juniper,项目名称:tempest,代码行数:8,代码来源:base.py

示例7: test_date_time_or_null_format

 def test_date_time_or_null_format(self):
     instance = None
     resp = fake_http.fake_http_response('', status=200)
     body = {'date-time': instance}
     rest_client.RestClient.validate_response(self.date_time_schema[1],
                                              resp, body)
     self.assertRaises(exceptions.InvalidHTTPResponseBody,
                       rest_client.RestClient.validate_response,
                       self.date_time_schema[0], resp, body)
开发者ID:Juniper,项目名称:tempest,代码行数:9,代码来源:test_jsonschema_validator.py

示例8: test_valid_date_time_format

 def test_valid_date_time_format(self):
     valid_instances = ['2016-10-02T10:00:00-05:00',
                        '2016-10-02T10:00:00+09:00',
                        '2016-10-02T15:00:00Z',
                        '2016-10-02T15:00:00.05Z']
     resp = fake_http.fake_http_response('', status=200)
     for instance in valid_instances:
         body = {'date-time': instance}
         for schema in self.date_time_schema:
             rest_client.RestClient.validate_response(schema, resp, body)
开发者ID:Juniper,项目名称:tempest,代码行数:10,代码来源:test_jsonschema_validator.py

示例9: _fake_auth_failure_response

def _fake_auth_failure_response():
    # the response body isn't really used in this case, but lets send it anyway
    # to have a safe check in some future change on the rest client.
    body = {
        "unauthorized": {
            "message": "Unauthorized",
            "code": "401"
        }
    }
    return fake_http.fake_http_response({}, status=401), json.dumps(body)
开发者ID:Tesora,项目名称:tesora-tempest,代码行数:10,代码来源:fake_identity.py

示例10: _test_is_resource_deleted

 def _test_is_resource_deleted(self, flavor_id, is_deleted=True,
                               bytes_body=False):
     body = json.dumps({'flavors': [TestFlavorsClient.FAKE_FLAVOR]})
     if bytes_body:
         body = body.encode('utf-8')
     response = fake_http.fake_http_response({}, status=200), body
     self.useFixture(fixtures.MockPatch(
         'tempest.lib.common.rest_client.RestClient.get',
         return_value=response))
     self.assertEqual(is_deleted,
                      self.client.is_resource_deleted(flavor_id))
开发者ID:Juniper,项目名称:tempest,代码行数:11,代码来源:test_flavors_client.py

示例11: test_request_with_str_body

    def test_request_with_str_body(self):
        token_client_v2 = token_client.TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None, status=200,
        )
        body = str('{"access": {"token": "fake_token"}}')

        with mock.patch.object(token_client_v2, 'raw_request') as mock_raw_r:
            mock_raw_r.return_value = response, body
            resp, body = token_client_v2.request('GET', 'fake_uri')
        self.assertIsInstance(body, dict)
开发者ID:HybridF5,项目名称:tempest,代码行数:11,代码来源:test_token_client.py

示例12: test_create_request_token

    def test_create_request_token(self):
        mock_resp = self._mock_token_response(self.FAKE_CREATE_REQUEST_TOKEN)
        resp = fake_http.fake_http_response(None, status=201), mock_resp
        self.useFixture(fixtures.MockPatch(
            'tempest.lib.common.rest_client.RestClient.post',
            return_value=resp))

        resp = self.client.create_request_token(
            consumer_key='12345',
            consumer_secret='23456',
            project_id='c8f58432c6f00162f04d3250f')
        self.assertEqual(self.FAKE_CREATE_REQUEST_TOKEN, resp)
开发者ID:Juniper,项目名称:tempest,代码行数:12,代码来源:test_oauth_token_client.py

示例13: test_update_resource

    def test_update_resource(self, mock_put):
        response = fake_http.fake_http_response(headers=None, status=200)
        mock_put.return_value = response, '{"baz": "qux"}'

        put_data = {'foo': 'bar'}
        resp = self.client.update_resource('/fake_url', put_data)

        self.assertEqual({'status': '200'}, resp.response)
        self.assertEqual("qux", resp["baz"])
        mock_put.assert_called_once_with('v2.0/fake_url', '{"foo": "bar"}')
        self.mock_expected_success.assert_called_once_with(
            200, 200)
开发者ID:Juniper,项目名称:tempest,代码行数:12,代码来源:test_base_network_client.py

示例14: test_update_resource_expect_different_values

    def test_update_resource_expect_different_values(self, mock_put):
        response = fake_http.fake_http_response(headers=None, status=201)
        mock_put.return_value = response, '{}'

        put_data = {'foo': 'bar'}
        resp = self.client.update_resource('/fake_url', put_data,
                                           expect_response_code=201,
                                           expect_empty_body=True)

        self.assertEqual({'status': '201'}, resp.response)
        self._assert_empty(resp)
        mock_put.assert_called_once_with('v2.0/fake_url', '{"foo": "bar"}')
        self.mock_expected_success.assert_called_once_with(
            201, 201)
开发者ID:Juniper,项目名称:tempest,代码行数:14,代码来源:test_base_network_client.py

示例15: test_create_access_token

    def test_create_access_token(self):
        mock_resp = self._mock_token_response(self.FAKE_CREATE_ACCESS_TOKEN)
        req_secret = self.FAKE_CREATE_REQUEST_TOKEN['oauth_token_secret']
        resp = fake_http.fake_http_response(None, status=201), mock_resp
        self.useFixture(fixtures.MockPatch(
            'tempest.lib.common.rest_client.RestClient.post',
            return_value=resp))

        resp = self.client.create_access_token(
            consumer_key='12345',
            consumer_secret='23456',
            request_key=self.FAKE_CREATE_REQUEST_TOKEN['oauth_token'],
            request_secret=req_secret,
            oauth_verifier='8171')
        self.assertEqual(self.FAKE_CREATE_ACCESS_TOKEN, resp)
开发者ID:Juniper,项目名称:tempest,代码行数:15,代码来源:test_oauth_token_client.py


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