mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
tests: Add fixture to help in testing privileged actions
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
6e1c8c30fd
commit
fdbe537529
35
conftest.py
35
conftest.py
@ -168,6 +168,41 @@ def fixture_call_action(request, capsys, actions_module):
|
|||||||
return _call_action
|
return _call_action
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name='mock_privileged')
|
||||||
|
def fixture_mock_privileged(request):
|
||||||
|
"""Mock the privileged decorator to nullify its effects."""
|
||||||
|
try:
|
||||||
|
privileged_modules_to_mock = request.module.privileged_modules_to_mock
|
||||||
|
except AttributeError:
|
||||||
|
raise AttributeError(
|
||||||
|
'mock_privileged fixture requires "privileged_module_to_mock" '
|
||||||
|
'attribute at module level')
|
||||||
|
|
||||||
|
for module_name in privileged_modules_to_mock:
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
for name, member in module.__dict__.items():
|
||||||
|
wrapped = getattr(member, '__wrapped__', None)
|
||||||
|
if not callable(member) or not wrapped:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not getattr(member, '_privileged', False):
|
||||||
|
continue
|
||||||
|
|
||||||
|
setattr(wrapped, '_original_wrapper', member)
|
||||||
|
module.__dict__[name] = wrapped
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
for module_name in privileged_modules_to_mock:
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
for name, member in module.__dict__.items():
|
||||||
|
wrapper = getattr(member, '_original_wrapper', None)
|
||||||
|
if not callable(member) or not wrapper:
|
||||||
|
continue
|
||||||
|
|
||||||
|
module.__dict__[name] = wrapper
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='splinter_screenshot_dir', scope='session')
|
@pytest.fixture(name='splinter_screenshot_dir', scope='session')
|
||||||
def fixture_splinter_screenshot_dir(request):
|
def fixture_splinter_screenshot_dir(request):
|
||||||
"""Set default screenshot directory to ./screenshots.
|
"""Set default screenshot directory to ./screenshots.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user