mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
*: Use action_utils.run instead of subprocess.check_output
- This is to capture stdout and stderr and transmit that from privileged daemon back to the service to be displayed in HTML. Tests: - Unit tests and code checks pass. - Some of the modified actions work as expected. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
1 parent
bf9005ac48
commit
b253166f6d
17 files changed
+101
-72
No files matched your search
@@ -7,7 +7,7 @@ import re
|
||||
import subprocess
|
||||
from datetime import datetime as datetime_original
|
||||
from datetime import timezone
|
||||
from unittest.mock import call, patch
|
||||
from unittest.mock import Mock, call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -264,28 +264,40 @@ def test_services_disable(service_is_running, service_disable, service_enable):
|
||||
|
||||
|
||||
@patch('subprocess.run')
|
||||
@patch('subprocess.check_output')
|
||||
def test_apt_hold_packages(check_output, run, tmp_path):
|
||||
def test_apt_hold_packages(run, tmp_path):
|
||||
"""Test that holding apt packages works."""
|
||||
|
||||
def _run(command, **kwargs):
|
||||
if 'showhold' in command:
|
||||
return Mock(stdout=False)
|
||||
|
||||
return Mock(returncode=0)
|
||||
|
||||
hold_flag = tmp_path / 'flag'
|
||||
run.return_value.returncode = 0
|
||||
run.side_effect = _run
|
||||
with patch('plinth.action_utils.apt_hold_flag', hold_flag), \
|
||||
patch('plinth.modules.upgrades.distupgrade.PACKAGES_WITH_PROMPTS',
|
||||
['package1', 'package2']):
|
||||
check_output.return_value = False
|
||||
with distupgrade._apt_hold_packages():
|
||||
assert hold_flag.exists()
|
||||
assert hold_flag.stat().st_mode & 0o117 == 0
|
||||
expected_calls = [
|
||||
call(['apt-mark', 'hold', 'freedombox'],
|
||||
call(['apt-mark', 'showhold', 'freedombox'], check=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE),
|
||||
call(['apt-mark', 'hold', 'freedombox'], check=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE),
|
||||
call(['apt-mark', 'showhold', 'package1'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
check=True),
|
||||
call(['apt-mark', 'hold', 'package1'], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, check=False),
|
||||
call(['apt-mark', 'hold', 'package2'], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, check=False)
|
||||
call(['apt-mark', 'hold', 'package1'], check=False,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE),
|
||||
call(['apt-mark', 'showhold', 'package2'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
check=True),
|
||||
call(['apt-mark', 'hold', 'package2'], check=False,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
]
|
||||
assert run.call_args_list == expected_calls
|
||||
assert run.mock_calls == expected_calls
|
||||
run.reset_mock()
|
||||
|
||||
expected_call = [
|
||||
|
||||
@@ -64,10 +64,10 @@ deb http://deb.debian.org/debian trixie main
|
||||
assert utils.get_sources_list_codename() == 'testing'
|
||||
|
||||
|
||||
@patch('subprocess.check_output')
|
||||
def test_get_current_release(check_output):
|
||||
@patch('subprocess.run')
|
||||
def test_get_current_release(run):
|
||||
"""Test that getting current release works."""
|
||||
check_output.return_value = b'test-release\ntest-codename\n\n'
|
||||
run.return_value.stdout = b'test-release\ntest-codename\n\n'
|
||||
assert utils.get_current_release() == ('test-release', 'test-codename')
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user