Add cloudtaf framework
[ta/cloudtaf.git] / libraries / openstackcli / conftest.py
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # pylint: disable=redefined-outer-name
16 from collections import namedtuple
17
18 import pytest
19 from .openstackcli import (
20     OpenStack,
21     Runner)
22
23
24 from .cloudcli import (
25     DefaultCloud,
26     TargetCloud,
27     TypoCloud)
28
29 from .envcli import (
30     EnvCli,
31     InitializedEnvCli)
32
33
34 CLIWRAPPER_CLSES = [DefaultCloud,
35                     TargetCloud,
36                     TypoCloud,
37                     EnvCli,
38                     InitializedEnvCli]
39
40
41 CLI_CLSES = [OpenStack, Runner]
42
43
44 class WrapperCliTuple(namedtuple('WrapperCliTuple', ['wrapper', 'cli'])):
45     pass
46
47
48 @pytest.fixture(params=[WrapperCliTuple(wrapper=cliw, cli=clicls)
49                         for clicls in CLI_CLSES
50                         for cliw in CLIWRAPPER_CLSES])
51 def cliwrapper(mock_remotesession, request):
52     c = request.param.wrapper(request.param.cli)
53     c.set_remotesession(mock_remotesession)
54     c.initialize()
55     return c
56
57
58 class MethodFmt(namedtuple('MethodFormat', ['method', 'fmt'])):
59     pass
60
61
62 @pytest.fixture(params=['run', 'run_ignore_output'])
63 def methodfmt(request, openstack):
64     return {
65         'run': MethodFmt(openstack.run, ' -f json'),
66         'run_ignore_output': MethodFmt(openstack.run_ignore_output, '')}[
67             request.param]