3872f35ca7cf6022d63cdb8768ff7d395a032fc4
[dcaegen2/platform.git] / adapter / acumos / tests / test_df.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 from testing_helpers import get_json_fixture, get_fixture_path
20 from aoconversion import dataformat_gen, utils
21
22 TEST_META = get_json_fixture("models/example-model/metadata.json")
23
24
25 def test_get_needed_formats():
26     assert dataformat_gen._get_needed_formats(TEST_META) == ["NumbersIn", "NumberOut"]
27
28
29 def test_generate_dcae_data_formats(mock_schemas):
30     """
31     Test generating data formats from the protobuf
32     """
33     test_proto_path = get_fixture_path("models/example-model/model.proto")
34     assert dataformat_gen._generate_dcae_data_formats(test_proto_path, TEST_META, utils.dataformat_schema.get(), utils.schema_schema.get()) == [
35         {
36             "self": {"name": "NumbersIn", "version": "1.0.0"},
37             "dataformatversion": "1.0.1",
38             "jsonschema": {
39                 "title": "NumbersIn",
40                 "type": "object",
41                 "properties": {
42                     "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
43                     "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
44                 },
45                 "$schema": "http://json-schema.org/draft-04/schema#",
46                 "definitions": {},
47             },
48         },
49         {
50             "self": {"name": "NumberOut", "version": "1.0.0"},
51             "dataformatversion": "1.0.1",
52             "jsonschema": {
53                 "title": "NumberOut",
54                 "type": "object",
55                 "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}},
56                 "$schema": "http://json-schema.org/draft-04/schema#",
57                 "definitions": {},
58             },
59         },
60     ]
61
62
63 def test_generate_dcae_data_formats_listofm(mock_schemas):
64     """
65     Test generating data formats from the protobuf
66     This one tests the case where definitions needs to be populated in one of the data formats because it's referenced in a "top level" message
67     """
68     test_meta = get_json_fixture("models/example-model-listofm/metadata.json")
69     test_proto_path = get_fixture_path("models/example-model-listofm/model.proto")
70     assert dataformat_gen._generate_dcae_data_formats(test_proto_path, test_meta, utils.dataformat_schema.get(), utils.schema_schema.get()) == [
71         {
72             "self": {"name": "ArgsList", "version": "1.0.0"},
73             "dataformatversion": "1.0.1",
74             "jsonschema": {
75                 "title": "ArgsList",
76                 "type": "object",
77                 "properties": {"args": {"type": "array", "items": {"$ref": "#/definitions/Args"}}},
78                 "$schema": "http://json-schema.org/draft-04/schema#",
79                 "definitions": {
80                     "Args": {
81                         "title": "Args",
82                         "type": "object",
83                         "properties": {
84                             "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
85                             "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
86                         },
87                     }
88                 },
89             },
90         },
91         {
92             "self": {"name": "SumOut", "version": "1.0.0"},
93             "dataformatversion": "1.0.1",
94             "jsonschema": {
95                 "title": "SumOut",
96                 "type": "object",
97                 "properties": {
98                     "value": {
99                         "type": "array",
100                         "items": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
101                     }
102                 },
103                 "$schema": "http://json-schema.org/draft-04/schema#",
104                 "definitions": {},
105             },
106         },
107     ]