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

tests.test_client.test_client()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
import re
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
introduced by
import missing from __future__ import absolute_import
Loading history...
2
import json
0 ignored issues
show
Unused Code introduced by
The import json seems to be unused.
Loading history...
3
import mock
4
import sys
0 ignored issues
show
introduced by
standard import "import sys" should be placed before "import mock"
Loading history...
5
import os
0 ignored issues
show
Unused Code introduced by
The import os seems to be unused.
Loading history...
introduced by
standard import "import os" should be placed before "import mock"
Loading history...
6
import tempfile
0 ignored issues
show
Unused Code introduced by
The import tempfile seems to be unused.
Loading history...
introduced by
standard import "import tempfile" should be placed before "import mock"
Loading history...
7
8
import pytest
9
10
from oval_graph.client import Client
11
import tests.any_test_help
12
13
14
def get_client(src, rule):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
15
    return Client(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
16
        [tests.any_test_help.get_src(src), rule])
17
18
19
def get_client_on_web_browser(src, rule):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
20
    return Client(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
21
        [tests.any_test_help.get_src(src), rule])
22
23
24
def test_client():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
25
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
26
    rule = 'rule'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
27
    client = get_client(src, rule)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
28
    assert client.source_filename == tests.any_test_help.get_src(src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
29
    assert client.rule_name == rule
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
30
31
32
def test_search_rules_id():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
33
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
34
    part_of_id_rule = 'xccdf_org.ssgproject.'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
35
    client = get_client(src, part_of_id_rule)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
36
    assert len(client.search_rules_id()) == 184
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
37
38
39
def test_search_rules_id_on_web_browser():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_search_rules_id_on_web_browser" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
40
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
41
    part_of_id_rule = 'xccdf_org.ssgproject.'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
42
    client = get_client_on_web_browser(src, part_of_id_rule)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
43
    assert len(client.search_rules_id()) == 184
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
44
45
46
def test_search_non_existent_rule():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
47
    rule = 'random_rule_which_doest_exist'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
48
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
49
    client = get_client(src, rule)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
50
    with pytest.raises(Exception, match='404 rule "{}" not found!'.format(rule)):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (81/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
51
        assert client.search_rules_id()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
52
53
54
def test_find_not_selected_rule():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
55
    rule = 'xccdf_org.ssgproject.content_rule_ntpd_specify_remote_server'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
56
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
57
    client = get_client(src, rule)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
58
    with pytest.raises(Exception, match=rule):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
59
        assert client.search_rules_id()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
60
61
62
def test_search_rules_with_regex():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
63
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
64
    regex = r'_package_\w+_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
65
    client = get_client(src, regex)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
66
    assert len(client.search_rules_id()) == 2
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
67
68
69
def test_get_questions():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
70
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
71
    regex = r'_package_\w+_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
72
    client = get_client(src, regex)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
73
    out = client.get_questions()[0].choices
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
74
    rule1 = 'xccdf_org.ssgproject.content_rule_package_abrt_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
75
    rule2 = 'xccdf_org.ssgproject.content_rule_package_sendmail_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
76
    assert out[0] == rule1
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
77
    assert out[1] == rule2
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
78
79
80
def test_get_wanted_not_selected_rules_from_array_of_IDs():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_get_wanted_not_selected_rules_from_array_of_IDs" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
81
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
82
    regex = r'_package_\w+_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
83
    client = get_client(src, regex)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
84
85
    out = [
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
86
        'xccdf_org.ssgproject.content_rule_package_nis_removed',
87
        'xccdf_org.ssgproject.content_rule_package_ntpdate_removed',
88
        'xccdf_org.ssgproject.content_rule_package_telnetd_removed',
89
        'xccdf_org.ssgproject.content_rule_package_gdm_removed',
90
        'xccdf_org.ssgproject.content_rule_package_setroubleshoot_removed',
91
        'xccdf_org.ssgproject.content_rule_package_mcstrans_removed']
92
93
    assert out == client._get_wanted_rules_from_array_of_IDs(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Best Practice introduced by
It seems like _get_wanted_rules_from_array_of_IDs was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
94
        client.xml_parser.notselected_rules)
95
96
97
def test_get_wanted_rules_from_array_of_IDs():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_get_wanted_rules_from_array_of_IDs" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
98
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
99
    regex = r'_package_\w+_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
100
    client = get_client(src, regex)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
101
102
    out = [
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
103
        'xccdf_org.ssgproject.content_rule_package_abrt_removed',
104
        'xccdf_org.ssgproject.content_rule_package_sendmail_removed',
105
    ]
106
107
    assert out == client._get_wanted_rules_from_array_of_IDs(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
Coding Style Best Practice introduced by
It seems like _get_wanted_rules_from_array_of_IDs was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
108
        client.xml_parser.used_rules.keys())
109
110
111
def test_search_not_selected_rule():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
112
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
113
    non_existent_rule = 'xccdf_org.ssgproject.content_rule_package_nis_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
114
    with pytest.raises(Exception, match=non_existent_rule):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
115
        assert get_client(src, non_existent_rule).search_rules_id()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
116
117
118
def test_if_not_installed_inquirer(capsys):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
119
    with mock.patch.dict(sys.modules, {'inquirer': None}):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
120
        src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
121
        regex = r'_package_\w+_removed'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
122
        client = get_client(src, regex)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
123
        client.isatty = True
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
124
        out = client.run_gui_and_return_answers()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
125
        assert out is None
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
126
        captured = capsys.readouterr()
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
127
        assert len(re.findall(regex, captured.out)) == 2
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
128