Passed
Pull Request — master (#160)
by Jan
05:29
created

test_arf_to_html_report   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 7

6 Functions

Rating   Name   Duplication   Size   Complexity  
A test_prepare_report() 0 8 1
A test_prepare_report_and_save_in_defined_destination() 0 6 1
A get_client_arf_to_html_with_define_dest() 0 5 1
A test_prepare_report_with_bad_file() 0 4 1
A try_expection_for_prepare_graph() 0 5 2
A get_client_arf_to_html() 0 2 1
1
import os
2
import tempfile
3
import uuid
4
5
import pytest
6
7
import tests.any_test_help
8
from oval_graph.command_line_client.arf_to_html_report import ArfToHtmlReport
9
10
11
def get_client_arf_to_html(src):
12
    return ArfToHtmlReport([tests.any_test_help.get_src(src)])
13
14
15
def get_client_arf_to_html_with_define_dest(src):
16
    return ArfToHtmlReport(
17
        ["--output", tests.any_test_help.get_src(
18
            os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))),
19
         tests.any_test_help.get_src(src)
20
         ])
21
22
23
def try_expection_for_prepare_graph(src, err):
24
    with pytest.raises(Exception, match=err):
25
        client = get_client_arf_to_html(src)
26
        rules = {'rules': ['.']}
27
        assert client.prepare_data(rules)
28
29
30
def test_prepare_report_with_bad_file():
31
    src = 'test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml'
32
33
    try_expection_for_prepare_graph(src, 'not arf report')
34
35
36
@pytest.mark.usefixtures("remove_generated_reports_in_root")
37
def test_prepare_report():
38
    src = 'test_data/ssg-fedora-ds-arf.xml'
39
    client = get_client_arf_to_html(src)
40
    rules = {'rules': ['.']}
41
    results_src = client.prepare_data(rules)
42
    client.kill_web_browsers()
43
    assert os.path.exists(results_src[0])
44
45
46
def test_prepare_report_and_save_in_defined_destination():
47
    src = 'test_data/ssg-fedora-ds-arf.xml'
48
    client = get_client_arf_to_html_with_define_dest(src)
49
    rules = {'rules': ['.']}
50
    results_src = client.prepare_data(rules)
51
    assert os.path.exists(results_src[0])
52