Debian Codegraph @

heatclient/tests/unit/test_openstack_common.py

raw symbols SCIP
1 # Copyright 2015 Huawei.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # 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, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import testtools
17
18 from heatclient.common import base
19 from heatclient.v1 import events
20 from heatclient.v1 import stacks
21
22
23 class BaseTest(testtools.TestCase):
24
25 def test_two_resources_with_same_id_are_not_equal(self):
26 # Two resources with same ID: never equal if their info is not equal
27 r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
28 r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
29 self.assertNotEqual(r1, r2)
30
31 def test_two_resources_with_same_id_and_info_are_equal(self):
32 # Two resources with same ID: equal if their info is equal
33 r1 = base.Resource(None, {'id': 1, 'name': 'hello'})
34 r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
35 self.assertEqual(r1, r2)
36
37 def test_two_resources_with_diff_type_are_not_equal(self):
38 # Two resoruces of different types: never equal
39 r1 = base.Resource(None, {'id': 1})
40 r2 = events.Event(None, {'id': 1})
41 self.assertNotEqual(r1, r2)
42
43 def test_two_resources_with_no_id_are_equal(self):
44 # Two resources with no ID: equal if their info is equal
45 r1 = base.Resource(None, {'name': 'joe', 'age': 12})
46 r2 = base.Resource(None, {'name': 'joe', 'age': 12})
47 self.assertEqual(r1, r2)
48
49 def test_is_same_object(self):
50 # Two resources with same type and same ID: is same object
51 r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
52 r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
53 self.assertTrue(r1.is_same_obj(r2))
54 self.assertTrue(r2.is_same_obj(r1))
55
56 def test_is_diff_object_with_diff_id(self):
57 # Two resources with same type and different ID: is different object
58 r1 = base.Resource(None, {'id': 1, 'name': 'hello'})
59 r2 = base.Resource(None, {'id': 2, 'name': 'hello'})
60 self.assertFalse(r1.is_same_obj(r2))
61 self.assertFalse(r2.is_same_obj(r1))
62
63 def test_is_diff_object_with_diff_type(self):
64 # Two resources with different types: is different object
65 r1 = events.Event(None, {'id': 1})
66 r2 = stacks.Stack(None, {'id': 1})
67 self.assertFalse(r1.is_same_obj(r2))
68 self.assertFalse(r2.is_same_obj(r1))
69
70 def test_is_diff_object_with_no_id(self):
71 # Two resources with no ID: is different object
72 r1 = base.Resource(None, {'name': 'joe', 'age': 12})
73 r2 = base.Resource(None, {'name': 'joe', 'age': 12})
74 self.assertFalse(r1.is_same_obj(r2))
75 self.assertFalse(r2.is_same_obj(r1))