Skip to content

Commit

Permalink
fix(tests): add comments and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maugde committed Aug 30, 2024
1 parent ad9969e commit e27b723
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/antares_web_installer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions tests/integration/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down
6 changes: 5 additions & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import hashlib
from pathlib import Path

import pytest

from antares_web_installer.app import App, EXCLUDED_FILES


Expand All @@ -13,14 +16,15 @@ 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.
"""
# Prepare the test resources
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"]
Expand Down

0 comments on commit e27b723

Please sign in to comment.