From e334bb7d6f3b3c9abb86944d87ec53d9cef643bf Mon Sep 17 00:00:00 2001 From: Maurane GLAUDE Date: Thu, 29 Aug 2024 17:05:03 +0200 Subject: [PATCH] fix(tests.integration): fix dependency missing --- pyproject.toml | 5 +++- src/antares_web_installer/gui/controller.py | 3 +-- tests/integration/conftest.py | 8 ++++-- tests/integration/server_mock/server.py | 3 +-- tests/integration/test_app.py | 18 +++---------- tests/test_app.py | 28 --------------------- 6 files changed, 15 insertions(+), 50 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 10814d0..e782ac8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ dependencies = [ 'pywin32<=306; sys_platform == "win32"', 'httpx<0.28', 'platformdirs<=4.2.2', + 'uvicorn', ] [project.urls] @@ -52,10 +53,12 @@ dependencies = [ "fastapi", "pyinstaller", "httpx==0.27.0", + "requests", "platformdirs==4.2.2", + "uvicorn", ] [tool.hatch.envs.default.scripts] -test = "pytest {args:tests}" +test = "pytest {args:tests} --basetemp=target" test-cov = "coverage run -m pytest {args:tests}" cov-report = [ "- coverage combine", diff --git a/src/antares_web_installer/gui/controller.py b/src/antares_web_installer/gui/controller.py index bab0d4e..f038c13 100644 --- a/src/antares_web_installer/gui/controller.py +++ b/src/antares_web_installer/gui/controller.py @@ -17,8 +17,7 @@ class InstallationThread(Thread): - def __init__(self, group=None, target=None, name=None, - args=(), kwargs=None, *, daemon=None): + def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None): super().__init__(group, target, name, args, kwargs, daemon=daemon) def run(self): diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 6663ad1..068a029 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,4 +1,6 @@ import os +from typing import List + import pytest from pathlib import Path @@ -9,15 +11,17 @@ @pytest.fixture(name="antares_web_server_paths", scope="session", autouse=True) -def antares_web_server_paths_fixture(tmp_path_factory: pytest.TempPathFactory) -> [Path]: +def antares_web_server_paths_fixture(tmp_path_factory: pytest.TempPathFactory) -> List[Path]: """Fixture used to build both the Antares web server version (2.14.4 and 2.15.2).""" target_dir = tmp_path_factory.mktemp("servers", numbered=False) apps = [] for version in ["2.14.4", "2.15.2"]: import tests.integration.server_mock.server as server + server.__dict__["version"] = version - version_target_dir = target_dir.joinpath("AntaresWeb-"+version) + version_target_dir = target_dir.joinpath("AntaresWeb-" + version) apps.append(build(version_target_dir, exe_name=EXE_NAME)) + print("servers built: {}".format(apps)) return apps diff --git a/tests/integration/server_mock/server.py b/tests/integration/server_mock/server.py index f1aac4c..8683b59 100644 --- a/tests/integration/server_mock/server.py +++ b/tests/integration/server_mock/server.py @@ -5,10 +5,9 @@ This server will only run 10 seconds, so it is not suitable for long tests. """ -import argparse +import argparse import uvicorn - from tests.integration.server_mock.web import app # Define the server configuration diff --git a/tests/integration/test_app.py b/tests/integration/test_app.py index a696e5f..fda8f71 100644 --- a/tests/integration/test_app.py +++ b/tests/integration/test_app.py @@ -66,12 +66,8 @@ 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: None) -> None: """ The goal of this test is to verify the behavior of the application when: - The Antares server is not running @@ -88,13 +84,7 @@ def test_run__empty_target( 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: None): for application_dir in downloaded_dir.iterdir(): # Run the application app = App(source_dir=application_dir, target_dir=program_dir, shortcut=True, launch=True) @@ -116,5 +106,3 @@ def test_shortcut__not_created(self): @return: """ pass - - diff --git a/tests/test_app.py b/tests/test_app.py index 24c20a6..1260cf9 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,8 +1,5 @@ import hashlib from pathlib import Path - -from _pytest.monkeypatch import MonkeyPatch - from antares_web_installer.app import App, EXCLUDED_FILES @@ -40,25 +37,6 @@ def test_install_files__from_scratch(self, tmp_path: Path) -> None: for name in expected_files: assert (target_dir / name).exists(), f"File {name} must be copied" - def test_install_files__update_config(self, datadir: Path, monkeypatch: MonkeyPatch) -> None: - # Replace the original `check_version` method with a mock - monkeypatch.setattr(App, "check_version", lambda _: "2.14") - - # Prepare the test resources - source_dir = datadir.joinpath("install_files/source_files") - target_dir = datadir.joinpath("install_files/target_files") - old_config = (target_dir / "config.yaml").read_text() - - app = App(source_dir=source_dir, target_dir=target_dir) - app.install_files() - - # Check that `dummy.txt` has been copied - assert (target_dir / "dummy.txt").exists() - - # Check that the config file has been updated - new_config = (target_dir / "config.yaml").read_text() - assert old_config != new_config - def test_copy_files__nominal_case(self, datadir: Path) -> None: # Prepare the test resources source_dir = datadir.joinpath("copy_files/source_files") @@ -92,9 +70,3 @@ def test_check_version(self, tmp_path: Path) -> None: # 2. Le programme exécutable existe, mais le programme plante => InstallError # 3. Le programme exécutable existe et fonctionne => pas d'erreur pass - - def test_create_icons(self) -> None: - pass - - def test_start_server(self) -> None: - pass