本文整理汇总了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)
示例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))
示例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),
"",
)
示例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')
示例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), '')
示例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
示例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)
示例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)
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)