summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_security_groups.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_security_groups.py')
-rw-r--r--novaclient/tests/unit/v2/test_security_groups.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_security_groups.py b/novaclient/tests/unit/v2/test_security_groups.py
new file mode 100644
index 0000000..9aeb8dd
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_security_groups.py
@@ -0,0 +1,76 @@
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 novaclient.tests.unit.fixture_data import client
15from novaclient.tests.unit.fixture_data import security_groups as data
16from novaclient.tests.unit import utils
17from novaclient.v2 import security_groups
18
19
20class SecurityGroupsTest(utils.FixturedTestCase):
21
22 client_fixture_class = client.V1
23 data_fixture_class = data.Fixture
24
25 def _do_test_list_security_groups(self, search_opts, path):
26 sgs = self.cs.security_groups.list(search_opts=search_opts)
27 self.assert_called('GET', path)
28 for sg in sgs:
29 self.assertIsInstance(sg, security_groups.SecurityGroup)
30
31 def test_list_security_groups_all_tenants_on(self):
32 self._do_test_list_security_groups(
33 None, '/os-security-groups')
34
35 def test_list_security_groups_all_tenants_on(self):
36 self._do_test_list_security_groups(
37 {'all_tenants': 1}, '/os-security-groups?all_tenants=1')
38
39 def test_list_security_groups_all_tenants_off(self):
40 self._do_test_list_security_groups(
41 {'all_tenants': 0}, '/os-security-groups')
42
43 def test_get_security_groups(self):
44 sg = self.cs.security_groups.get(1)
45 self.assert_called('GET', '/os-security-groups/1')
46 self.assertIsInstance(sg, security_groups.SecurityGroup)
47 self.assertEqual('1', str(sg))
48
49 def test_delete_security_group(self):
50 sg = self.cs.security_groups.list()[0]
51 sg.delete()
52 self.assert_called('DELETE', '/os-security-groups/1')
53 self.cs.security_groups.delete(1)
54 self.assert_called('DELETE', '/os-security-groups/1')
55 self.cs.security_groups.delete(sg)
56 self.assert_called('DELETE', '/os-security-groups/1')
57
58 def test_create_security_group(self):
59 sg = self.cs.security_groups.create("foo", "foo barr")
60 self.assert_called('POST', '/os-security-groups')
61 self.assertIsInstance(sg, security_groups.SecurityGroup)
62
63 def test_update_security_group(self):
64 sg = self.cs.security_groups.list()[0]
65 secgroup = self.cs.security_groups.update(sg, "update", "update")
66 self.assert_called('PUT', '/os-security-groups/1')
67 self.assertIsInstance(secgroup, security_groups.SecurityGroup)
68
69 def test_refresh_security_group(self):
70 sg = self.cs.security_groups.get(1)
71 sg2 = self.cs.security_groups.get(1)
72 self.assertEqual(sg.name, sg2.name)
73 sg2.name = "should be test"
74 self.assertNotEqual(sg.name, sg2.name)
75 sg2.get()
76 self.assertEqual(sg.name, sg2.name)