Refactoring of VolumeTypeSettings to extend VolumeTypeConfig
[snaps.git] / snaps / config / tests / volume_type_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.volume_type import (
18     VolumeTypeConfig,  VolumeTypeEncryptionConfig, ControlLocation,
19     VolumeTypeConfigError)
20
21
22 class VolumeTypeConfigUnitTests(unittest.TestCase):
23     """
24     Tests the construction of the VolumeTypeConfig class
25     """
26
27     def test_no_params(self):
28         with self.assertRaises(VolumeTypeConfigError):
29             VolumeTypeConfig()
30
31     def test_empty_config(self):
32         with self.assertRaises(VolumeTypeConfigError):
33             VolumeTypeConfig(**dict())
34
35     def test_name_only(self):
36         settings = VolumeTypeConfig(name='foo')
37         self.assertEqual('foo', settings.name)
38         self.assertIsNone(settings.description)
39         self.assertIsNone(settings.qos_spec_name)
40         self.assertIsNone(settings.encryption)
41         self.assertFalse(settings.public)
42
43     def test_config_with_name_only(self):
44         settings = VolumeTypeConfig(**{'name': 'foo'})
45         self.assertEqual('foo', settings.name)
46         self.assertIsNone(settings.description)
47         self.assertIsNone(settings.qos_spec_name)
48         self.assertIsNone(settings.encryption)
49         self.assertFalse(settings.public)
50
51     def test_all(self):
52         encryption_settings = VolumeTypeEncryptionConfig(
53             name='foo', provider_class='bar',
54             control_location=ControlLocation.back_end)
55         settings = VolumeTypeConfig(
56             name='foo', description='desc', encryption=encryption_settings,
57             qos_spec_name='spec_name', public=True)
58         self.assertEqual('foo', settings.name)
59         self.assertEqual('desc', settings.description)
60         self.assertEqual('spec_name', settings.qos_spec_name)
61         self.assertEqual(encryption_settings, settings.encryption)
62         self.assertTrue(True, settings.public)
63
64     def test_all_string(self):
65         encryption_settings = {
66             'name': 'foo', 'provider_class': 'bar',
67             'control_location': 'back-end'}
68         settings = VolumeTypeConfig(
69             name='foo', description='desc', encryption=encryption_settings,
70             qos_spec_name='spec_name', public='true')
71         self.assertEqual('foo', settings.name)
72         self.assertEqual('desc', settings.description)
73         self.assertEqual('spec_name', settings.qos_spec_name)
74         self.assertEqual(VolumeTypeEncryptionConfig(**encryption_settings),
75                          settings.encryption)
76         self.assertTrue(settings.public)
77
78     def test_config_all(self):
79         encryption_settings = {
80             'name': 'foo', 'provider_class': 'bar',
81             'control_location': 'back-end'}
82         settings = VolumeTypeConfig(
83             **{'name': 'foo', 'description': 'desc',
84                'encryption': encryption_settings,
85                'qos_spec_name': 'spec_name', 'public': 'false'})
86         self.assertEqual('foo', settings.name)
87         self.assertEqual('desc', settings.description)
88         self.assertEqual('spec_name', settings.qos_spec_name)
89         self.assertEqual(VolumeTypeEncryptionConfig(**encryption_settings),
90                          settings.encryption)
91         self.assertFalse(settings.public)