tests.integration_tests.test_json   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_json_structure_with_schema() 0 8 2
A test_json_count_of_rules() 0 5 1
1
# Copyright 2022, Red Hat, Inc.
2
# SPDX-License-Identifier: LGPL-2.1-or-later
3
4
import json
5
6
import pytest
7
from jsonschema import validate
8
9
from openscap_report.debug_settings import DebugSetting
10
from openscap_report.report_generators.json import JSONReportGenerator
11
from tests.unit_tests.test_data_structure import get_parser, get_report
12
13
from ..constants import PATH_TO_ARF, PATH_TO_JSON_SCHEMA
14
15
16
@pytest.mark.integration_test
17
def test_json_structure_with_schema():
18
    json_schema = None
19
    with open(PATH_TO_JSON_SCHEMA, "r", encoding="utf-8") as schema_file:
20
        json_schema = json.load(schema_file)
21
    json_gen = JSONReportGenerator(get_parser(PATH_TO_ARF))
22
    json_data = json_gen.generate_report(DebugSetting()).read().decode("utf-8")
23
    validate(json.loads(json_data), json_schema)
24
25
26
@pytest.mark.integration_test
27
def test_json_count_of_rules():
28
    report = get_report()
29
    json_dict = report.as_dict_for_default_json()
30
    assert len(json_dict["rules"]) == 714
31