0470d83bf0c2e1c844f044b48abe7de6ba86ce15
[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
41     def test_config_with_name_only(self):
42         settings = ProjectConfig(**{'name': 'foo'})
43         self.assertEqual('foo', settings.name)
44         self.assertEqual('Default', settings.domain_name)
45         self.assertIsNone(settings.description)
46         self.assertTrue(settings.enabled)
47         self.assertEqual(list(), settings.users)
48
49     def test_all(self):
50         users = ['test1', 'test2']
51         settings = ProjectConfig(
52             name='foo', domain='bar', description='foobar', enabled=False,
53             users=users)
54         self.assertEqual('foo', settings.name)
55         self.assertEqual('bar', settings.domain_name)
56         self.assertEqual('foobar', settings.description)
57         self.assertFalse(settings.enabled)
58         self.assertEqual(users, settings.users)
59
60     def test_config_all(self):
61         users = ['test1', 'test2']
62         settings = ProjectConfig(
63             **{'name': 'foo', 'domain': 'bar', 'description': 'foobar',
64                'enabled': False, 'users': users})
65         self.assertEqual('foo', settings.name)
66         self.assertEqual('bar', settings.domain_name)
67         self.assertEqual('foobar', settings.description)
68         self.assertFalse(settings.enabled)
69         self.assertEqual(users, settings.users)