mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
mediawiki: 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
757d24c2be
commit
351ba99c12
@ -1,53 +0,0 @@
|
||||
# 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)
|
||||
@ -4,12 +4,34 @@ Test module for MediaWiki utility functions.
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import shutil
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from plinth.modules import mediawiki
|
||||
|
||||
actions_name = 'mediawiki'
|
||||
current_directory = pathlib.Path(__file__).parent
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_setup_configuration(actions_module, conf_file):
|
||||
"""Set configuration file path in actions module."""
|
||||
actions_module.CONF_FILE = conf_file
|
||||
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
@pytest.fixture(name='test_configuration', autouse=True)
|
||||
def fixture_test_configuration(call_action, conf_file):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user