d0aec3a02c146d9846cae5ec21a1574fa3627203
[snaps.git] / snaps / domain / test / project_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.project import Project, Domain, ComputeQuotas, NetworkQuotas
18
19
20 class ProjectDomainObjectTests(unittest.TestCase):
21     """
22     Tests the construction of the snaps.domain.project.Project class
23     """
24
25     def test_construction_positional_minimal(self):
26         project = Project('foo', '123-456')
27         self.assertEqual('foo', project.name)
28         self.assertEqual('123-456', project.id)
29         self.assertIsNone(project.domain_id)
30
31     def test_construction_positional_all(self):
32         project = Project('foo', '123-456', 'hello')
33         self.assertEqual('foo', project.name)
34         self.assertEqual('123-456', project.id)
35         self.assertEqual('hello', project.domain_id)
36
37     def test_construction_named_minimal(self):
38         project = Project(project_id='123-456', name='foo')
39         self.assertEqual('foo', project.name)
40         self.assertEqual('123-456', project.id)
41         self.assertIsNone(project.domain_id)
42
43     def test_construction_named_all(self):
44         project = Project(domain_id='hello', project_id='123-456', name='foo')
45         self.assertEqual('foo', project.name)
46         self.assertEqual('123-456', project.id)
47         self.assertEqual('hello', project.domain_id)
48
49
50 class DomainDomainObjectTests(unittest.TestCase):
51     """
52     Tests the construction of the snaps.domain.project.Domain class
53     """
54
55     def test_construction_positional(self):
56         domain = Domain('foo', '123-456')
57         self.assertEqual('foo', domain.name)
58         self.assertEqual('123-456', domain.id)
59
60     def test_construction_named_minimal(self):
61         domain = Domain(domain_id='123-456', name='foo')
62         self.assertEqual('foo', domain.name)
63         self.assertEqual('123-456', domain.id)
64
65
66 class ComputeQuotasDomainObjectTests(unittest.TestCase):
67     """
68     Tests the construction of the snaps.domain.project.ComputeQuotas class
69     """
70
71     def test_construction_positional(self):
72         quotas = ComputeQuotas(
73             metadata_items=64, cores=5, instances= 4, injected_files= 3,
74             injected_file_content_bytes=5120,ram=25600, fixed_ips=100,
75             key_pairs=50)
76         self.assertEqual(64, quotas.metadata_items)
77         self.assertEqual(5, quotas.cores)
78         self.assertEqual(4, quotas.instances)
79         self.assertEqual(3, quotas.injected_files)
80         self.assertEqual(5120, quotas.injected_file_content_bytes)
81         self.assertEqual(25600, quotas.ram)
82         self.assertEqual(100, quotas.fixed_ips)
83         self.assertEqual(50, quotas.key_pairs)
84
85     def test_construction_named_minimal(self):
86         quotas = ComputeQuotas(
87             **{'metadata_items': 64, 'cores': 5, 'instances': 4,
88                'injected_files': 3, 'injected_file_content_bytes': 5120,
89                'ram': 25600, 'fixed_ips': 100, 'key_pairs': 50})
90         self.assertEqual(64, quotas.metadata_items)
91         self.assertEqual(5, quotas.cores)
92         self.assertEqual(4, quotas.instances)
93         self.assertEqual(3, quotas.injected_files)
94         self.assertEqual(5120, quotas.injected_file_content_bytes)
95         self.assertEqual(25600, quotas.ram)
96         self.assertEqual(100, quotas.fixed_ips)
97         self.assertEqual(50, quotas.key_pairs)
98
99
100 class NetworkQuotasDomainObjectTests(unittest.TestCase):
101     """
102     Tests the construction of the snaps.domain.project.NetworkQuotas class
103     """
104
105     def test_construction_positional(self):
106         quotas = NetworkQuotas(
107             security_group=5, security_group_rule=50,
108             floatingip=25, network=5, port=25, router=6, subnet=7)
109         self.assertEqual(5, quotas.security_group)
110         self.assertEqual(50, quotas.security_group_rule)
111         self.assertEqual(25, quotas.floatingip)
112         self.assertEqual(5, quotas.network)
113         self.assertEqual(25, quotas.port)
114         self.assertEqual(6, quotas.router)
115         self.assertEqual(7, quotas.subnet)
116
117     def test_construction_named_minimal(self):
118         quotas = NetworkQuotas(
119             **{'security_group': 5, 'security_group_rule': 50,
120                'floatingip': 25, 'network': 5, 'port': 25, 'router': 6,
121                'subnet': 7})
122         self.assertEqual(5, quotas.security_group)
123         self.assertEqual(50, quotas.security_group_rule)
124         self.assertEqual(25, quotas.floatingip)
125         self.assertEqual(5, quotas.network)
126         self.assertEqual(25, quotas.port)
127         self.assertEqual(6, quotas.router)
128         self.assertEqual(7, quotas.subnet)