gitweb: 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:
Sunil Mohan Adapa 2021-09-20 20:53:06 -07:00 committed by Veiko Aasa
parent 3526099c03
commit 344915d84e
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -3,10 +3,7 @@
Test module for gitweb module operations. Test module for gitweb module operations.
""" """
import imp
import json import json
import pathlib
from unittest.mock import patch
import pytest import pytest
from django.forms import ValidationError from django.forms import ValidationError
@ -19,29 +16,13 @@ REPO_DATA = {
'access': 'private', 'access': 'private',
} }
actions_name = 'gitweb'
def _action_file():
"""Return the path to the 'gitweb' actions file."""
current_directory = pathlib.Path(__file__).parent
return str(current_directory / '..' / '..' / '..' / '..' / 'actions' /
'gitweb')
gitweb_actions = imp.load_source('gitweb', _action_file()) @pytest.fixture(autouse=True)
def fixture_set_repo_path(actions_module, tmpdir):
"""Set a repository path in the actions module."""
@pytest.fixture(name='call_action') actions_module.GIT_REPO_PATH = str(tmpdir)
def fixture_call_action(tmpdir, capsys):
"""Run actions with custom repo root path."""
def _call_action(args, **kwargs):
gitweb_actions.GIT_REPO_PATH = str(tmpdir)
with patch('argparse._sys.argv', ['gitweb'] + args):
gitweb_actions.main()
captured = capsys.readouterr()
return captured.out
return _call_action
@pytest.fixture(name='existing_repo') @pytest.fixture(name='existing_repo')