summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/utils.py')
-rw-r--r--novaclient/tests/unit/v2/utils.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/utils.py b/novaclient/tests/unit/v2/utils.py
new file mode 100644
index 0000000..d28392f
--- /dev/null
+++ b/novaclient/tests/unit/v2/utils.py
@@ -0,0 +1,42 @@
1#
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
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
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
12# under the License.
13
14from nose.tools import ok_
15
16
17def fail(msg):
18 raise AssertionError(msg)
19
20
21def assert_in(thing, seq, msg=None):
22 msg = msg or "'%s' not found in %s" % (thing, seq)
23 ok_(thing in seq, msg)
24
25
26def assert_not_in(thing, seq, msg=None):
27 msg = msg or "unexpected '%s' found in %s" % (thing, seq)
28 ok_(thing not in seq, msg)
29
30
31def assert_has_keys(dict, required=[], optional=[]):
32 keys = dict.keys()
33 for k in required:
34 assert_in(k, keys, "required key %s missing from %s" % (k, dict))
35 allowed_keys = set(required) | set(optional)
36 extra_keys = set(keys).difference(allowed_keys)
37 if extra_keys:
38 fail("found unexpected keys: %s" % list(extra_keys))
39
40
41def assert_isinstance(thing, kls):
42 ok_(isinstance(thing, kls), "%s is not an instance of %s" % (thing, kls))