780cc555454506846418ce6371f8d1ca837a90c4
[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 # 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 Unit tests for convert.py
20 should return docker_uri, dataformat and spec
21 '''
22
23 import aoconversion
24 from testing_helpers import get_fixture_path
25
26
27 def test_gen_dcae_artifacts_for_model(monkeypatch):
28     model_repo_path = get_fixture_path('models')
29     model_name = 'example-model'
30     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', tmpdir=model_repo_path)
31     spec = {
32         "self": {
33             "version": "1.0.0",
34             "name": "example-model",
35             "description": "Automatically generated from Acumos model",
36             "component_type": "docker",
37         },
38         "services": {"calls": [], "provides": []},
39         "streams": {
40             "subscribes": [
41                 {"config_key": "add_subscriber", "format": "NumbersIn", "version": "1.0.0", "type": "message_router"}
42             ],
43             "publishes": [
44                 {"config_key": "add_publisher", "format": "NumberOut", "version": "1.0.0", "type": "message_router"}
45             ],
46         },
47         "parameters": [],
48         "auxilary": {"healthcheck": {"type": "http", "endpoint": "/healthcheck"}},
49         "artifacts": [{"type": "docker image", "uri": "nexus01.fake.com:18443/example-model:latest"}],
50     }
51     dataformat = [
52         {
53             "self": {"name": "NumbersIn", "version": "1.0.0"},
54             "dataformatversion": "1.0.1",
55             "jsonschema": {
56                 "title": "NumbersIn",
57                 "type": "object",
58                 "properties": {
59                     "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
60                     "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
61                 },
62                 "$schema": "http://json-schema.org/draft-04/schema#",
63                 "definitions": {},
64             },
65         },
66         {
67             "self": {"name": "NumberOut", "version": "1.0.0"},
68             "dataformatversion": "1.0.1",
69             "jsonschema": {
70                 "title": "NumberOut",
71                 "type": "object",
72                 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
73                 "$schema": "http://json-schema.org/draft-04/schema#",
74                 "definitions": {},
75             },
76         },
77     ]
78     dockeruri = 'dockerregistry/example-model:latest'
79
80     def mockreturn_dockeruri(config, model_name, model_version='latest'):
81         return dockeruri
82
83     def mockreturn_dataformats(model_repo_path, model_name):
84         return dataformat
85
86     def mockreturn_spec(model_repo_path, model_name, dataformat, dockeruri):
87         return spec
88
89     monkeypatch.setattr(aoconversion.docker_gen, 'build_and_push_docker', mockreturn_dockeruri)
90     monkeypatch.setattr(aoconversion.dataformat_gen, 'generate_dcae_data_formats', mockreturn_dataformats)
91     monkeypatch.setattr(aoconversion.spec_gen, 'generate_spec', mockreturn_spec)
92     assert aoconversion.convert.gen_dcae_artifacts_for_model(config, model_name, 'latest') == (dockeruri, dataformat, spec)