aboutsummaryrefslogtreecommitdiffstats
path: root/profiles/robot/src/main/resources/script/discover-robot-testcases.py
diff options
context:
space:
mode:
Diffstat (limited to 'profiles/robot/src/main/resources/script/discover-robot-testcases.py')
-rw-r--r--profiles/robot/src/main/resources/script/discover-robot-testcases.py131
1 files changed, 112 insertions, 19 deletions
diff --git a/profiles/robot/src/main/resources/script/discover-robot-testcases.py b/profiles/robot/src/main/resources/script/discover-robot-testcases.py
index fbb8d8be..a7f03552 100644
--- a/profiles/robot/src/main/resources/script/discover-robot-testcases.py
+++ b/profiles/robot/src/main/resources/script/discover-robot-testcases.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# Copyright 2020 Simran Singhal.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# Copyright 2020 Huawei Technologies Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import os
import argparse
from argparse import RawTextHelpFormatter
@@ -33,7 +44,6 @@ class OcompException(Exception):
class OCOMP:
def run(self, command, params={}):
- CMD_NAME = 'oclip'
CMD = [CMD_NAME]
CMD.append(command)
@@ -65,7 +75,7 @@ class LineBreakDumper(Dumper):
if len(self.indents) == 1:
super().write_line_break()
-def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_folder_path):
+def create_testcase_yaml(testcase_name, description, path_test_suite, testsuite_name, test_suite_folder_path, api_tests_folder_path):
def change_style(style, representer):
def new_representer(dumper, data):
@@ -83,24 +93,72 @@ def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_
open_cli_schema_version = 1.0
name = re.sub(re.compile('(?:\-){2,}'), '-', testcase_name.replace(' ', '-').lower())
- description = LiteralString(description.replace(r'\n', '\n') + '\n')
-
- product = "etsi-mano"
- service = test_suite_folder_path.split('/')[0]
- info = OrderedDict(product = product, service = service)
-
- test_suite_path = '${api-tests-folder-path}/api-tests/' + test_suite_folder_path + '/' + testsuite_name + '.robot'
- command = ['python3 $s{env:OPEN_CLI_HOME}/script/run-robot-testcase.py --variables-file-path ${variables-file-path} --test-suite ' +
- test_suite_path + ' --testcase ' + testcase_name]
+ if(not description):
+ description = name
+ else:
+ description = LiteralString(description.replace(r'\n', '\n') + '\n')
+
+ product = os.getenv('OPEN_CLI_PRODUCT')
+ if not product:
+ product = "etsi-mano"
+ robotName = testsuite_name.replace(' ', '_')
+ service = test_suite_folder_path.split('/')[0] + '_' + robotName
+
+ if not test_suite_folder_path.split('/')[0]:
+ service = service[1:]
+ author = os.getenv('AUTHOR')
+ if not author:
+ author = 'edgeT team'
+ info = OrderedDict(product = product, service = service, author = author)
+
+ if(data_list_file_path and data_list_file_path1):
+ param_name = "envFilePath"
+ description = "env File Path"
+ type = "string"
+ short_option = "x"
+ long_option = "envFilePath"
+ is_optional = 'false'
+ parameters = [OrderedDict(name = param_name, description = description, type = type, short_option = short_option, long_option = long_option, is_optional = is_optional)]
+
+ rdirection = 'landscape'
+ rname = 'reports_path'
+ rdescription = 'reports path'
+ rscope = 'short'
+ rtype = 'string'
+ attributes = [OrderedDict(name=rname, description=rdescription, scope=rscope, type=rtype)]
+ results = OrderedDict(direction=rdirection, attributes=attributes)
+
+ if path_test_suite.split('.')[-1] != "robot":
+ tcappend = ""
+ else:
+ tcappend = " --testcase " + testcase_name
+ if (data_list_file_path and data_list_file_path1):
+ openCliHome= os.getenv('OPEN_CLI_HOME')
+ command = ['python3 '+openCliHome+'/script/run-robot-testcase.py --test-suite ' +
+ path_test_suite + tcappend + ' --env-file-path ${envFilePath}']
+ else:
+ test_suite_path = '${api-tests-folder-path}/api-tests/' + test_suite_folder_path + '/' + testsuite_name + '.robot'
+ command = ['python3 $s{env:OPEN_CLI_HOME}/script/run-robot-testcase.py --variables-file-path ${variables-file-path} --test-suite ' +
+ test_suite_path + tcappend]
success_codes = [0]
working_directory = '.'
output = '$stdout'
- robot = OrderedDict(command=command, success_codes=success_codes, working_directory=working_directory, output=output)
+ if(data_list_file_path and data_list_file_path1):
+ reports_path = '$s{env:OPEN_CLI_REQUEST_ID}/logs/'
+ result_map = OrderedDict(reports_path=reports_path)
+ robot = OrderedDict(command=command, success_codes=success_codes, working_directory=working_directory, output=output, result_map=result_map)
+ else:
+ robot = OrderedDict(command=command, success_codes=success_codes, working_directory=working_directory,
+ output=output)
- data = OrderedDict(open_cli_schema_version=open_cli_schema_version, name=name, description=description,
- info=info, robot=robot)
+ if(data_list_file_path and data_list_file_path1):
+ data = OrderedDict(open_cli_schema_version=open_cli_schema_version, name=name, description=description, info=info, cmd=robot, parameters=parameters, results=results)
+ yaml_path = openCliHome + '/open-cli-schema/robot' + test_suite_folder_path + testsuite_name
+ else:
+ data = OrderedDict(open_cli_schema_version=open_cli_schema_version, name=name, description=description, info=info,
+ robot=robot)
- yaml_path = os.getenv('OPEN_CLI_HOME') + '/open-cli-schema/robot/' + test_suite_folder_path + '/' + testsuite_name
+ yaml_path = os.getenv('OPEN_CLI_HOME') + '/open-cli-schema/robot/' + test_suite_folder_path + '/' + testsuite_name
os.makedirs(yaml_path, exist_ok=True)
with open(yaml_path + '/' + name + '.yaml', 'w') as file:
@@ -118,7 +176,14 @@ def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_
print()
def discover_testcases(api_tests_folder_path):
-
+ product = os.getenv('OPEN_CLI_PRODUCT')
+ if data_list_file_path and data_list_file_path1:
+ with open(os.getenv('OPEN_CLI_HOME') + "/conf/vtp.properties", 'w') as file:
+ file.write("cmd." + product + ".envpath=" + data_list_file_path + "\n")
+ with open(os.getenv('OPEN_CLI_HOME') + "/conf/vtp.properties", 'a') as file:
+ file.write("cmd." + product + ".envpath1=" + data_list_file_path1 + "\n")
+
+ #create yaml at file level
for root, dirs, files in os.walk(api_tests_folder_path):
for file in files:
@@ -129,10 +194,20 @@ def discover_testcases(api_tests_folder_path):
suite = TestData(parent=None, source=path_to_test_suite)
for testcase in suite.testcase_table:
test_suite_folder_path = root[len(api_tests_folder_path):]
- create_testcase_yaml(testcase.name, testcase.doc.value, suite.name, test_suite_folder_path)
+ create_testcase_yaml(testcase.name, testcase.doc.value, path_to_test_suite, suite.name, test_suite_folder_path, api_tests_folder_path)
except Exception as e:
pass
+ #create yaml at folder level
+ for root, dirs, files in os.walk(api_tests_folder_path):
+ test_suite_folder_path = api_tests_folder_path
+ for dir in dirs:
+ try:
+ create_testcase_yaml(dir, "run " + test_suite_folder_path + "/" + dir + " suite", os.path.join(root, dir),
+ dir, api_tests_folder_path.split('/')[-1], api_tests_folder_path)
+ except Exception as e:
+ pass
+ break
ocomp = OCOMP()
res = ocomp.run(command='schema-refresh')
@@ -141,6 +216,7 @@ def discover_testcases(api_tests_folder_path):
raise OcompException(9999, result)
def main():
+ global CMD_NAME
text = 'This command helps to discover all robot testcases\n' \
'These python modules are need to be installed for running the tests\n' \
'robotframework==3.1\n' \
@@ -153,9 +229,19 @@ def main():
parser = argparse.ArgumentParser(description=text, formatter_class=RawTextHelpFormatter)
parser.add_argument('--api-tests-folder-path', action='store', dest='api_tests_folder_path',
help='Location to api-tests folder', required=True)
+ parser.add_argument('--data_list_file_path', action='store', dest='data_list_file_path',
+ help='Location to data list file path')
+ parser.add_argument('--data_list_file_path1', action='store', dest='data_list_file_path1',
+ help='Location to data list1 file path')
args = parser.parse_args()
- api_tests_folder_path = args.api_tests_folder_path + '/api-tests/'
+ api_tests_folder_path = args.api_tests_folder_path
+ global data_list_file_path,data_list_file_path1
+ data_list_file_path = args.data_list_file_path
+ data_list_file_path1 = args.data_list_file_path1
+
+ if not (data_list_file_path and data_list_file_path1):
+ api_tests_folder_path = args.api_tests_folder_path + '/api-tests/'
if os.path.exists(api_tests_folder_path):
@@ -165,6 +251,13 @@ def main():
else:
raise Exception('Given api-tests folder location does not exist\n')
+ try:
+ subprocess.check_call('ocomp -v', shell=True)
+ CMD_NAME = 'ocomp'
+ except subprocess.CalledProcessError:
+ subprocess.check_call('oclip -v', shell=True)
+ CMD_NAME = 'oclip'
+
discover_testcases(api_tests_folder_path)
if __name__ == '__main__':