mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
matrixsynapse: 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
1ec16a7d58
commit
cf32de2839
@ -1,57 +0,0 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
"""
|
|
||||||
Common test fixtures for Matrix Synapse.
|
|
||||||
"""
|
|
||||||
|
|
||||||
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' / 'matrixsynapse')
|
|
||||||
loader = importlib.machinery.SourceFileLoader('matrixsynapse',
|
|
||||||
actions_file_path)
|
|
||||||
module = types.ModuleType(loader.name)
|
|
||||||
loader.exec_module(module)
|
|
||||||
return module
|
|
||||||
|
|
||||||
|
|
||||||
actions = _load_actions_module()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='managed_turn_conf_file')
|
|
||||||
def fixture_managed_turn_conf_file(tmp_path):
|
|
||||||
"""Returns a dummy TURN configuration file."""
|
|
||||||
conf_file = tmp_path / 'freedombox-turn.yaml'
|
|
||||||
return str(conf_file)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='overridden_turn_conf_file')
|
|
||||||
def fixture_overridden_turn_conf_file(tmp_path):
|
|
||||||
"""Returns a dummy TURN configuration file."""
|
|
||||||
conf_file = tmp_path / 'turn.yaml'
|
|
||||||
return str(conf_file)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='call_action')
|
|
||||||
def fixture_call_action(capsys, managed_turn_conf_file,
|
|
||||||
overridden_turn_conf_file):
|
|
||||||
"""Run actions with custom root path."""
|
|
||||||
|
|
||||||
def _call_action(module_name, args, **kwargs):
|
|
||||||
actions.TURN_CONF_PATH = managed_turn_conf_file
|
|
||||||
actions.OVERRIDDEN_TURN_CONF_PATH = overridden_turn_conf_file
|
|
||||||
with patch('argparse._sys.argv', [module_name] +
|
|
||||||
args), patch('plinth.action_utils.service_try_restart'):
|
|
||||||
actions.main()
|
|
||||||
captured = capsys.readouterr()
|
|
||||||
return captured.out
|
|
||||||
|
|
||||||
return _call_action
|
|
||||||
@ -10,6 +10,32 @@ import pytest
|
|||||||
from plinth.modules import matrixsynapse
|
from plinth.modules import matrixsynapse
|
||||||
from plinth.modules.coturn.components import TurnConfiguration
|
from plinth.modules.coturn.components import TurnConfiguration
|
||||||
|
|
||||||
|
actions_name = 'matrixsynapse'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name='managed_turn_conf_file')
|
||||||
|
def fixture_managed_turn_conf_file(tmp_path):
|
||||||
|
"""Returns a dummy TURN configuration file."""
|
||||||
|
conf_file = tmp_path / 'freedombox-turn.yaml'
|
||||||
|
return str(conf_file)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name='overridden_turn_conf_file')
|
||||||
|
def fixture_overridden_turn_conf_file(tmp_path):
|
||||||
|
"""Returns a dummy TURN configuration file."""
|
||||||
|
conf_file = tmp_path / 'turn.yaml'
|
||||||
|
return str(conf_file)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def fixture_set_paths(actions_module, capsys, managed_turn_conf_file,
|
||||||
|
overridden_turn_conf_file):
|
||||||
|
"""Run actions with custom root path."""
|
||||||
|
actions_module.TURN_CONF_PATH = managed_turn_conf_file
|
||||||
|
actions_module.OVERRIDDEN_TURN_CONF_PATH = overridden_turn_conf_file
|
||||||
|
with patch('plinth.action_utils.service_try_restart'):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='test_configuration', autouse=True)
|
@pytest.fixture(name='test_configuration', autouse=True)
|
||||||
def fixture_test_configuration(call_action, managed_turn_conf_file,
|
def fixture_test_configuration(call_action, managed_turn_conf_file,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user