File: test_providers.py

package info (click to toggle)
python-karborclient 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 776 kB
  • sloc: python: 8,201; makefile: 21; sh: 10
file content (144 lines) | stat: -rw-r--r-- 4,990 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy

from karborclient.osc.v1 import providers as osc_providers
from karborclient.tests.unit.osc.v1 import fakes
from karborclient.v1 import providers


PROVIDER_INFO = {
    "id": "2220f8b1-975d-4621-a872-fa9afb43cb6c",
    "name": "OS Infra Provider",
    "description": "provider description",
    "extended_info_schema": {
        "options_schema": {
            "OS::Cinder::Volume": {
                "required": [
                    "backup_mode"
                ],
                "type": "object",
                "properties": {
                    "backup_mode": {
                        "default": "auto",
                        "enum": [
                            "full",
                            "incremental",
                            "auto"
                        ],
                        "type": "string",
                        "description": "The backup mode.",
                        "title": "Backup Mode"
                    }
                },
                "title": "Cinder Protection Options"
            }
        },
        "saved_info_schema": {
            "OS::Cinder::Volume": {
                "required": [
                    "name"
                ],
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "description": "The name for this backup.",
                        "title": "Name"
                    }
                },
                "title": "Cinder Protection Saved Info"
            }
        },
        "restore_schema": {
            "OS::Cinder::Volume": {
                "type": "object",
                "properties": {
                    "restore_name": {
                        "type": "string",
                        "description": "The name of the restored volume.",
                        "title": "Restore Name"
                    }
                },
                "title": "Cinder Protection Restore"
            }
        }
    }
}


class TestProviders(fakes.TestDataProtection):
    def setUp(self):
        super(TestProviders, self).setUp()
        self.providers_mock = self.app.client_manager.data_protection.providers
        self.providers_mock.reset_mock()


class TestListProviders(TestProviders):
    def setUp(self):
        super(TestListProviders, self).setUp()
        self.providers_mock.list.return_value = [providers.Provider(
            None, copy.deepcopy(PROVIDER_INFO))]

        # Command to test
        self.cmd = osc_providers.ListProviders(self.app, None)

    def test_providers_list(self):
        arglist = ['--name', 'OS Infra Provider']
        verifylist = [('name', 'OS Infra Provider')]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)

        # Check that columns are correct
        expected_columns = (
            ['Id', 'Name', 'Description'])
        self.assertEqual(expected_columns, columns)

        # Check that data is correct
        expected_data = [("2220f8b1-975d-4621-a872-fa9afb43cb6c",
                          "OS Infra Provider",
                          "provider description")]
        self.assertEqual(expected_data, list(data))


class TestShowProvider(TestProviders):
    def setUp(self):
        super(TestShowProvider, self).setUp()
        self._provider_info = copy.deepcopy(PROVIDER_INFO)
        self.providers_mock.get.return_value = providers.Provider(
            None, self._provider_info)

        # Command to test
        self.cmd = osc_providers.ShowProvider(self.app, None)

    def test_provider_show(self):
        arglist = ['2220f8b1-975d-4621-a872-fa9afb43cb6c']
        verifylist = [('provider', '2220f8b1-975d-4621-a872-fa9afb43cb6c')]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)

        # Check that columns are correct
        expected_columns = (
            'description', 'extended_info_schema', 'id', 'name')
        self.assertEqual(expected_columns, columns)

        # Check that data is correct
        self.assertEqual(self._provider_info['description'], data[0])
        self.assertEqual(self._provider_info['extended_info_schema'], data[1])
        self.assertEqual(self._provider_info['id'], data[2])
        self.assertEqual(self._provider_info['name'], data[3])