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.user import UserConfig
20 class UserConfigUnitTests(unittest.TestCase):
22 Tests the construction of the UserConfig class
25 def test_no_params(self):
26 with self.assertRaises(Exception):
29 def test_empty_config(self):
30 with self.assertRaises(Exception):
33 def test_name_only(self):
34 with self.assertRaises(Exception):
35 UserConfig(name='foo')
37 def test_config_with_name_only(self):
38 with self.assertRaises(Exception):
39 UserConfig(**{'name': 'foo'})
41 def test_name_pass_enabled_str(self):
42 with self.assertRaises(Exception):
43 UserConfig(name='foo', password='bar', enabled='true')
45 def test_config_with_name_pass_enabled_str(self):
46 with self.assertRaises(Exception):
48 **{'name': 'foo', 'password': 'bar', 'enabled': 'true'})
50 def test_name_pass_only(self):
51 settings = UserConfig(name='foo', password='bar')
52 self.assertEqual('foo', settings.name)
53 self.assertEqual('bar', settings.password)
54 self.assertIsNone(settings.project_name)
55 self.assertIsNone(settings.email)
56 self.assertTrue(settings.enabled)
58 def test_config_with_name_pass_only(self):
59 settings = UserConfig(**{'name': 'foo', 'password': 'bar'})
60 self.assertEqual('foo', settings.name)
61 self.assertEqual('bar', settings.password)
62 self.assertIsNone(settings.project_name)
63 self.assertIsNone(settings.email)
64 self.assertTrue(settings.enabled)
67 settings = UserConfig(
68 name='foo', password='bar', project_name='proj-foo',
69 email='foo@bar.com', enabled=False)
70 self.assertEqual('foo', settings.name)
71 self.assertEqual('bar', settings.password)
72 self.assertEqual('proj-foo', settings.project_name)
73 self.assertEqual('foo@bar.com', settings.email)
74 self.assertFalse(settings.enabled)
76 def test_config_all(self):
77 settings = UserConfig(
78 **{'name': 'foo', 'password': 'bar', 'project_name': 'proj-foo',
79 'email': 'foo@bar.com', 'enabled': False})
80 self.assertEqual('foo', settings.name)
81 self.assertEqual('bar', settings.password)
82 self.assertEqual('proj-foo', settings.project_name)
83 self.assertEqual('foo@bar.com', settings.email)
84 self.assertFalse(settings.enabled)