From ee21dcfbb82cd002eb444e39e4224b48f8caeb38 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Wed, 22 May 2019 12:45:19 +0530 Subject: [PATCH] backups: Avoid using `sudo` in tests Signed-off-by: Joseph Nuthalapati --- plinth/modules/backups/tests/test_ssh_remotes.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plinth/modules/backups/tests/test_ssh_remotes.py b/plinth/modules/backups/tests/test_ssh_remotes.py index 1ab962877..3fd521d6a 100644 --- a/plinth/modules/backups/tests/test_ssh_remotes.py +++ b/plinth/modules/backups/tests/test_ssh_remotes.py @@ -31,7 +31,7 @@ from plinth.utils import generate_password, random_string from .. import forms -pytestmark = pytest.mark.usefixtures('needs_root', 'needs_sudo') +pytestmark = pytest.mark.usefixtures('needs_root') @pytest.fixture(name='temp_home', scope='module', autouse=True) @@ -43,7 +43,7 @@ def fixture_temp_home_directory(): dir_name = f'/tmp/{random_string()}' os.mkdir(dir_name) yield dir_name - subprocess.check_call(['sudo', 'rm', '-rf', dir_name]) + subprocess.check_call(['rm', '-rf', dir_name]) @pytest.fixture(name='password', scope='module', autouse=True) @@ -59,20 +59,20 @@ def fixture_create_temp_user(temp_home, password): # User account expires tomorrow tomorrow = datetime.date.today() + datetime.timedelta(days=1) subprocess.check_call([ - 'sudo', 'useradd', '-d', temp_home, '-m', '-p', password, username, - '-e', + 'useradd', '-d', temp_home, '-m', '-p', password, username, '-e', tomorrow.strftime('%Y-%m-%d') ]) - subprocess.check_call(['sudo', 'chown', username, temp_home]) + subprocess.check_call(['chown', username, temp_home]) yield username - subprocess.check_call(['sudo', 'userdel', username]) + subprocess.check_call(['userdel', username]) +@pytest.mark.usefixtures('needs_sudo') @pytest.fixture(name='has_ssh_key', scope='module', autouse=True) def fixture_ssh_key(temp_home, temp_user, password): subprocess.check_call([ - 'sudo', '-u', temp_user, 'ssh-keygen', '-t', 'rsa', '-b', '1024', '-N', - '', '-f', f'{temp_home}/.ssh/id_rsa', '-q' + 'sudo', '-n', '-u', temp_user, 'ssh-keygen', '-t', 'rsa', '-b', '1024', + '-N', '', '-f', f'{temp_home}/.ssh/id_rsa', '-q' ])