2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3
# not use this file except in compliance with the License. You may obtain
4
# a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
# License for the specific language governing permissions and limitations
15
A fake server that "responds" to API methods with pre-canned responses.
17
All of these responses come from the spec, so if for some reason the spec's
18
wrong the tests might raise AssertionError. I've indicated in comments the
19
places where actual behavior differs from the spec.
22
from seamicroclient import base
25
def assert_has_keys(dict, required=[], optional=[]):
30
except AssertionError:
31
extra_keys = set(keys).difference(set(required + optional))
32
raise AssertionError("found unexpected keys: %s" %
36
class FakeClient(object):
38
def assert_called(self, method, url, body=None, pos=-1):
40
Assert than an API method was just called.
42
expected = (method, url)
43
called = self.client.callstack[pos][0:2]
45
assert self.client.callstack, \
46
"Expected %s %s but no calls were made." % expected
48
assert expected == called, 'Expected %s %s; got %s %s' % \
52
if self.client.callstack[pos][2] != body:
53
raise AssertionError('%r != %r' %
54
(self.client.callstack[pos][2], body))
56
def assert_called_anytime(self, method, url, body=None):
58
Assert than an API method was called anytime in the test.
60
expected = (method, url)
62
assert self.client.callstack, \
63
"Expected %s %s but no calls were made." % expected
66
for entry in self.client.callstack:
67
if expected == entry[0:2]:
71
assert found, 'Expected %s; got %s' % \
72
(expected, self.client.callstack)
75
assert entry[2] == body
76
except AssertionError:
82
self.client.callstack = []
84
def clear_callstack(self):
85
self.client.callstack = []
87
def authenticate(self):
91
# Fake class that will be used as an extension
92
class FakeManager(base.Manager):