1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
16
A fake server that "responds" to API methods with pre-canned responses.
18
All of these responses come from the spec, so if for some reason the spec's
19
wrong the tests might raise AssertionError. I've indicated in comments the
20
places where actual behavior differs from the spec.
23
from keystoneclient import access
26
def assert_has_keys(dict, required=[], optional=[]):
31
except AssertionError:
32
extra_keys = set(keys).difference(set(required + optional))
33
raise AssertionError("found unexpected keys: %s" %
37
class FakeClient(object):
39
def assert_called(self, method, url, body=None, pos=-1):
40
"""Assert than an API method was just called."""
41
expected = (method, url)
42
called = self.callstack[pos][0:2]
44
assert self.callstack, ("Expected %s %s but no calls were made." %
46
assert expected == called, ("Expected %s %s; got %s %s" %
50
assert self.callstack[pos][2] == body
52
def assert_called_anytime(self, method, url, body=None):
53
"""Assert than an API method was called anytime in the test."""
54
expected = (method, url)
56
assert self.callstack, ("Expected %s %s but no calls were made." %
60
for entry in self.callstack:
61
if expected == entry[0:2]:
65
assert found, ('Expected %s; got %s' %
66
(expected, self.callstack))
69
raise AssertionError('%s != %s' % (entry[2], body))
72
def clear_callstack(self):
75
def authenticate(self, cl_obj):
77
cl_obj.auth_user_id = '1'
78
cl_obj.project_id = '1'
79
cl_obj.auth_tenant_id = '1'
80
cl_obj.auth_ref = access.AccessInfo.factory(None, {
83
"expires": "2012-02-05T00:00:00",
84
"id": "887665443383838",
92
"adminURL": "http://swift.admin-nets.local:8080/",
93
"region": "RegionOne",
94
"internalURL": "http://127.0.0.1:8080/v1/AUTH_1",
96
"http://swift.publicinternets.com/v1/AUTH_1"
98
"type": "object-store",
102
"adminURL": "http://cdn.admin-nets.local/v1.1/1",
103
"region": "RegionOne",
104
"internalURL": "http://127.0.0.1:7777/v1.1/1",
105
"publicURL": "http://cdn.publicinternets.com/v1.1/1"
107
"type": "object-store",