be897224ecb4ed5d04c082f81fde7d152bf1debc
[dcaegen2/platform.git] / mod / onboardingapi / dcae_cli / commands / tests / test_profiles_cmd.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
3 # ================================================================================
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18 #
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
20
21 # -*- coding: utf-8 -*-
22 '''
23 Tests profiles CLI commands
24 '''
25 import json
26
27 import pytest
28 import click
29 from click.testing import CliRunner
30
31 from dcae_cli import util
32 from dcae_cli.cli import cli
33 from dcae_cli.util import profiles
34 from dcae_cli.util import config
35
36
37 def test_basic(monkeypatch, tmpdir, mock_db_url):
38
39     runner = CliRunner()
40
41     # Setup config
42     test_db_url = mock_db_url
43     config_dict = { "user": "ninny", "active_profile": "fake-solutioning",
44             "db_url": test_db_url, "cli_version": "2.0.0" }
45     config_file = tmpdir.join("config.json")
46     config_file.write(json.dumps(config_dict))
47
48     # Setup profile
49     profile_dict = { "fake-solutioning": { "cdap_broker": "cdap_broker",
50         "config_binding_service": "config_binding_service",
51         "consul_host": "realsolcnsl00.dcae.solutioning.com",
52         "docker_host": "realsoldokr00.dcae.solutioning.com:2376" }}
53     profile_file = tmpdir.join("profiles.json")
54     profile_file.write(json.dumps(profile_dict))
55
56     monkeypatch.setattr(click, "get_app_dir", lambda app: str(tmpdir.realpath()))
57
58     cmd = 'profiles show fake-solutioning'.split()
59     result = runner.invoke(cli, cmd)
60     assert result.output == "{}\n".format(json.dumps(profile_dict["fake-solutioning"],
61         sort_keys=True, indent=4))
62
63     cmd = 'profiles list'.split()
64     result = runner.invoke(cli, cmd)
65     assert result.output == '*  fake-solutioning\n'
66
67     cmd = 'profiles create foo'.split()
68     result = runner.invoke(cli, cmd)
69
70     cmd = 'profiles list'.split()
71     result = runner.invoke(cli, cmd)
72     assert result.output == '*  fake-solutioning\n   foo\n'
73
74     cmd = 'profiles activate foo'.split()
75     result = runner.invoke(cli, cmd)
76
77     cmd = 'profiles list'.split()
78     result = runner.invoke(cli, cmd)
79     assert result.output == '   fake-solutioning\n*  foo\n'
80
81
82 if __name__ == '__main__':
83     '''Test area'''
84     pytest.main([__file__, ])