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

tests.test_arf_to_hml   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 107
dl 0
loc 140
rs 10
c 0
b 0
f 0
wmc 20

16 Functions

Rating   Name   Duplication   Size   Complexity  
A test_prepare_tree() 0 9 1
A get_client_arf_to_html_with_define_dest() 0 6 1
A test_prepare_graph_with_not_selected_rule() 0 4 1
A get_client_arf_to_html() 0 2 1
A test_prepare_graph_with_non_existent_rule() 0 4 1
A get_client_arf_to_html_with_option_show_not_selected_rules_and_show_failed_rules() 0 7 1
A try_expection_for_prepare_graph() 0 5 2
A test_get_questions_with_option_show_failed_rules() 0 5 1
A test_if_not_installed_inquirer_with_option_show_not_selected_rules() 0 9 2
A test_if_not_installed_inquirer_with_option_show_failed_rules() 0 9 2
A get_client_arf_to_html_with_option_show_failed_rules() 0 3 1
A test_get_questions_not_selected_and_show_failed_rules() 0 7 1
A get_client_arf_to_html_with_option_show_not_selected_rules() 0 4 1
A test_prepare_tree_and_save_in_defined_destination() 0 7 1
A test_if_not_installed_inquirer_with_option_show_not_selected_rules_and_show_failed_rules() 0 11 2
A test_get_questions_not_selected() 0 6 1
1
import pytest
2
import tempfile
3
import os
4
import uuid
5
import mock
6
import sys
7
8
from oval_graph.arf_to_html import ArfToHtml
9
import tests.any_test_help
10
11
12
def get_client_arf_to_html(src, rule):
13
    return ArfToHtml(["--display", tests.any_test_help.get_src(src), rule])
14
15
16
def get_client_arf_to_html_with_define_dest(src, rule):
17
    return ArfToHtml(
18
        ["--output", tests.any_test_help.get_src(
19
            os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))),
20
         tests.any_test_help.get_src(src),
21
         rule])
22
23
24
def get_client_arf_to_html_with_option_show_failed_rules(src, rule):
25
    return ArfToHtml(["--show-failed-rules",
26
                      tests.any_test_help.get_src(src), rule])
27
28
29
def get_client_arf_to_html_with_option_show_not_selected_rules(src, rule):
30
    return ArfToHtml(["--show-not-selected-rules",
31
                      tests.any_test_help.get_src(src),
32
                      rule])
33
34
35
def get_client_arf_to_html_with_option_show_not_selected_rules_and_show_failed_rules(
36
        src,
37
        rule):
38
    return ArfToHtml(["--show-not-selected-rules",
39
                      "--show-failed-rules",
40
                      tests.any_test_help.get_src(src),
41
                      rule])
42
43
44
def try_expection_for_prepare_graph(src, rule, err):
45
    client = get_client_arf_to_html(src, rule)
46
    rules = {'rules': [rule]}
47
    with pytest.raises(Exception, match=err):
48
        assert client.prepare_data(rules)
49
50
51
def test_prepare_graph_with_non_existent_rule():
52
    src = 'test_data/ssg-fedora-ds-arf.xml'
53
    rule = 'non-existent_rule'
54
    try_expection_for_prepare_graph(src, rule, '404')
55
56
57
def test_prepare_graph_with_not_selected_rule():
58
    src = 'test_data/ssg-fedora-ds-arf.xml'
59
    rule = 'xccdf_org.ssgproject.content_rule_package_nis_removed'
60
    try_expection_for_prepare_graph(src, rule, 'not selected')
61
62
63
@pytest.mark.usefixtures("remove_generated_reports_in_root")
64
def test_prepare_tree():
65
    src = 'test_data/ssg-fedora-ds-arf.xml'
66
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
67
    client = get_client_arf_to_html(src, rule)
68
    rules = {'rules': [rule]}
69
    results_src = client.prepare_data(rules)
70
    tests.any_test_help.compare_results_html(results_src[0])
71
    client.kill_web_browsers()
72
73
74
def test_prepare_tree_and_save_in_defined_destination():
75
    src = 'test_data/ssg-fedora-ds-arf.xml'
76
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
77
    client = get_client_arf_to_html_with_define_dest(src, rule)
78
    rules = {'rules': [rule]}
79
    results_src = client.prepare_data(rules)
80
    tests.any_test_help.compare_results_html(results_src[0])
81
82
83
def test_get_questions_not_selected(capsys):
84
    src = 'test_data/ssg-fedora-ds-arf.xml'
85
    regex = r'_package_\w+_removed'
86
    client = get_client_arf_to_html_with_option_show_not_selected_rules(
87
        src, regex)
88
    tests.any_test_help.get_questions_not_selected(capsys, client)
89
90
91
def test_get_questions_not_selected_and_show_failed_rules(capsys):
92
    src = 'test_data/ssg-fedora-ds-arf.xml'
93
    regex = r'_package_\w+_removed'
94
    client = get_client_arf_to_html_with_option_show_not_selected_rules_and_show_failed_rules(
95
        src, regex)
96
    tests.any_test_help.get_questions_not_selected_and_show_failed_rules(
97
        capsys, client)
98
99
100
def test_get_questions_with_option_show_failed_rules():
101
    src = 'test_data/ssg-fedora-ds-arf.xml'
102
    regex = r'_package_\w+_removed'
103
    client = get_client_arf_to_html_with_option_show_failed_rules(src, regex)
104
    tests.any_test_help.get_questions_with_option_show_failed_rules(client)
105
106
107
def test_if_not_installed_inquirer_with_option_show_failed_rules(capsys):
108
    with mock.patch.dict(sys.modules, {'inquirer': None}):
109
        src = 'test_data/ssg-fedora-ds-arf.xml'
110
        regex = r'_package_\w+_removed'
111
        client = get_client_arf_to_html_with_option_show_failed_rules(
112
            src, regex)
113
        client.isatty = True
114
        tests.any_test_help.if_not_installed_inquirer_with_option_show_failed_rules(
115
            capsys, client)
116
117
118
def test_if_not_installed_inquirer_with_option_show_not_selected_rules(capsys):
119
    with mock.patch.dict(sys.modules, {'inquirer': None}):
120
        src = 'test_data/ssg-fedora-ds-arf.xml'
121
        regex = r'_package_\w+_removed'
122
        client = get_client_arf_to_html_with_option_show_not_selected_rules(
123
            src, regex)
124
        client.isatty = True
125
        tests.any_test_help.if_not_installed_inquirer_with_option_show_not_selected_rules(
126
            capsys, client)
127
128
129
def test_if_not_installed_inquirer_with_option_show_not_selected_rules_and_show_failed_rules(
130
        capsys):
131
    with mock.patch.dict(sys.modules, {'inquirer': None}):
132
        src = 'test_data/ssg-fedora-ds-arf.xml'
133
        regex = r'_package_\w+_removed'
134
        client = get_client_arf_to_html_with_option_show_not_selected_rules_and_show_failed_rules(
135
            src, regex)
136
        client.isatty = True
137
        (tests.any_test_help.
138
         if_not_installed_inquirer_with_option_show_not_selected_rules_and_show_failed_rules(
139
             capsys, client))
140