Passed
Pull Request — master (#136)
by
unknown
01:36
created

test_installation.test_install_content_task()   A

Complexity

Conditions 2

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nop 1
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
#
2
# Copyright (C) 2021  Red Hat, Inc.
3
#
4
# This copyrighted material is made available to anyone wishing to use,
5
# modify, copy, or redistribute it subject to the terms and conditions of
6
# the GNU General Public License v.2, or (at your option) any later version.
7
# This program is distributed in the hope that it will be useful, but WITHOUT
8
# ANY WARRANTY expressed or implied, including the implied warranties of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
10
# Public License for more details.  You should have received a copy of the
11
# GNU General Public License along with this program; if not, write to the
12
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
13
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
14
# source code or documentation are not subject to the GNU General Public
15
# License and may only be used or replicated with the express permission of
16
# Red Hat, Inc.
17
#
18
import logging
19
20
from org_fedora_oscap.service import installation
21
from org_fedora_oscap.structures import PolicyData
22
23
# FIXME: Extend the tests to test all paths of the installation tasks.
24
25
26
def test_fetch_content_task(caplog):
27
    data = PolicyData()
28
    task = installation.FetchContentTask(
29
        policy_enabled=False,
30
        policy_data=data,
31
        file_path="/file/path",
32
        content_path="/content/path",
33
    )
34
35
    with caplog.at_level(logging.DEBUG):
36
        task.run()
37
38
    assert task.name == "Fetch the content"
39
    assert "The security policy is disabled. Skip." in caplog.text
40
41
42
def test_check_fingerprint_task(caplog):
43
    data = PolicyData()
44
    task = installation.CheckFingerprintTask(
45
        policy_enabled=False,
46
        policy_data=data,
47
        file_path="/file/path"
48
    )
49
50
    with caplog.at_level(logging.DEBUG):
51
        task.run()
52
53
    assert task.name == "Check the fingerprint"
54
    assert "The security policy is disabled. Skip." in caplog.text
55
56
57
def test_evaluate_rules_task(caplog):
58
    data = PolicyData()
59
    task = installation.EvaluateRulesTask(
60
        policy_enabled=False,
61
        policy_data=data,
62
        content_path="/content/path",
63
        tailoring_path="/tailoring/path"
64
    )
65
66
    with caplog.at_level(logging.DEBUG):
67
        task.run()
68
69
    assert task.name == "Evaluate the rules"
70
    assert "The security policy is disabled. Skip." in caplog.text
71
72
73
def test_install_content_task(caplog):
74
    data = PolicyData()
75
    task = installation.InstallContentTask(
76
        sysroot="/sysroot/path",
77
        policy_enabled=False,
78
        policy_data=data,
79
        file_path="/file/path",
80
        content_path="/content/path",
81
        tailoring_path="/tailoring/path",
82
        target_directory="target_dir"
83
    )
84
85
    with caplog.at_level(logging.DEBUG):
86
        task.run()
87
88
    assert task.name == "Install the content"
89
    assert "The security policy is disabled. Skip." in caplog.text
90
91
92
def test_remediate_system_task(caplog):
93
    data = PolicyData()
94
    task = installation.RemediateSystemTask(
95
        sysroot="/sysroot/path",
96
        policy_enabled=False,
97
        policy_data=data,
98
        target_content_path="/target/content/path",
99
        target_tailoring_path="/target/tailoring/path"
100
    )
101
102
    with caplog.at_level(logging.DEBUG):
103
        task.run()
104
105
    assert task.name == "Remediate the system"
106
    assert "The security policy is disabled. Skip." in caplog.text
107