1 # ============LICENSE_START====================================================
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
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 Unit tests for convert.py
20 should return docker_uri, dataformat and spec
24 from testing_helpers import get_fixture_path
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)
34 "name": "example-model",
35 "description": "Automatically generated from Acumos model",
36 "component_type": "docker",
38 "services": {"calls": [], "provides": []},
41 {"config_key": "add_subscriber", "format": "NumbersIn", "version": "1.0.0", "type": "message_router"}
44 {"config_key": "add_publisher", "format": "NumberOut", "version": "1.0.0", "type": "message_router"}
48 "auxilary": {"healthcheck": {"type": "http", "endpoint": "/healthcheck"}},
49 "artifacts": [{"type": "docker image", "uri": "nexus01.fake.com:18443/example-model:latest"}],
53 "self": {"name": "NumbersIn", "version": "1.0.0"},
54 "dataformatversion": "1.0.1",
59 "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
60 "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
62 "$schema": "http://json-schema.org/draft-04/schema#",
67 "self": {"name": "NumberOut", "version": "1.0.0"},
68 "dataformatversion": "1.0.1",
72 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
73 "$schema": "http://json-schema.org/draft-04/schema#",
78 dockeruri = 'dockerregistry/example-model:latest'
80 def mockreturn_dockeruri(config, model_name, model_version='latest'):
83 def mockreturn_dataformats(model_repo_path, model_name):
86 def mockreturn_spec(model_repo_path, model_name, dataformat, dockeruri):
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)