Enable Adapter to work behind proxy
[dcaegen2/platform.git] / adapter / acumos / tests / test_convert.py
1 # ============LICENSE_START====================================================
2 # org.onap.dcae
3 # =============================================================================
4 # Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
5 # =============================================================================
6 # Copyright (c) 2021 highstreet technologies GmbH. All rights reserved.
7 # =============================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #      http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END======================================================
20 '''
21 Unit tests for convert.py
22 should return docker_uri, dataformat and spec
23 '''
24
25 import aoconversion
26 from testing_helpers import get_fixture_path
27
28
29 def test_gen_dcae_artifacts_for_model(monkeypatch):
30     model_repo_path = get_fixture_path('models')
31     model_name = 'example-model'
32     config = aoconversion.scanner.Config(dcaeurl='http://dcaeurl', dcaeuser='dcaeuser', onboardingurl='https://onboarding', onboardinguser='obuser', onboardingpass='obpass', acumosurl='https://acumos', certfile=None, dockerregistry='dockerregistry', dockeruser='registryuser', dockerpass='registrypassword', http_proxy='', https_proxy='', no_proxy='', tmpdir=model_repo_path)
33     spec = {
34         "self": {
35             "version": "1.0.0",
36             "name": "example-model",
37             "description": "Automatically generated from Acumos model",
38             "component_type": "docker",
39         },
40         "services": {"calls": [], "provides": []},
41         "streams": {
42             "subscribes": [
43                 {"config_key": "add_subscriber", "format": "NumbersIn", "version": "1.0.0", "type": "message_router"}
44             ],
45             "publishes": [
46                 {"config_key": "add_publisher", "format": "NumberOut", "version": "1.0.0", "type": "message_router"}
47             ],
48         },
49         "parameters": [],
50         "auxilary": {"healthcheck": {"type": "http", "endpoint": "/healthcheck"}},
51         "artifacts": [{"type": "docker image", "uri": "nexus01.fake.com:18443/example-model:latest"}],
52     }
53     dataformat = [
54         {
55             "self": {"name": "NumbersIn", "version": "1.0.0"},
56             "dataformatversion": "1.0.1",
57             "jsonschema": {
58                 "title": "NumbersIn",
59                 "type": "object",
60                 "properties": {
61                     "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
62                     "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
63                 },
64                 "$schema": "http://json-schema.org/draft-04/schema#",
65                 "definitions": {},
66             },
67         },
68         {
69             "self": {"name": "NumberOut", "version": "1.0.0"},
70             "dataformatversion": "1.0.1",
71             "jsonschema": {
72                 "title": "NumberOut",
73                 "type": "object",
74                 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
75                 "$schema": "http://json-schema.org/draft-04/schema#",
76                 "definitions": {},
77             },
78         },
79     ]
80     dockeruri = 'dockerregistry/example-model:latest'
81
82     def mockreturn_dockeruri(config, model_name, model_version='latest'):
83         return dockeruri
84
85     def mockreturn_dataformats(model_repo_path, model_name):
86         return dataformat
87
88     def mockreturn_spec(model_repo_path, model_name, dataformat, dockeruri):
89         return spec
90
91     monkeypatch.setattr(aoconversion.docker_gen, 'build_and_push_docker', mockreturn_dockeruri)
92     monkeypatch.setattr(aoconversion.dataformat_gen, 'generate_dcae_data_formats', mockreturn_dataformats)
93     monkeypatch.setattr(aoconversion.spec_gen, 'generate_spec', mockreturn_spec)
94     assert aoconversion.convert.gen_dcae_artifacts_for_model(config, model_name, 'latest') == (dockeruri, dataformat, spec)