diff options
Diffstat (limited to 'snaps/domain/test/network_tests.py')
-rw-r--r-- | snaps/domain/test/network_tests.py | 97 |
1 files changed, 89 insertions, 8 deletions
diff --git a/snaps/domain/test/network_tests.py b/snaps/domain/test/network_tests.py index 24a60c9..3003326 100644 --- a/snaps/domain/test/network_tests.py +++ b/snaps/domain/test/network_tests.py @@ -25,39 +25,48 @@ class NetworkObjectTests(unittest.TestCase): """ def test_construction_kwargs_1(self): + subnet = Subnet( + **{'name': 'foo', 'id': 'bar', 'network_id': 'foo-bar'}) network = Network( **{'name': 'foo', 'id': 'bar', 'provider:network_type': 'flat', 'admin_state_up': False, 'shared': True, - 'router:external': False}) + 'router:external': False, 'subnets': [subnet]}) self.assertEqual('foo', network.name) self.assertEqual('bar', network.id) self.assertEqual('flat', network.type) self.assertFalse(network.admin_state_up) self.assertFalse(network.external) self.assertTrue(network.shared) + self.assertEqual([subnet], network.subnets) def test_construction_kwargs_2(self): + subnet = Subnet( + **{'name': 'foo', 'id': 'bar', 'network_id': 'foo-bar'}) network = Network( **{'name': 'foo', 'id': 'bar', 'type': 'flat', - 'admin_state_up': False, 'shared': True, - 'external': False}) + 'admin_state_up': False, 'shared': True, 'external': False, + 'subnets': [subnet]}) self.assertEqual('foo', network.name) self.assertEqual('bar', network.id) self.assertEqual('flat', network.type) self.assertFalse(network.admin_state_up) self.assertFalse(network.external) self.assertTrue(network.shared) + self.assertEqual([subnet], network.subnets) def test_construction_named(self): + subnet = Subnet( + **{'name': 'foo', 'id': 'bar', 'network_id': 'foo-bar'}) network = Network( name='foo', id='bar', type='flat', admin_state_up=False, - shared=True, external=False) + shared=True, external=False, subnets=[subnet]) self.assertEqual('foo', network.name) self.assertEqual('bar', network.id) self.assertEqual('flat', network.type) self.assertFalse(network.admin_state_up) self.assertFalse(network.external) self.assertTrue(network.shared) + self.assertEqual([subnet], network.subnets) class SubnetObjectTests(unittest.TestCase): @@ -213,7 +222,8 @@ class RouterDomainObjectTests(unittest.TestCase): self.assertEqual('hello', router.status) self.assertEqual('1234', router.tenant_id) self.assertEqual('yes', router.admin_state_up) - self.assertEqual('no', router.external_gateway_info) + self.assertIsNone(router.external_fixed_ips) + self.assertIsNone(router.external_network_id) def test_construction_named(self): router = Router( @@ -224,7 +234,35 @@ class RouterDomainObjectTests(unittest.TestCase): self.assertEqual('hello', router.status) self.assertEqual('1234', router.tenant_id) self.assertEqual('yes', router.admin_state_up) - self.assertEqual('no', router.external_gateway_info) + self.assertIsNone(router.external_fixed_ips) + self.assertIsNone(router.external_network_id) + + def test_ext_gateway_named(self): + router = Router( + external_fixed_ips=['456', '789'], external_network_id='123', + admin_state_up='yes', tenant_id='1234', status='hello', id='id', + name='name') + self.assertEqual('name', router.name) + self.assertEqual('id', router.id) + self.assertEqual('hello', router.status) + self.assertEqual('1234', router.tenant_id) + self.assertEqual('yes', router.admin_state_up) + self.assertEqual(['456', '789'], router.external_fixed_ips) + self.assertEqual('123', router.external_network_id) + + def test_ext_net_ips_named(self): + ext_gateway = {'network_id': '123', + 'external_fixed_ips': ['456', '789']} + router = Router( + external_gateway_info=ext_gateway, admin_state_up='yes', + tenant_id='1234', status='hello', id='id', name='name') + self.assertEqual('name', router.name) + self.assertEqual('id', router.id) + self.assertEqual('hello', router.status) + self.assertEqual('1234', router.tenant_id) + self.assertEqual('yes', router.admin_state_up) + self.assertEqual(['456', '789'], router.external_fixed_ips) + self.assertEqual('123', router.external_network_id) class InterfaceRouterDomainObjectTests(unittest.TestCase): @@ -254,12 +292,33 @@ class SecurityGroupDomainObjectTests(unittest.TestCase): def test_construction_proj_id_kwargs(self): sec_grp = SecurityGroup( **{'name': 'name', 'id': 'id', 'project_id': 'foo', - 'description': 'test desc'}) + 'description': 'test desc', + 'rules': [ + {'id': 'id', 'security_group_id': 'grp_id', + 'description': 'desc', 'direction': 'dir', + 'ethertype': 'eType', 'port_range_min': '10.0.0.100', + 'port_range_max': '10.0.0.200', 'protocol': 'proto', + 'remote_group_id': 'group_id', + 'remote_ip_prefix': 'ip_prefix'} + ]}) self.assertEqual('name', sec_grp.name) self.assertEqual('id', sec_grp.id) self.assertEqual('test desc', sec_grp.description) self.assertEqual('foo', sec_grp.project_id) + self.assertEqual(1, len(sec_grp.rules)) + rule = sec_grp.rules[0] + self.assertEqual('id', rule.id) + self.assertEqual('grp_id', rule.security_group_id) + self.assertEqual('desc', rule.description) + self.assertEqual('dir', rule.direction) + self.assertEqual('eType', rule.ethertype) + self.assertEqual('10.0.0.100', rule.port_range_min) + self.assertEqual('10.0.0.200', rule.port_range_max) + self.assertEqual('proto', rule.protocol) + self.assertEqual('group_id', rule.remote_group_id) + self.assertEqual('ip_prefix', rule.remote_ip_prefix) + def test_construction_tenant_id_kwargs(self): sec_grp = SecurityGroup( **{'name': 'name', 'id': 'id', @@ -268,15 +327,37 @@ class SecurityGroupDomainObjectTests(unittest.TestCase): self.assertEqual('id', sec_grp.id) self.assertEqual('foo', sec_grp.project_id) self.assertIsNone(sec_grp.description) + self.assertEqual(0, len(sec_grp.rules)) def test_construction_named(self): + rules = [SecurityGroupRule( + **{'id': 'id', 'security_group_id': 'grp_id', + 'description': 'desc', 'direction': 'dir', + 'ethertype': 'eType', 'port_range_min': '10.0.0.100', + 'port_range_max': '10.0.0.200', 'protocol': 'proto', + 'remote_group_id': 'group_id', + 'remote_ip_prefix': 'ip_prefix'} + )] sec_grp = SecurityGroup(description='test desc', tenant_id='foo', - id='id', name='name') + id='id', name='name', rules=rules) self.assertEqual('name', sec_grp.name) self.assertEqual('id', sec_grp.id) self.assertEqual('test desc', sec_grp.description) self.assertEqual('foo', sec_grp.project_id) + self.assertEqual(1, len(sec_grp.rules)) + rule = sec_grp.rules[0] + self.assertEqual('id', rule.id) + self.assertEqual('grp_id', rule.security_group_id) + self.assertEqual('desc', rule.description) + self.assertEqual('dir', rule.direction) + self.assertEqual('eType', rule.ethertype) + self.assertEqual('10.0.0.100', rule.port_range_min) + self.assertEqual('10.0.0.200', rule.port_range_max) + self.assertEqual('proto', rule.protocol) + self.assertEqual('group_id', rule.remote_group_id) + self.assertEqual('ip_prefix', rule.remote_ip_prefix) + class SecurityGroupRuleDomainObjectTests(unittest.TestCase): """ |