From ea72aa01e864b6ddf3145d51d060077da00526d3 Mon Sep 17 00:00:00 2001 From: "pawel.denst" Date: Wed, 10 May 2023 10:50:58 +0000 Subject: ONAP Python SDK tests should generate JSON artifact (next to HTML) Generation of report file in JSON format Issue-ID: INT-2235 Signed-off-by: pawel.denst Signed-off-by: Lukasz Rajewski Change-Id: Ib99a0cb8bf317633e19a4a2e1c41d611a3b9f343 --- src/onaptests/configuration/settings.py | 4 +++- src/onaptests/steps/reports_collection.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/onaptests') diff --git a/src/onaptests/configuration/settings.py b/src/onaptests/configuration/settings.py index 74bc840..436e82c 100644 --- a/src/onaptests/configuration/settings.py +++ b/src/onaptests/configuration/settings.py @@ -40,7 +40,9 @@ LOG_CONFIG = { CLEANUP_FLAG = False SDC_CLEANUP = False -REPORTING_FILE_PATH = "/tmp/reporting.html" +REPORTING_FILE_DIRECTORY = "/tmp/" +HTML_REPORTING_FILE_NAME = "reporting.html" +JSON_REPORTING_FILE_NAME = "reporting.json" K8S_REGION_TYPE = "k8s" TILLER_HOST = "localhost" K8S_CONFIG = None # None means it will use default config (~/.kube/config) diff --git a/src/onaptests/steps/reports_collection.py b/src/onaptests/steps/reports_collection.py index 4b7f79b..0e5076f 100644 --- a/src/onaptests/steps/reports_collection.py +++ b/src/onaptests/steps/reports_collection.py @@ -1,5 +1,7 @@ from dataclasses import dataclass from enum import Enum +import json +from pathlib import Path from typing import List from jinja2 import Environment, FileSystemLoader, select_autoescape from onapsdk.configuration import settings @@ -83,4 +85,20 @@ class ReportsCollection: details=details, components=components, log_path="./pythonsdk.debug.log").dump( - settings.REPORTING_FILE_PATH) + str(Path(settings.REPORTING_FILE_DIRECTORY).joinpath(settings.HTML_REPORTING_FILE_NAME))) + + report_dict = { + 'usecase': usecase, + 'details': details, + 'components': components, + 'steps': [ + { + 'description': step_report.step_description, + 'status': step_report.step_execution_status.value, + 'duration': step_report.step_execution_duration + } + for step_report in reversed(self.report) + ] + } + with (Path(settings.REPORTING_FILE_DIRECTORY).joinpath(settings.JSON_REPORTING_FILE_NAME)).open('w') as file: + json.dump(report_dict, file, indent=4) \ No newline at end of file -- cgit 1.2.3-korg