Passed
Pull Request — master (#202)
by Jan
04:08
created

tests_oval_graph.test_commands.test_command_bad_arf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

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

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_bad_command_json_to_graph_with_verbose() 0 7 1
A test_command_with_bad_arf_file() 0 25 2
A test_bad_command_json_to_graph() 0 6 1
1
import subprocess
2
3
import pytest
4
5
COMMAND_START = ['python3',
6
                 '-m',
7
                 'oval_graph.command_line'
8
                 ]
9
10
JSON_TO_GRAPH_COMMAND = [*COMMAND_START,
11
                         'json-to-graph',
12
                         'tests_oval_graph/global_test_data/ssg-fedora-ds-arf.xml',
13
                         '.'
14
                         ]
15
16
17
@pytest.mark.parametrize("command_name, optional_args", [
18
    ('arf-to-graph', []),
19
    ('arf-to-json', []),
20
    ('arf-to-graph', ['-v']),
21
    ('arf-to-json', ['-v']),
22
])
23
def test_command_with_bad_arf_file(command_name, optional_args):
24
    command = [
25
        *COMMAND_START,
26
        command_name,
27
        'tests/test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml',
28
        '.'
29
    ]
30
    command.extend(optional_args)
31
32
    out = subprocess.check_output(
33
        command,
34
        stderr=subprocess.STDOUT)
35
    out_string = out.decode('utf-8')
36
    if '-v' in optional_args:
37
        assert out_string.find("Traceback") > -1
38
    else:
39
        assert out_string.find("Traceback") == -1
40
    assert out_string.find("Warning:") > -1
41
    assert out_string.find("Error:") > -1
42
43
44
def test_bad_command_json_to_graph_with_verbose():
45
    command = [*JSON_TO_GRAPH_COMMAND, '-v']
46
    out = subprocess.check_output(command,
47
                                  stderr=subprocess.STDOUT)
48
    out_string = out.decode('utf-8')
49
    assert out_string.find("Traceback") > -1
50
    assert out_string.find("Error:") > -1
51
52
53
def test_bad_command_json_to_graph():
54
    out = subprocess.check_output(JSON_TO_GRAPH_COMMAND,
55
                                  stderr=subprocess.STDOUT)
56
    out_string = out.decode('utf-8')
57
    assert out_string.find("Traceback") == -1
58
    assert out_string.find("Error:") > -1
59