~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to keystoneclient/tests/v2_0/fakes.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2013-11-14 10:51:32 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20131114105132-p1o428l7fclasv9e
Tags: 1:0.4.1-0ubuntu1
[ Adam Gandelman ]
* debian/patches: Refreshed.
* debian/patches/use-mox-dependency.patch: Use mox instead of mox3
  dependency.

[ Chuck Short ]
* New upstream release.
* debian/control:
  - open icehouse release.
  - Dropped python-d2to1 and python-httplib2 dependency.
* debian/patches/skip-tests-ubuntu.patch: Dropped no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
 
2
# Copyright 2011 OpenStack Foundation
 
3
#
 
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
 
7
#
 
8
# http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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.
 
15
 
 
16
import urlparse
 
17
 
 
18
from keystoneclient.tests import fakes
 
19
from keystoneclient.tests.v2_0 import utils
 
20
 
 
21
 
 
22
class FakeHTTPClient(fakes.FakeClient):
 
23
    def __init__(self, **kwargs):
 
24
        self.username = 'username'
 
25
        self.password = 'password'
 
26
        self.auth_url = 'auth_url'
 
27
        self.callstack = []
 
28
 
 
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
 
33
        elif method == 'PUT':
 
34
            kwargs.setdefault('body', None)
 
35
 
 
36
        # Call the method
 
37
        args = urlparse.parse_qsl(urlparse.urlparse(url)[4])
 
38
        kwargs.update(args)
 
39
        munged_url = url.rsplit('?', 1)[0]
 
40
        munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
 
41
        munged_url = munged_url.replace('-', '_')
 
42
 
 
43
        callback = "%s_%s" % (method.lower(), munged_url)
 
44
 
 
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))
 
49
 
 
50
        # Note the call
 
51
        self.callstack.append((method, url, kwargs.get('body', None)))
 
52
 
 
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))
 
57
 
 
58
        # Note the call
 
59
        self.callstack.append((method, url, kwargs.get('body', None)))
 
60
 
 
61
        status, body = getattr(self, callback)(**kwargs)
 
62
        r = utils.TestResponse({
 
63
            "status_code": status,
 
64
            "text": body})
 
65
        return r, body
 
66
 
 
67
    #
 
68
    # List all extensions
 
69
    #
 
70
    def post_tokens(self, **kw):
 
71
        body = [
 
72
            {"access":
 
73
                {"token":
 
74
                    {"expires": "2012-02-05T00:00:00",
 
75
                     "id": "887665443383838",
 
76
                     "tenant":
 
77
                        {"id": "1",
 
78
                         "name": "customer-x"}},
 
79
                 "serviceCatalog": [
 
80
                    {"endpoints": [
 
81
                        {"adminURL": "http://swift.admin-nets.local:8080/",
 
82
                         "region": "RegionOne",
 
83
                         "internalURL": "http://127.0.0.1:8080/v1/AUTH_1",
 
84
                         "publicURL":
 
85
                         "http://swift.publicinternets.com/v1/AUTH_1"}],
 
86
                     "type": "object-store",
 
87
                     "name": "swift"},
 
88
                    {"endpoints": [
 
89
                        {"adminURL": "http://cdn.admin-nets.local/v1.1/1",
 
90
                         "region": "RegionOne",
 
91
                         "internalURL": "http://127.0.0.1:7777/v1.1/1",
 
92
                         "publicURL":
 
93
                         "http://cdn.publicinternets.com/v1.1/1"}],
 
94
                     "type": "object-store",
 
95
                     "name": "cdn"}],
 
96
                 "user":
 
97
                    {"id": "1",
 
98
                     "roles": [
 
99
                         {"tenantId": "1",
 
100
                          "id": "3",
 
101
                          "name": "Member"}],
 
102
                 "name": "joeuser"}}
 
103
             }
 
104
        ]
 
105
        return (200, body)
 
106
 
 
107
    def get_tokens_887665443383838(self, **kw):
 
