Created domain class for ports.
[snaps.git] / snaps / domain / test / network_tests.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain 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,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import unittest
17 from snaps.domain.network import Port, SecurityGroup, SecurityGroupRule
18
19
20 class PortDomainObjectTests(unittest.TestCase):
21     """
22     Tests the construction of the snaps.domain.network.Port class
23     """
24
25     def test_construction_kwargs(self):
26         ips = ['10', '11']
27         port = Port(
28             **{'name': 'name', 'id': 'id', 'ips': ips})
29         self.assertEqual('name', port.name)
30         self.assertEqual('id', port.id)
31         self.assertEqual(ips, port.ips)
32
33     def test_construction_named(self):
34         ips = ['10', '11']
35         port = Port(ips=ips, id='id', name='name')
36         self.assertEqual('name', port.name)
37         self.assertEqual('id', port.id)
38         self.assertEqual(ips, port.ips)
39
40
41 class SecurityGroupDomainObjectTests(unittest.TestCase):
42     """
43     Tests the construction of the snaps.domain.test.SecurityGroup class
44     """
45
46     def test_construction_proj_id_kwargs(self):
47         sec_grp = SecurityGroup(
48             **{'name': 'name', 'id': 'id',
49                'project_id': 'foo'})
50         self.assertEqual('name', sec_grp.name)
51         self.assertEqual('id', sec_grp.id)
52         self.assertEqual('foo', sec_grp.project_id)
53
54     def test_construction_tenant_id_kwargs(self):
55         sec_grp = SecurityGroup(
56             **{'name': 'name', 'id': 'id',
57                'tenant_id': 'foo'})
58         self.assertEqual('name', sec_grp.name)
59         self.assertEqual('id', sec_grp.id)
60         self.assertEqual('foo', sec_grp.project_id)
61
62     def test_construction_named(self):
63         sec_grp = SecurityGroup(tenant_id='foo', id='id', name='name')
64         self.assertEqual('name', sec_grp.name)
65         self.assertEqual('id', sec_grp.id)
66         self.assertEqual('foo', sec_grp.project_id)
67
68
69 class SecurityGroupRuleDomainObjectTests(unittest.TestCase):
70     """
71     Tests the construction of the snaps.domain.test.SecurityGroupRule class
72     """
73
74     def test_construction_kwargs(self):
75         sec_grp_rule = SecurityGroupRule(
76             **{'id': 'id', 'security_group_id': 'grp_id',
77                'description': 'desc', 'direction': 'dir', 'ethertype': 'eType',
78                'port_range_min': '10.0.0.100', 'port_range_max': '10.0.0.200',
79                'protocol': 'proto', 'remote_group_id': 'group_id',
80                'remote_ip_prefix': 'ip_prefix'})
81         self.assertEqual('id', sec_grp_rule.id)
82         self.assertEqual('grp_id', sec_grp_rule.security_group_id)
83         self.assertEqual('desc', sec_grp_rule.description)
84         self.assertEqual('dir', sec_grp_rule.direction)
85         self.assertEqual('eType', sec_grp_rule.ethertype)
86         self.assertEqual('10.0.0.100', sec_grp_rule.port_range_min)
87         self.assertEqual('10.0.0.200', sec_grp_rule.port_range_max)
88         self.assertEqual('proto', sec_grp_rule.protocol)
89         self.assertEqual('group_id', sec_grp_rule.remote_group_id)
90         self.assertEqual('ip_prefix', sec_grp_rule.remote_ip_prefix)
91
92     def test_construction_named(self):
93         sec_grp_rule = SecurityGroupRule(
94             remote_ip_prefix='ip_prefix', remote_group_id='group_id',
95             protocol='proto', port_range_min='10.0.0.100',
96             port_range_max='10.0.0.200', ethertype='eType',
97             direction='dir', description='desc', security_group_id='grp_id',
98             id='id')
99         self.assertEqual('id', sec_grp_rule.id)
100         self.assertEqual('grp_id', sec_grp_rule.security_group_id)
101         self.assertEqual('desc', sec_grp_rule.description)
102         self.assertEqual('dir', sec_grp_rule.direction)
103         self.assertEqual('eType', sec_grp_rule.ethertype)
104         self.assertEqual('10.0.0.100', sec_grp_rule.port_range_min)
105         self.assertEqual('10.0.0.200', sec_grp_rule.port_range_max)
106         self.assertEqual('proto', sec_grp_rule.protocol)
107         self.assertEqual('group_id', sec_grp_rule.remote_group_id)
108         self.assertEqual('ip_prefix', sec_grp_rule.remote_ip_prefix)