Passed
Push — master ( f92a60...087b33 )
by Matěj
02:24 queued 11s
created

test_arf_to_hml   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 8

7 Functions

Rating   Name   Duplication   Size   Complexity  
A get_client_arf_to_html() 0 3 1
A get_client_arf_to_html_with_define_dest() 0 7 1
A test_prepare_graph_with_not_selected_rule() 0 4 1
A test_prepare_graph_with_non_existent_rule() 0 4 1
A test_prepare_tree() 0 7 1
A test_prepare_tree_and_save_in_defined_destination() 0 7 1
A 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.arf_to_html import ArfToHtml
7
import tests.any_test_help
8
9
10
def get_client_arf_to_html(src, rule):
11
    return ArfToHtml(
12
        ["--off-web-browser", tests.any_test_help.get_src(src), rule])
13
14
15
def get_client_arf_to_html_with_define_dest(src, rule):
16
    return ArfToHtml(
17
        ["--out", tests.any_test_help.get_src(
18
            os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))),
19
         "--off-web-browser",
20
         tests.any_test_help.get_src(src),
21
         rule])
22
23
24
def try_expection_for_prepare_graph(src, rule, err):
25
    client = get_client_arf_to_html(src, rule)
26
    rules = {'rules': [rule]}
27
    with pytest.raises(Exception, match=err):
28
        assert client.prepare_data(rules)
29
30
31
def test_prepare_graph_with_non_existent_rule():
32
    src = 'test_data/ssg-fedora-ds-arf.xml'
33
    rule = 'non-existent_rule'
34
    try_expection_for_prepare_graph(src, rule, '404')
35
36
37
def test_prepare_graph_with_not_selected_rule():
38
    src = 'test_data/ssg-fedora-ds-arf.xml'
39
    rule = 'xccdf_org.ssgproject.content_rule_package_nis_removed'
40
    try_expection_for_prepare_graph(src, rule, 'not selected')
41
42
43
def test_prepare_tree():
44
    src = 'test_data/ssg-fedora-ds-arf.xml'
45
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
46
    client = get_client_arf_to_html(src, rule)
47
    rules = {'rules': [rule]}
48
    results_src = client.prepare_data(rules)
49
    tests.any_test_help.compare_results_js(results_src[0])
50
51
52
def test_prepare_tree_and_save_in_defined_destination():
53
    src = 'test_data/ssg-fedora-ds-arf.xml'
54
    rule = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
55
    client = get_client_arf_to_html_with_define_dest(src, rule)
56
    rules = {'rules': [rule]}
57
    results_src = client.prepare_data(rules)
58
    tests.any_test_help.compare_results_js(results_src[0])
59