Add component name to the JSON report format 75/134775/1
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Tue, 6 Jun 2023 12:20:00 +0000 (12:20 +0000)
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Tue, 6 Jun 2023 12:32:30 +0000 (12:32 +0000)
Issue-ID: INT-2235
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I81274e0cca45ef86490e8004c594d7e85bf3c539

src/onaptests/steps/base.py
src/onaptests/steps/reports_collection.py
tests/test_generate_json.py

index 0715545..8ebe247 100644 (file)
@@ -193,7 +193,8 @@ class BaseStep(ABC):
                     self._cleanup_report = Report(
                         step_description=f"[{self.component}] {self.name} cleanup: {self.description}",
                         step_execution_status=execution_status,
-                        step_execution_duration=time.time() - self._start_cleanup_time
+                        step_execution_duration=time.time() - self._start_cleanup_time,
+                        step_component=self.component
                     )
                 else:
                     self._logger.info("*****************************************************")
@@ -207,7 +208,8 @@ class BaseStep(ABC):
                     self._execution_report = Report(
                         step_description=f"[{self.component}] {self.name}: {self.description}",
                         step_execution_status=execution_status if execution_status else ReportStepStatus.FAIL,
-                        step_execution_duration=time.time() - self._start_execution_time
+                        step_execution_duration=time.time() - self._start_execution_time,
+                        step_component=self.component
                     )
         return wrapper
 
index 0e5076f..be06151 100644 (file)
@@ -15,13 +15,13 @@ class ReportStepStatus(Enum):
     FAIL = "FAIL"
     NOT_EXECUTED = "NOT EXECUTED"
 
-
 @dataclass
 class Report:
     """Step execution report."""
     step_description: str
     step_execution_status: ReportStepStatus
     step_execution_duration: float
+    step_component: str
 
 
 class ReportsCollection:
@@ -95,10 +95,11 @@ class ReportsCollection:
                 {
                     'description': step_report.step_description,
                     'status': step_report.step_execution_status.value,
-                    'duration': step_report.step_execution_duration
+                    'duration': step_report.step_execution_duration,
+                    'component': step_report.step_component
                 }
                 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
+            json.dump(report_dict, file, indent=4)
index b5bc48c..7c5bcd7 100644 (file)
@@ -19,12 +19,12 @@ class TestReportsCollection(unittest.TestCase):
         settings.HTML_REPORTING_FILE_NAME = "reporting.html"
         settings.JSON_REPORTING_FILE_NAME = "reporting.json"
 
-        self.collection.put(Report("Step 1", ReportStepStatus.PASS, 10.0))
-        self.collection.put(Report("Step 2", ReportStepStatus.FAIL, 5.0))
-        self.collection.put(Report("Step 3", ReportStepStatus.NOT_EXECUTED, 0.0))
-        self.collection.put(Report("Step 10", ReportStepStatus.NOT_EXECUTED, 0.0))
-        self.collection.put(Report("Step 12", ReportStepStatus.PASS, 20.0))
-        self.collection.put(Report("Step 21", ReportStepStatus.FAIL, 15.0))
+        self.collection.put(Report("Step 1", ReportStepStatus.PASS, 10.0, "TEST"))
+        self.collection.put(Report("Step 2", ReportStepStatus.FAIL, 5.0, "TEST"))
+        self.collection.put(Report("Step 3", ReportStepStatus.NOT_EXECUTED, 0.0, "TEST"))
+        self.collection.put(Report("Step 10", ReportStepStatus.NOT_EXECUTED, 0.0, "TEST"))
+        self.collection.put(Report("Step 12", ReportStepStatus.PASS, 20.0, "TEST"))
+        self.collection.put(Report("Step 21", ReportStepStatus.FAIL, 15.0, "TEST"))
 
         report_dict = self.collection.generate_report()
         report_json_path = os.path.join(settings.REPORTING_FILE_DIRECTORY, settings.JSON_REPORTING_FILE_NAME)