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

test_installation.content_path()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 0
dl 0
loc 4
rs 10
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
import tempfile
20
import pytest
21
22
from org_fedora_oscap.service import installation
23
from org_fedora_oscap.structures import PolicyData
24
25
# FIXME: Extend the tests to test all paths of the installation tasks.
26
27
28
@pytest.fixture()
29
def file_path():
30
    with tempfile.NamedTemporaryFile() as f:
31
        yield f.name
32
33
34
@pytest.fixture()
35
def content_path():
36
    with tempfile.TemporaryDirectory() as tmpdir:
37
        yield tmpdir
38
39
40
@pytest.fixture()
41
def tailoring_path():
42
    with tempfile.TemporaryDirectory() as tmpdir:
43
        yield tmpdir
44
45
46
@pytest.fixture()
47
def sysroot_path():
48
    with tempfile.TemporaryDirectory() as tmpdir:
49
        yield tmpdir
50
51
52
def test_fetch_content_task(caplog, file_path, content_path):
53
    data = PolicyData()
54
    task = installation.FetchContentTask(
55
        policy_data=data,
56
        file_path=file_path,
57
        content_path=content_path,
58
    )
59
60
    with caplog.at_level(logging.DEBUG):
61
        task.run()
62
63
    assert task.name == "Fetch the content"
64
    assert "Content is already available. Skip." in caplog.text
65
66
67
def test_check_fingerprint_task(caplog, file_path):
68
    data = PolicyData()
69
    task = installation.CheckFingerprintTask(
70
        policy_data=data,
71
        file_path=file_path
72
    )
73
74
    with caplog.at_level(logging.DEBUG):
75
        task.run()
76
77
    assert task.name == "Check the fingerprint"
78
    assert "No fingerprint is provided. Skip." in caplog.text
79
80
81
def test_evaluate_rules_task(caplog, content_path, tailoring_path):
82
    data = PolicyData()
83
    task = installation.EvaluateRulesTask(
84
        policy_data=data,
85
        content_path=content_path,
86
        tailoring_path=tailoring_path
87
    )
88
89
    with caplog.at_level(logging.DEBUG):
90
        task.run()
91
92
    assert task.name == "Evaluate the rules"
93
    assert "The security policy is disabled. Skip." in caplog.text
94
95
96
def test_install_content_task(caplog, sysroot_path, file_path, content_path, tailoring_path):
97
    data = PolicyData()
98
    task = installation.InstallContentTask(
99
        sysroot=sysroot_path,
100
        policy_data=data,
101
        file_path=file_path,
102
        content_path=content_path,
103
        tailoring_path=tailoring_path,
104
        target_directory="target_dir"
105
    )
106
107
    with caplog.at_level(logging.DEBUG):
108
        task.run()
109
110
    assert task.name == "Install the content"
111
112
113
def test_remediate_system_task(caplog, sysroot_path, content_path, tailoring_path):
114
    data = PolicyData()
115
    task = installation.RemediateSystemTask(
116
        sysroot=sysroot_path,
117
        policy_data=data,
118
        target_content_path=content_path,
119
        target_tailoring_path=tailoring_path
120
    )
121
122
    with caplog.at_level(logging.DEBUG):
123
        task.run()
124
125
    assert task.name == "Remediate the system"
126