summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_security_group_rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_security_group_rules.py')
-rw-r--r--novaclient/tests/unit/v2/test_security_group_rules.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_security_group_rules.py b/novaclient/tests/unit/v2/test_security_group_rules.py
new file mode 100644
index 0000000..8375198
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_security_group_rules.py
@@ -0,0 +1,89 @@
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 import exceptions
15from novaclient.tests.unit.fixture_data import client
16from novaclient.tests.unit.fixture_data import security_group_rules as data
17from novaclient.tests.unit import utils
18from novaclient.v2 import security_group_rules
19
20
21class SecurityGroupRulesTest(utils.FixturedTestCase):
22
23 client_fixture_class = client.V1
24 data_fixture_class = data.Fixture
25
26 def test_delete_security_group_rule(self):
27 self.cs.security_group_rules.delete(1)
28 self.assert_called('DELETE', '/os-security-group-rules/1')
29
30 def test_create_security_group_rule(self):
31 sg = self.cs.security_group_rules.create(1, "tcp", 1, 65535,
32 "10.0.0.0/16")
33
34 body = {
35 "security_group_rule": {
36 "ip_protocol": "tcp",
37 "from_port": 1,
38 "to_port": 65535,
39 "cidr": "10.0.0.0/16",
40 "group_id": None,
41 "parent_group_id": 1,
42 }
43 }
44
45 self.assert_called('POST', '/os-security-group-rules', body)
46 self.assertTrue(isinstance(sg, security_group_rules.SecurityGroupRule))
47
48 def test_create_security_group_group_rule(self):
49 sg = self.cs.security_group_rules.create(1, "tcp", 1, 65535,
50 "10.0.0.0/16", 101)
51
52 body = {
53 "security_group_rule": {
54 "ip_protocol": "tcp",
55 "from_port": 1,
56 "to_port": 65535,
57 "cidr": "10.0.0.0/16",
58 "group_id": 101,
59 "parent_group_id": 1,
60 }
61 }
62
63 self.assert_called('POST', '/os-security-group-rules', body)
64 self.assertTrue(isinstance(sg, security_group_rules.SecurityGroupRule))
65
66 def test_invalid_parameters_create(self):
67 self.assertRaises(exceptions.CommandError,
68 self.cs.security_group_rules.create,
69 1, "invalid_ip_protocol", 1, 65535,
70 "10.0.0.0/16", 101)
71 self.assertRaises(exceptions.CommandError,
72 self.cs.security_group_rules.create,
73 1, "tcp", "invalid_from_port", 65535,
74 "10.0.0.0/16", 101)
75 self.assertRaises(exceptions.CommandError,
76 self.cs.security_group_rules.create,
77 1, "tcp", 1, "invalid_to_port",
78 "10.0.0.0/16", 101)
79
80 def test_security_group_rule_str(self):
81 sg = self.cs.security_group_rules.create(1, "tcp", 1, 65535,
82 "10.0.0.0/16")
83 self.assertEqual('1', str(sg))
84
85 def test_security_group_rule_del(self):
86 sg = self.cs.security_group_rules.create(1, "tcp", 1, 65535,
87 "10.0.0.0/16")
88 sg.delete()
89 self.assert_called('DELETE', '/os-security-group-rules/1')