mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-17 11:10:23 +00:00
- Done automatically by running isort . in top level directory. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Common test fixtures for MediaWiki.
|
|
"""
|
|
|
|
import importlib
|
|
import pathlib
|
|
import shutil
|
|
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' / 'mediawiki')
|
|
loader = importlib.machinery.SourceFileLoader('mediawiki',
|
|
actions_file_path)
|
|
module = types.ModuleType(loader.name)
|
|
loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
actions = _load_actions_module()
|
|
|
|
|
|
@pytest.fixture(name='call_action')
|
|
def fixture_call_action(capsys, conf_file):
|
|
"""Run actions with custom root path."""
|
|
|
|
def _call_action(module_name, args, **kwargs):
|
|
actions.CONF_FILE = conf_file
|
|
with patch('argparse._sys.argv', [module_name] + args):
|
|
actions.main()
|
|
captured = capsys.readouterr()
|
|
return captured.out
|
|
|
|
return _call_action
|
|
|
|
|
|
@pytest.fixture(name='conf_file')
|
|
def fixture_conf_file(tmp_path):
|
|
"""Uses a dummy configuration file."""
|
|
settings_file_name = 'FreedomBoxSettings.php'
|
|
conf_file = tmp_path / settings_file_name
|
|
conf_file.touch()
|
|
shutil.copyfile(
|
|
str(current_directory / '..' / 'data' / 'etc' / 'mediawiki' /
|
|
settings_file_name), str(conf_file))
|
|
return str(conf_file)
|