Debian Codegraph @

glanceclient/tests/unit/test_base.py

raw symbols SCIP
1 # Copyright 2013 OpenStack Foundation
2 # Copyright (C) 2013 Yahoo! Inc.
3 # All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16
17 import testtools
18
19 from glanceclient.v1.apiclient import base
20
21
22 class TestBase(testtools.TestCase):
23
24 def test_resource_repr(self):
25 r = base.Resource(None, dict(foo="bar", baz="spam"))
26 self.assertEqual("<Resource baz=spam, foo=bar>", repr(r))
27
28 def test_getid(self):
29 self.assertEqual(4, base.getid(4))
30
31 class TmpObject(object):
32 id = 4
33 self.assertEqual(4, base.getid(TmpObject))
34
35 def test_two_resources_with_same_id_are_not_equal(self):
36 # Two resources with same ID: never equal if their info is not equal
37 r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
38 r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
39 self.assertNotEqual(r1, r2)
40
41 def test_two_resources_with_same_id_and_info_are_equal(self):
42 # Two resources with same ID: equal if their info is equal
43 r1 = base.Resource(None, {'id': 1, 'name': 'hello'})
44 r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
45 self.assertEqual(r1, r2)
46
47 def test_two_resources_with_eq_info_are_equal(self):
48 # Two resources with no ID: equal if their info is equal
49 r1 = base.Resource(None, {'name': 'joe', 'age': 12})
50 r2 = base.Resource(None, {'name': 'joe', 'age': 12})
51 self.assertEqual(r1, r2)
52
53 def test_two_resources_with_diff_id_are_not_equal(self):
54 # Two resources with diff ID: not equal
55 r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
56 r2 = base.Resource(None, {'id': 2, 'name': 'hello'})
57 self.assertNotEqual(r1, r2)
58
59 def test_two_resources_with_not_eq_info_are_not_equal(self):
60 # Two resources with no ID: not equal if their info is not equal
61 r1 = base.Resource(None, {'name': 'bill', 'age': 21})
62 r2 = base.Resource(None, {'name': 'joe', 'age': 12})
63 self.assertNotEqual(r1, r2)