Passed
Pull Request — master (#161)
by Jan
04:56
created

test_json_to_html   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A tests.test_json_to_html.test_prepare_tree() 0 8 1
A tests.test_json_to_html.get_client_json_to_html() 0 2 1
A tests.test_json_to_html.test_prepare_tree_and_save_in_defined_destination() 0 6 1
A tests.test_json_to_html.test_prepare_graph_with_not_valid_file() 0 4 1
A tests.test_json_to_html.test_prepare_graph_with_bat_data() 0 4 1
A tests.test_json_to_html.test_prepare_graph_with_not_exist_rule() 0 4 1
A tests.test_json_to_html.get_client_json_to_html_with_define_dest() 0 6 1
A tests.test_json_to_html.try_expection_for_prepare_graph() 0 5 2
1
import pytest
2
import tempfile
3
import os
4
import uuid
5
6
from oval_graph.json_to_html import JsonToHtml
7
import tests.any_test_help
8
9
10
def get_client_json_to_html(src, rule):
11
    return JsonToHtml(["--display", tests.any_test_help.get_src(src), rule])
12
13
14
def get_client_json_to_html_with_define_dest(src, rule):
15
    return JsonToHtml(
16
        ["--output", tests.any_test_help.get_src(
17
            os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))),
18
         tests.any_test_help.get_src(src),
19
         rule,
20
         ])
21
22
23
def try_expection_for_prepare_graph(src, rule, err):
24
    rules = {'rules': [rule]}
25
    with pytest.raises(Exception, match=err):
26
        client = get_client_json_to_html(src, rule)
27
        assert client.prepare_data(rules)
28
29
30
def test_prepare_graph_with_not_valid_file():
31
    src = 'test_data/ssg-fedora-ds-arf.xml'
32
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
33
    try_expection_for_prepare_graph(src, rule, 'is not valid json')
34
35
36
def test_prepare_graph_with_not_exist_rule():
37
    src = 'test_data/referenc_html_report.html'
38
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
39
    try_expection_for_prepare_graph(src, rule, 'No such file or directory:')
40
41
42
def test_prepare_graph_with_bat_data():
43
    src = 'test_data/bad_result_data_json.json'
44
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
45
    try_expection_for_prepare_graph(src, rule, 'valid for OVAL tree')
46
47
48
@pytest.mark.usefixtures("remove_generated_reports_in_root")
49
def test_prepare_tree():
50
    src = 'test_data/referenc_result_data_json.json'
51
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
52
    client = get_client_json_to_html(src, rule)
53
    results_src = client.prepare_data({'rules': client.search_rules_id()})
54
    tests.any_test_help.compare_results_html(results_src[0])
55
    client.kill_web_browsers()
56
57
58
def test_prepare_tree_and_save_in_defined_destination():
59
    src = 'test_data/referenc_result_data_json.json'
60
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
61
    client = get_client_json_to_html_with_define_dest(src, rule)
62
    results_src = client.prepare_data({'rules': client.search_rules_id()})
63
    tests.any_test_help.compare_results_html(results_src[0])
64