1 # ============LICENSE_START====================================================
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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======================================================
21 Unit tests for convert.py
22 should return docker_uri, dataformat and spec
26 from testing_helpers import get_fixture_path
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)
36 "name": "example-model",
37 "description": "Automatically generated from Acumos model",
38 "component_type": "docker",
40 "services": {"calls": [], "provides": []},
43 {"config_key": "add_subscriber", "format": "NumbersIn", "version": "1.0.0", "type": "message_router"}
46 {"config_key": "add_publisher", "format": "NumberOut", "version": "1.0.0", "type": "message_router"}
50 "auxilary": {"healthcheck": {"type": "http", "endpoint": "/healthcheck"}},
51 "artifacts": [{"type": "docker image", "uri": "nexus01.fake.com:18443/example-model:latest"}],
55 "self": {"name": "NumbersIn", "version": "1.0.0"},
56 "dataformatversion": "1.0.1",
61 "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
62 "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
64 "$schema": "http://json-schema.org/draft-04/schema#",
69 "self": {"name": "NumberOut", "version": "1.0.0"},
70 "dataformatversion": "1.0.1",
74 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
75 "$schema": "http://json-schema.org/draft-04/schema#",
80 dockeruri = 'dockerregistry/example-model:latest'
82 def mockreturn_dockeruri(config, model_name, model_version='latest'):
85 def mockreturn_dataformats(model_repo_path, model_name):
88 def mockreturn_spec(model_repo_path, model_name, dataformat, dockeruri):
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)