diff --git a/src/antares_web_installer/app.py b/src/antares_web_installer/app.py index 05f6289..9d74488 100644 --- a/src/antares_web_installer/app.py +++ b/src/antares_web_installer/app.py @@ -222,8 +222,8 @@ def create_shortcuts(self): desktop_path = Path(get_desktop()) logger.info("Generating server shortcut on desktop...") - shortcut_name, shortcut_ext = SHORTCUT_NAMES[os.name].split('.') - new_shortcut_name = f"{shortcut_name}-{self.version}.{shortcut_ext}" + name, ext = SHORTCUT_NAMES[os.name].split('.') + new_shortcut_name = f"{name}-{self.version}.{ext}" shortcut_path = desktop_path.joinpath(new_shortcut_name) # if the shortcut already exists, remove it diff --git a/tests/integration/test_app.py b/tests/integration/test_app.py index fda8f71..6d4c184 100644 --- a/tests/integration/test_app.py +++ b/tests/integration/test_app.py @@ -2,10 +2,12 @@ import shutil from difflib import SequenceMatcher from pathlib import Path +from typing import Any import psutil import pytest from _pytest.monkeypatch import MonkeyPatch +import re from antares_web_installer.app import App from tests.samples import SAMPLES_DIR @@ -67,7 +69,7 @@ class TestApp: Integration tests for the app """ - def test_run__empty_target(self, downloaded_dir: Path, program_dir: Path, settings: None) -> None: + def test_run__empty_target(self, downloaded_dir: Path, program_dir: Path, settings: Any) -> None: """ The goal of this test is to verify the behavior of the application when: - The Antares server is not running @@ -84,18 +86,24 @@ def test_run__empty_target(self, downloaded_dir: Path, program_dir: Path, settin app = App(source_dir=application_dir, target_dir=program_dir, shortcut=True, launch=True) app.run() - def test_shortcut__created(self, downloaded_dir: Path, program_dir: Path, desktop_dir: Path, settings: None): + def test_shortcut__created(self, downloaded_dir: Path, program_dir: Path, desktop_dir: Path, settings: Any): for application_dir in downloaded_dir.iterdir(): # Run the application app = App(source_dir=application_dir, target_dir=program_dir, shortcut=True, launch=True) app.run() - desktop_files = [file_name.name for file_name in list(desktop_dir.iterdir())] - - if os.name != "nt": - assert "AntaresWebServer.desktop" in desktop_files - else: - assert "Antares Web Server.lnk" in desktop_files + match = 0 + + for file in list(desktop_dir.iterdir()): + if os.name == "nt": + pattern = re.compile(r"AntaresWebServer-([0-9]*\.){3}lnk") + if pattern.fullmatch(file.name): + match += 1 + else: + pattern = re.compile(r"AntaresWebServer-([0-9]*\.){3}desktop") + if pattern.fullmatch(file.name): + match += 1 + assert match == 1 def test_shortcut__not_created(self): """ diff --git a/tests/test_app.py b/tests/test_app.py index 1260cf9..3017eb3 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,5 +1,8 @@ import hashlib from pathlib import Path + +import pytest + from antares_web_installer.app import App, EXCLUDED_FILES @@ -13,7 +16,7 @@ def test_kill_running_server(self) -> None: # 3. Vérifier que le serveur a bien été tué pass - def test_install_files__from_scratch(self, tmp_path: Path) -> None: + def test_install_files__from_scratch(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: """ Case where the target directory does not exist. """ @@ -21,6 +24,7 @@ def test_install_files__from_scratch(self, tmp_path: Path) -> None: source_dir = tmp_path / "source" source_dir.mkdir() target_dir = tmp_path / "target" + monkeypatch.setattr("antares_web_installer.app.App.check_version", lambda _: "2.17.0") # Say we have dummy files in the source directory expected_files = ["dummy.txt", "folder/dummy2.txt"]