aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/reports_collection.py
blob: 62c044789c549387a8d09a6c5551d222154a2e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
from typing import Dict
from jinja2 import Environment, FileSystemLoader, select_autoescape
from onapsdk.configuration import settings

class ReportsCollection:
    """Collection to store steps execution statuses."""

    def __init__(self) -> None:
        """Initialize collection."""
        self._collection: list = []

    def put(self, item: Dict[str, str]) -> None:
        """Put execution status dictionary.

        Args:
            item (Dict[str, str]): Step name with status dictionary

        """
        self._collection.append(item)

    @property
    def report(self) -> Dict[str, str]:
        """Get report.

        Build a dictionary with execution statuses.

        Returns:
            Dict[str, str]: Steps name with status dictionary

        """
        report: Dict[str, str] = {}
        for element in self._collection[::-1]:
            report.update(element)
        return report

    def generate_report(self) -> None:
        step_list = self.report
        failing_steps = []
        for step,status in step_list.items():
            if 'FAIL' in status:
                failing_steps[step] = status
        usecase = settings.SERVICE_NAME
        try:
            details = settings.SERVICE_DETAILS
        except:
            details = ""
        try:
            components = settings.SERVICE_COMPONENTS
        except:
            components = ""
        log_path = settings.LOG_CONFIG['handlers']['file']['filename']
        jinja_env = Environment(
            autoescape=select_autoescape(['html']),
            loader=FileSystemLoader(sys.path[-1] + '/onaptests/templates/reporting'))

        jinja_env.get_template('reporting.html.j2').stream(
            failing_steps=failing_steps,
            steps=step_list,
            usecase=usecase,
            details=details,
            components=components,
            log_path=log_path).dump(
            settings.REPORTING_FILE_PATH)