108
        body = [
 
109
            {"access":
 
110
                {"token":
 
111
                    {"expires": "2012-02-05T00:00:00",
 
112
                     "id": "887665443383838",
 
113
                     "tenant": {"id": "1",
 
114
                                "name": "customer-x"}},
 
115
                 "user":
 
116
                 {"name": "joeuser",
 
117
                  "tenantName": "customer-x",
 
118
                  "id": "1",
 
119
                  "roles": [
 
120
                  {"serviceId": "1",
 
121
                          "id": "3",
 
122
                          "name": "Member"}],
 
123
                 "tenantId": "1"}}
 
124
             }
 
125
        ]
 
126
        return (200, body)
 
127
 
 
128
    def get_tokens_887665443383838_endpoints(self, **kw):
 
129
        body = [
 
130
            {"endpoints_links": [
 
131
                {"href":
 
132
                 "http://127.0.0.1:35357/tokens/887665443383838"
 
133
                 "/endpoints?'marker=5&limit=10'",
 
134
                 "rel": "next"}],
 
135
             "endpoints": [
 
136
                 {"internalURL": "http://127.0.0.1:8080/v1/AUTH_1",
 
137
                  "name": "swift",
 
138
                  "adminURL": "http://swift.admin-nets.local:8080/",
 
139
                  "region": "RegionOne",
 
140
                  "tenantId": 1,
 
141
                  "type": "object-store",
 
142
                  "id": 1,
 
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",
 
148
                  "tenantId": 1,
 
149
                  "type": "compute",
 
150
                  "id": 2,
 
151
                  "publicURL": "http://nova.publicinternets.com/v1.0/"},
 
152
                 {"internalURL": "http://localhost:8774/v1.1",
 
153
                  "name": "nova",
 
154
                  "adminURL": "http://127.0.0.1:8774/v1.1",
 
155
                  "region": "RegionOne",
 
156
                  "tenantId": 1,
 
157
                  "type": "compute",
 
158
                  "id": 3,
 
159
                  "publicURL": "http://nova.publicinternets.com/v1.1/"},
 
160
                 {"internalURL": "http://127.0.0.1:9292/v1.1/",
 
161
                  "name": "glance",
 
162
                  "adminURL": "http://nova.admin-nets.local/v1.1/",
 
163
                  "region": "RegionOne",
 
164
                  "tenantId": 1,
 
165
                  "type": "image",
 
166
                  "id": 4,
 
167
                  "publicURL": "http://glance.publicinternets.com/v1.1/"},
 
168
                 {"internalURL": "http://127.0.0.1:7777/v1.1/1",
 
169
                  "name": "cdn",
 
170
                  "adminURL": "http://cdn.admin-nets.local/v1.1/1",
 
171
                  "region": "RegionOne",
 
172
                  "tenantId": 1,
 
173
                  "versionId": "1.1",
 
174
                  "versionList": "http://127.0.0.1:7777/",
 
175
                  "versionInfo": "http://127.0.0.1:7777/v1.1",
 
176
                  "type": "object-store",
 
177
                  "id": 5,
 
178
                  "publicURL": "http://cdn.publicinternets.com/v1.1/1"}]
 
179
             }
 
180
        ]
 
181
        return (200, body)
 
182
 
 
183
    def get(self, **kw):
 
