1
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
2
# Copyright 2011 OpenStack Foundation
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
18
from keystoneclient.tests import fakes
19
from keystoneclient.tests.v2_0 import utils
22
class FakeHTTPClient(fakes.FakeClient):
23
def __init__(self, **kwargs):
24
self.username = 'username'
25
self.password = 'password'
26
self.auth_url = 'auth_url'
29
def _cs_request(self, url, method, **kwargs):
30
# Check that certain things are called correctly
31
if method in ['GET', 'DELETE']:
32
assert 'body' not in kwargs
34
kwargs.setdefault('body', None)
37
args = urlparse.parse_qsl(urlparse.urlparse(url)[4])
39
munged_url = url.rsplit('?', 1)[0]
40
munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
41
munged_url = munged_url.replace('-', '_')
43
callback = "%s_%s" % (method.lower(), munged_url)
45
if not hasattr(self, callback):
46
raise AssertionError('Called unknown API method: %s %s, '
47
'expected fakes method name: %s' %
48
(method, url, callback))
51
self.callstack.append((method, url, kwargs.get('body', None)))
53
if not hasattr(self, callback):
54
raise AssertionError('Called unknown API method: %s %s, '
55
'expected fakes method name: %s' %
56
(method, url, callback))
59
self.callstack.append((method, url, kwargs.get('body', None)))
61
status, body = getattr(self, callback)(**kwargs)
62
r = utils.TestResponse({
63
"status_code": status,
70
def post_tokens(self, **kw):
74
{"expires": "2012-02-05T00:00:00",
75
"id": "887665443383838",
78
"name": "customer-x"}},
81
{"adminURL": "http://swift.admin-nets.local:8080/",
82
"region": "RegionOne",
83
"internalURL": "http://127.0.0.1:8080/v1/AUTH_1",
85
"http://swift.publicinternets.com/v1/AUTH_1"}],
86
"type": "object-store",
89
{"adminURL": "http://cdn.admin-nets.local/v1.1/1",
90
"region": "RegionOne",
91
"internalURL": "http://127.0.0.1:7777/v1.1/1",
93
"http://cdn.publicinternets.com/v1.1/1"}],
94
"type": "object-store",
107
def get_tokens_887665443383838(self, **kw):
111
{"expires": "2012-02-05T00:00:00",
112
"id": "887665443383838",
113
"tenant": {"id": "1",
114
"name": "customer-x"}},
117
"tenantName": "customer-x",
128
def get_tokens_887665443383838_endpoints(self, **kw):
130
{"endpoints_links": [
132
"http://127.0.0.1:35357/tokens/887665443383838"
133
"/endpoints?'marker=5&limit=10'",
136
{"internalURL": "http://127.0.0.1:8080/v1/AUTH_1",
138
"adminURL": "http://swift.admin-nets.local:8080/",
139
"region": "RegionOne",
141
"type": "object-store",
143
"publicURL": "http://swift.publicinternets.com/v1/AUTH_1"},
144
{"internalURL": "http://localhost:8774/v1.0",
145
"name": "nova_compat",
146
"adminURL": "http://127.0.0.1:8774/v1.0",
147
"region": "RegionOne",
151
"publicURL": "http://nova.publicinternets.com/v1.0/"},
152
{"internalURL": "http://localhost:8774/v1.1",
154
"adminURL": "http://127.0.0.1:8774/v1.1",
155
"region": "RegionOne",
159
"publicURL": "http://nova.publicinternets.com/v1.1/"},
160
{"internalURL": "http://127.0.0.1:9292/v1.1/",
162
"adminURL": "http://nova.admin-nets.local/v1.1/",
163
"region": "RegionOne",
167
"publicURL": "http://glance.publicinternets.com/v1.1/"},
168
{"internalURL": "http://127.0.0.1:7777/v1.1/1",
170
"adminURL": "http://cdn.admin-nets.local/v1.1/1",
171
"region": "RegionOne",
174
"versionList": "http://127.0.0.1:7777/",
175
"versionInfo": "http://127.0.0.1:7777/v1.1",
176
"type": "object-store",
178
"publicURL": "http://cdn.publicinternets.com/v1.1/1"}]
188
"updated": "2011-11-19T00:00:00Z",
191
"href": "http://127.0.0.1:35357/v2.0/"},
192
{"rel": "describedby",
194
"href": "http://docs.openstack.org/"
195
"api/openstack-identity-service/2.0/content/"},
196
{"rel": "describedby",
197
"type": "application/pdf",
198
"href": "http://docs.openstack.org/api/"
199
"openstack-identity-service/2.0/identity-dev-guide-2.0.pdf"},
200
{"rel": "describedby",
201
"type": "application/vnd.sun.wadl+xml",
202
"href": "http://127.0.0.1:35357/v2.0/identity-admin.wadl"}],
204
{"base": "application/xml",
205
"type": "application/vnd.openstack.identity-v2.0+xml"},
206
{"base": "application/json",
207
"type": "application/vnd.openstack.identity-v2.0+json"}]
212
def get_extensions(self, **kw):
214
"extensions": {"values": []}
218
def post_tenants(self, **kw):
222
"name": "new-tenant",
226
def post_tenants_2(self, **kw):
229
"description": "desc",
230
"name": "new-tenant1",
234
def get_tenants(self, **kw):
244
"name": "new-tenant",
248
"name": "customer-x",
253
def get_tenants_1(self, **kw):
257
"name": "new-tenant",
261
def get_tenants_2(self, **kw):
265
"name": "new-tenant",
269
def delete_tenants_2(self, **kw):
273
def get_tenants_1_users_1_roles(self, **kw):
285
def put_users_1_roles_OS_KSADM_1(self, **kw):
292
def delete_users_1_roles_OS_KSADM_1(self, **kw):
296
def put_tenants_1_users_1_roles_OS_KSADM_1(self, **kw):
303
def get_users(self, **kw):
306
{"name": self.username,
308
"email": "sdfsdf@sdfsd.sdf",
313
"email": "sdfsdf@sdfsd.sdf",
319
def get_users_1(self, **kw):
325
"name": self.username}
329
def put_users_1(self, **kw):
336
"email": "user@email.com"}
340
def put_users_1_OS_KSADM_password(self, **kw):
347
"email": "user@email.com"}
351
def post_users(self, **kw):
357
"name": self.username}
361
def delete_users_1(self, **kw):
365
def get_users_1_roles(self, **kw):
370
"name": "KeystoneServiceAdmin"}]
375
def post_OS_KSADM_roles(self, **kw):
381
def get_OS_KSADM_roles(self, **kw):
383
{"id": "10", "name": "admin"},
384
{"id": "20", "name": "member"},
385
{"id": "1", "name": "new-role"}]
389
def get_OS_KSADM_roles_1(self, **kw):
396
def delete_OS_KSADM_roles_1(self, **kw):
400
def post_OS_KSADM_services(self, **kw):
401
body = {"OS-KSADM:service":
409
def get_OS_KSADM_services_1(self, **kw):
410
body = {"OS-KSADM:service":
411
{"description": None,
418
def get_OS_KSADM_services(self, **kw):
420
"OS-KSADM:services": [
421
{"description": None,
425
{"description": None,
432
def delete_OS_KSADM_services_1(self, **kw):
436
def post_users_1_credentials_OS_EC2(self, **kw):
437
body = {"credential":
445
def get_users_1_credentials_OS_EC2(self, **kw):
446
body = {"credentials": [
454
def get_users_1_credentials_OS_EC2_2(self, **kw):
464
def delete_users_1_credentials_OS_EC2_2(self, **kw):
468
def patch_OS_KSCRUD_users_1(self, **kw):
472
def get_endpoints(self, **kw):
475
{'adminURL': 'http://cdn.admin-nets.local/v1.1/1',
476
'region': 'RegionOne',
477
'internalURL': 'http://127.0.0.1:7777/v1.1/1',
478
'publicURL': 'http://cdn.publicinternets.com/v1.1/1'}],
480
'name': 'nova-compute'
484
def post_endpoints(self, **kw):
487
{"adminURL": "http://swift.admin-nets.local:8080/",
488
"region": "RegionOne",
489
"internalURL": "http://127.0.0.1:8080/v1/AUTH_1",
490
"publicURL": "http://swift.publicinternets.com/v1/AUTH_1"},
492
"name": "nova-compute"