Added ability to set several quota settings upon project creation.
[snaps.git] / snaps / config / tests / 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 import unittest
16
17 from snaps.config.project import ProjectConfig, ProjectConfigError
18
19
20 class ProjectConfigUnitTests(unittest.TestCase):
21     """
22     Tests the construction of the ProjectConfig class
23     """
24
25     def test_no_params(self):
26         with self.assertRaises(ProjectConfigError):
27             ProjectConfig()
28
29     def test_empty_config(self):
30         with self.assertRaises(ProjectConfigError):
31             ProjectConfig(**dict())
32
33     def test_name_only(self):
34         settings = ProjectConfig(name='foo')
35         self.assertEqual('foo', settings.name)
36         self.assertEqual('Default', settings.domain_name)
37         self.assertIsNone(settings.description)
38         self.assertTrue(settings.enabled)
39         self.assertEqual(list(), settings.users)
40         self.assertIsNone(settings.quotas)
41
42     def test_config_with_name_only(self):
43         settings = ProjectConfig(**{'name': 'foo'})
44         self.assertEqual('foo', settings.name)
45         self.assertEqual('Default', settings.domain_name)
46         self.assertIsNone(settings.description)
47         self.assertTrue(settings.enabled)
48         self.assertEqual(list(), settings.users)
49         self.assertIsNone(settings.quotas)
50
51     def test_all(self):
52         users = ['test1', 'test2']
53         quotas = {
54             'cores': 4, 'instances': 5, 'injected_files': 6,
55             'injected_file_content_bytes': 60000, 'ram': 70000, 'fixed_ips': 7,
56             'key_pairs': 8}
57         settings = ProjectConfig(
58             name='foo', domain='bar', description='foobar', enabled=False,
59             users=users, quotas=quotas)
60         self.assertEqual('foo', settings.name)
61         self.assertEqual('bar', settings.domain_name)
62         self.assertEqual('foobar', settings.description)
63         self.assertFalse(settings.enabled)
64         self.assertEqual(users, settings.users)
65         self.assertIsNotNone(settings.quotas)
66         self.assertEquals(4, settings.quotas.get('cores'))
67         self.assertEquals(5, settings.quotas.get('instances'))
68         self.assertEquals(6, settings.quotas.get('injected_files'))
69         self.assertEquals(
70             60000, settings.quotas.get('injected_file_content_bytes'))
71         self.assertEquals(70000, settings.quotas.get('ram'))
72         self.assertEquals(7, settings.quotas.get('fixed_ips'))
73         self.assertEquals(8, settings.quotas.get('key_pairs'))
74
75     def test_config_all(self):
76         users = ['test1', 'test2']
77         settings = ProjectConfig(
78             **{'name': 'foo', 'domain': 'bar', 'description': 'foobar',
79                'enabled': False, 'users': users,
80                'quotas': {
81                    'cores': 4, 'instances': 5, 'injected_files': 6,
82                    'injected_file_content_bytes': 60000, 'ram': 70000,
83                    'fixed_ips': 7, 'key_pairs': 8}})
84         self.assertEqual('foo', settings.name)
85         self.assertEqual('bar', settings.domain_name)
86         self.assertEqual('foobar', settings.description)
87         self.assertFalse(settings.enabled)
88         self.assertEqual(users, settings.users)
89         self.assertIsNotNone(settings.quotas)
90         self.assertEquals(4, settings.quotas.get('cores'))
91         self.assertEquals(5, settings.quotas.get('instances'))
92         self.assertEquals(6, settings.quotas.get('injected_files'))
93         self.assertEquals(
94             60000, settings.quotas.get('injected_file_content_bytes'))
95         self.assertEquals(70000, settings.quotas.get('ram'))
96         self.assertEquals(7, settings.quotas.get('fixed_ips'))
97         self.assertEquals(8, settings.quotas.get('key_pairs'))