1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2018-2020 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 This module is actually for pytesting. This contains fixtures.
27 # REVIEW: Having issues trying to share this amongst all the tests. Putting this
28 # fixture here allows it to be shared when running tests over the entire project.
29 # The pytest recommendation was to place this file high up in the project.
32 def mock_schemas(monkeypatch):
35 schemadir = cwd[:cwd.find('/onboardingapi')] + '/component-json-schemas'
36 monkeypatch.setattr(dcae_cli.catalog.mock.schema.component_schema, 'path', schemadir + '/component-specification/dcae-cli-v2/component-spec-schema.json')
37 monkeypatch.setattr(dcae_cli.catalog.mock.schema.dataformat_schema, 'path', schemadir + '/data-format/dcae-cli-v1/data-format-schema.json')
40 def mock_cli_config(mock_schemas, monkeypatch):
41 """Fixture to provide a mock dcae-cli configuration and profiles
43 This fixture monkeypatches the respective get calls to return mock objects
45 # NOTE: The component spec and data format in gerrit moved once already.
47 fake_config = { "active_profile": "default",
48 "server_url": "https://git.onap.org/dcaegen2/platform/cli/plain",
49 "db_url": "postgresql://postgres:abc123@localhost:5432/dcae_onboarding_db",
50 "path_component_spec": "/component-json-schemas/component-specification/dcae-cli-v2/component-spec-schema.json",
51 "path_data_format": "/component-json-schemas/data-format/dcae-cli-v1/data-format-schema.json"
54 fake_profiles = { "default": { "consul_host": "consul",
55 "cdap_broker": "cdap_broker",
56 "config_binding_service": "config_binding_service",
57 "docker_host": "docker_host" }
59 fake_profiles["active"] = fake_profiles["default"]
61 def fake_get_config():
64 def fake_get_profiles(user_only=False, include_active=True):
67 from dcae_cli.util import config, profiles
68 monkeypatch.setattr(dcae_cli.util.config, "get_config", fake_get_config)
69 monkeypatch.setattr(dcae_cli.util.profiles, "get_profiles", fake_get_profiles)
73 def mock_db_url(tmpdir):
74 """Fixture to provide mock db url
76 This url is intended to be the location of where to place the local sqlite
77 databases for each unit test"""
78 dbname="dcae_cli.test.db"
79 config_dir = tmpdir.mkdir("config")
80 return "/".join(["sqlite://", str(config_dir), dbname])