forked from quipucords/qpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
67 lines (53 loc) · 1.72 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (c) 2022 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 3 (GPLv3). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv3
# along with this software; if not, see
# https://www.gnu.org/licenses/gpl-3.0.txt.
#
"""pytest configuration file."""
from unittest import mock
import pytest
QPC_PATH_CONSTANTS = (
"CONFIG_DIR",
"DATA_DIR",
"INSIGHTS_CONFIG",
"INSIGHTS_ENCRYPTION",
"INSIGHTS_LOGIN_CONFIG",
"QPC_CLIENT_TOKEN",
"QPC_LOG",
"QPC_SERVER_CONFIG",
)
@pytest.fixture(autouse=True)
def mock_path_constants(tmp_path, monkeypatch):
"""Mock path constants used on qpc."""
for path in QPC_PATH_CONSTANTS:
monkeypatch.setattr(f"qpc.utils.{path}", str(tmp_path / path))
def _set_path_constants_to_none():
"""Set qpc path constants to None."""
for constant in QPC_PATH_CONSTANTS:
mocker = mock.patch(f"qpc.utils.{constant}", None)
mocker.start()
def pytest_collection(session):
"""pytest collection hook.
This function runs before collecting tests.
"""
_set_path_constants_to_none()
@pytest.fixture
def server_config():
"""
Create server config with require_token set to False.
Since all cli commands require qpc config and qpc login to be executed,
require_token must be False, to avoid passing login info
"""
from qpc.utils import write_server_config
return write_server_config(
{
"host": "127.0.0.1",
"port": 8000,
"use_http": True,
"require_token": False,
}
)