1 # ============LICENSE_START=======================================================
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 # -*- coding: utf-8 -*-
23 Tests profiles CLI commands
29 from click.testing import CliRunner
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
37 def test_basic(monkeypatch, tmpdir):
42 test_db_url = "sqlite:///{0}/dcae_cli.db".format(util.get_app_dir())
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))
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))
56 monkeypatch.setattr(click, "get_app_dir", lambda app: str(tmpdir.realpath()))
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))
63 cmd = 'profiles list'.split()
64 result = runner.invoke(cli, cmd)
65 assert result.output == '* fake-solutioning\n'
67 cmd = 'profiles create foo'.split()
68 result = runner.invoke(cli, cmd)
70 cmd = 'profiles list'.split()
71 result = runner.invoke(cli, cmd)
72 assert result.output == '* fake-solutioning\n foo\n'
74 cmd = 'profiles activate foo'.split()
75 result = runner.invoke(cli, cmd)
77 cmd = 'profiles list'.split()
78 result = runner.invoke(cli, cmd)
79 assert result.output == ' fake-solutioning\n* foo\n'
82 if __name__ == '__main__':
84 pytest.main([__file__, ])