diff --git a/majordome/local_files.py b/majordome/local_files.py index d9304ce..bb339cc 100644 --- a/majordome/local_files.py +++ b/majordome/local_files.py @@ -1,3 +1,4 @@ +import subprocess from pathlib import Path @@ -15,3 +16,11 @@ def set_execution_rights(file: Path): def save_and_make_executable(destination: Path, content: bytes): save(destination, content) set_execution_rights(destination) + + +def install_package(file: Path) -> None: + subprocess.Popen(("apt", "install", "-f", str(file))) + + +def run(file: Path) -> None: + subprocess.Popen((str(file))) diff --git a/tests/local_files_test.py b/tests/local_files_test.py index da54214..634a587 100644 --- a/tests/local_files_test.py +++ b/tests/local_files_test.py @@ -1,3 +1,4 @@ +import subprocess from pathlib import Path from majordome import local_files @@ -49,3 +50,26 @@ def test_download_and_make_executable(clean_tmpdir): assert tmp_file.read_bytes() == file_content assert tmp_file.stat().st_mode == 0o100775 + + +def test_install_package(): + file = Path("/home/stan/Téléchargements/freetube_0.23.2_amd64.deb") + + local_files.install_package(file) + + apt = subprocess.Popen(("apt", "list", "--installed"), stdout=subprocess.PIPE) + output = subprocess.check_output(("grep", "freetube"), stdin=apt.stdout) + apt.wait() + assert "0.23.2" in output.decode("utf-8") + + +def test_run(): + file = Path("/home/stan/Logiciels/Nextcloud-3.14.2-x86_64.AppImage") + + local_files.run(file) + + ps = subprocess.Popen(("ps", "-ef"), stdout=subprocess.PIPE) + output = subprocess.check_output(("grep", str(file)), stdin=ps.stdout) + ps.wait() + assert output is not None + assert str(file) in output.decode("utf-8") diff --git a/tests/main_test.py b/tests/main_test.py index 8ad8da8..c29584f 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -3,10 +3,17 @@ from pathlib import Path from majordome import main -def test_download_and_save_latest_asset(freetube_url, freetube_amd64_deb_mnemonic): +def test_download_and_save_latest_asset( + freetube_url, freetube_amd64_deb_mnemonic, freetube_tag_name_mnemonic +): destination = Path(__file__).parent / "tmp" - main.download_latest(freetube_url, freetube_amd64_deb_mnemonic, destination) + main.download_latest( + freetube_url, + freetube_amd64_deb_mnemonic, + freetube_tag_name_mnemonic, + destination, + ) files = list(destination.glob("*")) assert len(files) == 1