184
        body = {
 
185
            "version": {
 
186
            "id": "v2.0",
 
187
            "status": "beta",
 
188
            "updated": "2011-11-19T00:00:00Z",
 
189
            "links": [
 
190
                {"rel": "self",
 
191
                 "href": "http://127.0.0.1:35357/v2.0/"},
 
192
                {"rel": "describedby",
 
193
                 "type": "text/html",
 
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"}],
 
203
            "media-types": [
 
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"}]
 
208
            }
 
209
        }
 
210
        return (200, body)
 
211
 
 
212
    def get_extensions(self, **kw):
 
213
        body = {
 
214
            "extensions": {"values": []}
 
215
        }
 
216
        return (200, body)
 
217
 
 
218
    def post_tenants(self, **kw):
 
219
        body = {"tenant":
 
220
               {"enabled": True,
 
221
                "description": None,
 
222
                "name": "new-tenant",
 
223
                "id": "1"}}
 
224
        return (200, body)
 
225
 
 
226
    def post_tenants_2(self, **kw):
 
227
        body = {"tenant":
 
228
               {"enabled": False,
 
229
                "description": "desc",
 
230
                "name": "new-tenant1",
 
231
                "id": "2"}}
 
232
        return (200, body)
 
233
 
 
234
    def get_tenants(self, **kw):
 
235
        body = {
 
236
            "tenants_links": [],
 
237
            "tenants": [
 
238
                {"enabled": False,
 
239
                 "description": None,
 
240
                 "name": "project-y",
 
241
                 "id": "1"},
 
242
                {"enabled": True,
 
243
                 "description": None,
 
244
                 "name": "new-tenant",
 
245
                 "id": "2"},
 
246
                {"enabled": True,
 
247
                 "description": None,
 
248
                 "name": "customer-x",
 
249
                 "id": "1"}]
 
250
        }
 
251
        return (200, body)
 
252
 
 
253
    def get_tenants_1(self, **kw):
 
254
        body = {"tenant":
 
255
               {"enabled": True,
 
256
                "description": None,
 
257
                "name": "new-tenant",
 
258
                "id": "1"}}
 
259
        return (200, body)
 
260
 
 
261
    def get_tenants_2(self, **kw):
 
262
        body = {"tenant":
 
263
               {"enabled": True,
 
264
                "description": None,
 
265
                "name": "new-tenant",
 
266
                "id": "2"}}
 
267
        return (200, body)
 
268
 
 
269
    def delete_tenants_2(self, **kw):
 
270
        body = {}
 
271
        return (200, body)
 
272
 
 
273
    def get_tenants_1_users_1_roles(self, **kw):
 
274
        body = {
 
275
            "roles": [
 
276
                {"id": "1",
 
277
                 "name": "Admin"},
 
278
                {"id": "2",
 
279
                 "name": "Member"},
 
280
                {"id": "3",
 
281
                 "name": "new-role"}]
 
282
        }
 
283
        return (200, body)
 
284
 
 
285
    def put_users_1_roles_OS_KSADM_1(self, **kw):
 
286
        body = {
 
287
            "roles":
 
288
            {"id": "1",
 
289
             "name": "Admin"}}
 
290
        return (200, body)
 
291
 
 
292
    def delete_users_1_roles_OS_KSADM_1(self, **kw):
 
293
        body = {}
 
294
        return (200, body)
 
295
 
 
296
    def put_tenants_1_users_1_roles_OS_KSADM_1(self, **kw):
 
297
        body = {
 
298
            "role":
 
299
            {"id": "1",
 
300
             "name": "Admin"}}
 
301
        return (200, body)
 
302
 
 
303
    def get_users(self, **kw):
 
304
        body = {
 
305
            "users": [
 
306
                {"name": self.username,
 
307
                 "enabled": "true",
 
308
                 "email": "sdfsdf@sdfsd.sdf",
 
309
                 "id": "1",
 
310
                 "tenantId": "1"},
 
311
                {"name": "user2",
 
312
                 "enabled": "true",
 
313
                 "email": "sdfsdf@sdfsd.sdf",
 
314
                 "id": "2",
 
315
                 "tenantId": "1"}]
 
316
        }
 
317
        return (200, body)
 
318
 
 
319
    def get_users_1(self, **kw):
 
320
        body = {
 
321
            "user": {
 
322
                "tenantId": "1",
 
323
                "enabled": "true",
 
324
                "id": "1",
 
325
                "name": self.username}
 
326
        }
 
327
        return (200, body)
 
328
 
 
329
    def put_users_1(self, **kw):
 
330
        body = {
 
331
            "user": {
 
332
                "tenantId": "1",
 
333
                "enabled": "true",
 
334
                "id": "1",
 
335
                "name": "new-user1",
 
336
                "email": "user@email.com"}
 
337
        }
 
338
        return (200, body)
 
339
 
 
340
    def put_users_1_OS_KSADM_password(self, **kw):
 
341
        body = {
 
342
            "user": {
 
343
                "tenantId": "1",
 
344
                "enabled": "true",
 
345
                "id": "1",
 
346
                "name": "new-user1",
 
347
                "email": "user@email.com"}
 
348
        }
 
349
        return (200, body)
 
350
 
 
351
    def post_users(self, **kw):
 
352
        body = {
 
353
            "user": {
 
354
                "tenantId": "1",
 
355
                "enabled": "true",
 
356
                "id": "1",
 
357
                "name": self.username}
 
358
        }
 
359
        return (200, body)
 
360
 
 
361
    def delete_users_1(self, **kw):
 
362
        body = []
 
363
        return (200, body)
 
364
 
 
365
    def get_users_1_roles(self, **kw):
 
366
        body = [
 
367
            {"roles_links": [],
 
368
             "roles":[
 
369
                 {"id": "2",
 
370
                  "name": "KeystoneServiceAdmin"}]
 
371
             }
 
372
        ]
 
373
        return (200, body)
 
374
 
 
375
    def post_OS_KSADM_roles(self, **kw):
 
376
        body = {"role":
 
377
               {"name": "new-role",
 
378
                "id": "1"}}
 
379
        return (200, body)
 
380
 
 
381
    def get_OS_KSADM_roles(self, **kw):
 
382
        body = {"roles": [
 
383
                {"id": "10", "name": "admin"},
 
384
                {"id": "20", "name": "member"},
 
385
                {"id": "1", "name": "new-role"}]
 
386
                }
 
387
        return (200, body)
 
388
 
 
389
    def get_OS_KSADM_roles_1(self, **kw):
 
390
        body = {"role":
 
391
               {"name": "new-role",
 
392
                "id": "1"}
 
393
                }
 
394
        return (200, body)
 
395
 
 
396
    def delete_OS_KSADM_roles_1(self, **kw):
 
397
        body = {}
 
398
        return (200, body)
 
399
 
 
400
    def post_OS_KSADM_services(self, **kw):
 
401
        body = {"OS-KSADM:service":
 
402
               {"id": "1",
 
403
                "type": "compute",
 
404
                "name": "service1",
 
405
                "description": None}
 
406
                }
 
407
        return (200, body)
 
408
 
 
409
    def get_OS_KSADM_services_1(self, **kw):
 
410
        body = {"OS-KSADM:service":
 
411
               {"description": None,
 
412
                "type": "compute",
 
413
                "id": "1",
 
414
                "name": "service1"}
 
415
                }
 
416
        return (200, body)
 
417
 
 
418
    def get_OS_KSADM_services(self, **kw):
 
419
        body = {
 
420
            "OS-KSADM:services": [
 
421
            {"description": None,
 
422
             "type": "compute",
 
423
             "id": "1",
 
424
             "name": "service1"},
 
425
            {"description": None,
 
426
             "type": "identity",
 
427
             "id": "2",
 
428
             "name": "service2"}]
 
429
        }
 
430
        return (200, body)
 
431
 
 
432
    def delete_OS_KSADM_services_1(self, **kw):
 
433
        body = {}
 
434
        return (200, body)
 
435
 
 
436
    def post_users_1_credentials_OS_EC2(self, **kw):
 
437
        body = {"credential":
 
438
               {"access": "1",
 
439
                "tenant_id": "1",
 
440
                "secret": "1",
 
441
                "user_id": "1"}
 
442
                }
 
443
        return (200, body)
 
444
 
 
445
    def get_users_1_credentials_OS_EC2(self, **kw):
 
446
        body = {"credentials": [
 
447
            {"access": "1",
 
448
             "tenant_id": "1",
 
449
             "secret": "1",
 
450
             "user_id": "1"}]
 
451
        }
 
452
        return (200, body)
 
453
 
 
454
    def get_users_1_credentials_OS_EC2_2(self, **kw):
 
455
        body = {
 
456
            "credential":
 
457
               {"access": "2",
 
458
                "tenant_id": "1",
 
459
                "secret": "1",
 
460
                "user_id": "1"}
 
461
        }
 
462
        return (200, body)
 
463
 
 
464
    def delete_users_1_credentials_OS_EC2_2(self, **kw):
 
465
        body = {}
 
466
        return (200, body)
 
467
 
 
468
    def patch_OS_KSCRUD_users_1(self, **kw):
 
469
        body = {}
 
470
        return (200, body)
 
471
 
 
472
    def get_endpoints(self, **kw):
 
473
        body = {
 
474
            'endpoints': [
 
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'}],
 
479
            'type': 'compute',
 
480
            'name': 'nova-compute'
 
481
        }
 
482
        return (200, body)
 
483
 
 
484
    def post_endpoints(self, **kw):
 
485
        body = {
 
486
            "endpoint":
 
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"},
 
491
            "type": "compute",
 
492
            "name": "nova-compute"
 
493
        }
 
494
        return (200, body)