summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_flavor_access.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_flavor_access.py')
-rw-r--r--novaclient/tests/unit/v2/test_flavor_access.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_flavor_access.py b/novaclient/tests/unit/v2/test_flavor_access.py
new file mode 100644
index 0000000..109f177
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_flavor_access.py
@@ -0,0 +1,70 @@
1# Copyright 2012 OpenStack Foundation
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
16from novaclient.tests.unit import utils
17from novaclient.tests.unit.v2 import fakes
18from novaclient.v2 import flavor_access
19
20
21cs = fakes.FakeClient()
22
23
24class FlavorAccessTest(utils.TestCase):
25
26 def test_list_access_by_flavor_private(self):
27 kwargs = {'flavor': cs.flavors.get(2)}
28 r = cs.flavor_access.list(**kwargs)
29 cs.assert_called('GET', '/flavors/2/os-flavor-access')
30 [self.assertIsInstance(a, flavor_access.FlavorAccess) for a in r]
31
32 def test_add_tenant_access(self):
33 flavor = cs.flavors.get(2)
34 tenant = 'proj2'
35 r = cs.flavor_access.add_tenant_access(flavor, tenant)
36
37 body = {
38 "addTenantAccess": {
39 "tenant": "proj2"
40 }
41 }
42
43 cs.assert_called('POST', '/flavors/2/action', body)
44 [self.assertIsInstance(a, flavor_access.FlavorAccess) for a in r]
45
46 def test_remove_tenant_access(self):
47 flavor = cs.flavors.get(2)
48 tenant = 'proj2'
49 r = cs.flavor_access.remove_tenant_access(flavor, tenant)
50
51 body = {
52 "removeTenantAccess": {
53 "tenant": "proj2"
54 }
55 }
56
57 cs.assert_called('POST', '/flavors/2/action', body)
58 [self.assertIsInstance(a, flavor_access.FlavorAccess) for a in r]
59
60 def test_repr_flavor_access(self):
61 flavor = cs.flavors.get(2)
62 tenant = 'proj3'
63 r = cs.flavor_access.add_tenant_access(flavor, tenant)
64
65 def get_expected(flavor_access):
66 return ("<FlavorAccess flavor id: %s, tenant id: %s>" %
67 (flavor_access.flavor_id, flavor_access.tenant_id))
68
69 for a in r:
70 self.assertEqual(get_expected(a), repr(a))