aai should not check status code
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / PreloadDataKeywords.py
1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from robot import utils
16 from robot.api.deco import keyword
17 import os.path
18 import json
19
20
21 class PreloadDataKeywords(object):
22     """PreloadData is used for loading data for services into the robot framework in a structured decentralized way
23     that lets vnfs be added without code change to testuite"""
24
25     def __init__(self):
26         super(PreloadDataKeywords, self).__init__()
27         self._cache = utils.ConnectionCache('No Preload Data directories loaded')
28
29     @keyword
30     def set_directory(self, alias, preload_data_directory):
31         self._cache.register(preload_data_directory, alias=alias)
32
33     @keyword
34     def get_preload_data(self, alias, service, template):
35         """returns a dictionary with all of the preload data for the passed in service and template"""
36         return self._preload_data(alias, service)[template]
37
38     @keyword
39     def get_default_preload_data(self, alias):
40         """returns a dictionary with all of the default values"""
41         return self._preload_data(alias, "defaults")
42
43     def _preload_data(self, alias, service):
44         filepath = os.path.join(self._cache.switch(alias), service, 'preload_data.json')
45         with open(filepath, 'r') as f:
46             return json.load(f)