mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-19 12:36:06 +00:00
openvpn: tests: Use common fixtures for testing actions module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
344915d84e
commit
1ec16a7d58
@ -1,45 +0,0 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Common test fixtures for OpenVPN.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import pathlib
|
||||
import types
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
current_directory = pathlib.Path(__file__).parent
|
||||
|
||||
|
||||
def _load_actions_module():
|
||||
actions_file_path = str(current_directory / '..' / '..' / '..' / '..' /
|
||||
'actions' / 'openvpn')
|
||||
loader = importlib.machinery.SourceFileLoader('openvpn', actions_file_path)
|
||||
module = types.ModuleType(loader.name)
|
||||
loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
actions = _load_actions_module()
|
||||
|
||||
|
||||
@pytest.fixture(name='keys_directory')
|
||||
def fixture_keys_directory(tmp_path):
|
||||
return tmp_path
|
||||
|
||||
|
||||
@pytest.fixture(name='call_action')
|
||||
def fixture_call_action(capsys, keys_directory):
|
||||
"""Run actions with overridden directory paths."""
|
||||
|
||||
def _call_action(module_name, args, **kwargs):
|
||||
actions.DH_PARAMS = f'{keys_directory}/pki/dh.pem'
|
||||
actions.EC_PARAMS_DIR = f'{keys_directory}/pki/ecparams'
|
||||
with patch('argparse._sys.argv', [module_name] + args):
|
||||
actions.main()
|
||||
captured = capsys.readouterr()
|
||||
return captured.out
|
||||
|
||||
return _call_action
|
||||
@ -10,6 +10,20 @@ import pytest
|
||||
|
||||
from plinth.modules import openvpn
|
||||
|
||||
actions_name = 'openvpn'
|
||||
|
||||
|
||||
@pytest.fixture(name='keys_directory')
|
||||
def fixture_keys_directory(tmp_path):
|
||||
return tmp_path
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_set_keys_directory(actions_module, keys_directory):
|
||||
"""Set the keys directory in the actions module."""
|
||||
actions_module.DH_PARAMS = f'{keys_directory}/pki/dh.pem'
|
||||
actions_module.EC_PARAMS_DIR = f'{keys_directory}/pki/ecparams'
|
||||
|
||||
|
||||
@pytest.fixture(name='conf_file')
|
||||
def fixture_conf_file(tmp_path):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user