From 344915d84eb2126db0303c1319151eab4f7584a1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 20 Sep 2021 20:53:06 -0700 Subject: [PATCH] gitweb: tests: Use common fixtures for testing actions module Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/gitweb/tests/test_actions.py | 29 ++++----------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/plinth/modules/gitweb/tests/test_actions.py b/plinth/modules/gitweb/tests/test_actions.py index 26ccad990..c76008289 100644 --- a/plinth/modules/gitweb/tests/test_actions.py +++ b/plinth/modules/gitweb/tests/test_actions.py @@ -3,10 +3,7 @@ Test module for gitweb module operations. """ -import imp import json -import pathlib -from unittest.mock import patch import pytest from django.forms import ValidationError @@ -19,29 +16,13 @@ REPO_DATA = { 'access': 'private', } - -def _action_file(): - """Return the path to the 'gitweb' actions file.""" - current_directory = pathlib.Path(__file__).parent - return str(current_directory / '..' / '..' / '..' / '..' / 'actions' / - 'gitweb') +actions_name = 'gitweb' -gitweb_actions = imp.load_source('gitweb', _action_file()) - - -@pytest.fixture(name='call_action') -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(autouse=True) +def fixture_set_repo_path(actions_module, tmpdir): + """Set a repository path in the actions module.""" + actions_module.GIT_REPO_PATH = str(tmpdir) @pytest.fixture(name='existing_repo')