Passed
Pull Request — master (#160)
by Jan
08:04 queued 04:21
created

test_arf_to_html_report   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 38
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Functions

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