1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 from snaps.config.project import ProjectConfig, ProjectConfigError
20 class ProjectConfigUnitTests(unittest.TestCase):
22 Tests the construction of the ProjectConfig class
25 def test_no_params(self):
26 with self.assertRaises(ProjectConfigError):
29 def test_empty_config(self):
30 with self.assertRaises(ProjectConfigError):
31 ProjectConfig(**dict())
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)
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)
52 users = ['test1', 'test2']
54 'cores': 4, 'instances': 5, 'injected_files': 6,
55 'injected_file_content_bytes': 60000, 'ram': 70000, 'fixed_ips': 7,
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'))
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'))
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,
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'))
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'))