Added MTU network config and updated flavor_metadata test support
[snaps.git] / snaps / config / tests / user_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.user import UserConfig
18
19
20 class UserConfigUnitTests(unittest.TestCase):
21     """
22     Tests the construction of the UserConfig class
23     """
24
25     def test_no_params(self):
26         with self.assertRaises(Exception):
27             UserConfig()
28
29     def test_empty_config(self):
30         with self.assertRaises(Exception):
31             UserConfig(**dict())
32
33     def test_name_only(self):
34         with self.assertRaises(Exception):
35             UserConfig(name='foo')
36
37     def test_config_with_name_only(self):
38         with self.assertRaises(Exception):
39             UserConfig(**{'name': 'foo'})
40
41     def test_name_pass_enabled_str(self):
42         with self.assertRaises(Exception):
43             UserConfig(name='foo', password='bar', enabled='true')
44
45     def test_config_with_name_pass_enabled_str(self):
46         with self.assertRaises(Exception):
47             UserConfig(
48                 **{'name': 'foo', 'password': 'bar', 'enabled': 'true'})
49
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)
57
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)
65
66     def test_all(self):
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)
75
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)