Copy dcae-cli->onboardingapi, copy component specs
[dcaegen2/platform.git] / mod / onboardingapi / dcae_cli / conftest.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
3 # ================================================================================
4 # Copyright (c) 2018 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 This module is actually for pytesting. This contains fixtures.
22 """
23
24 import pytest
25 import dcae_cli
26
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.
30
31 @pytest.fixture
32 def mock_cli_config(monkeypatch):
33     """Fixture to provide a mock dcae-cli configuration and profiles
34
35     This fixture monkeypatches the respective get calls to return mock objects
36     """
37     # NOTE: The component spec and data format in gerrit moved once already.
38     # Might move again..
39     fake_config = { "active_profile": "default", "user": "bob",
40             "server_url": "https://git.onap.org/dcaegen2/platform/cli/plain",
41             "db_url": "postgresql://postgres:abc123@localhost:5432/dcae_onboarding_db",
42             "path_component_spec": "/component-json-schemas/component-specification/dcae-cli-v2/component-spec-schema.json",
43             "path_data_format": "/component-json-schemas/data-format/dcae-cli-v1/data-format-schema.json"
44             }
45
46     fake_profiles = { "default": { "consul_host": "consul",
47         "cdap_broker": "cdap_broker",
48         "config_binding_service": "config_binding_service",
49         "docker_host": "docker_host" }
50         }
51     fake_profiles["active"] = fake_profiles["default"]
52
53     def fake_get_config():
54         return fake_config
55
56     def fake_get_profiles(user_only=False, include_active=True):
57         return fake_profiles
58
59     from dcae_cli.util import config, profiles
60     monkeypatch.setattr(dcae_cli.util.config, "get_config", fake_get_config)
61     monkeypatch.setattr(dcae_cli.util.profiles, "get_profiles", fake_get_profiles)
62
63
64 @pytest.fixture
65 def mock_db_url(tmpdir):
66     """Fixture to provide mock db url
67
68     This url is intended to be the location of where to place the local sqlite
69     databases for each unit test"""
70     dbname="dcae_cli.test.db"
71     config_dir = tmpdir.mkdir("config")
72     return "/".join(["sqlite://", str(config_dir), dbname])