-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import hashlib | ||
from pathlib import Path | ||
|
||
from _pytest.monkeypatch import MonkeyPatch | ||
|
||
from antares_web_installer.app import App, EXCLUDED_FILES | ||
|
||
|
||
class TestApp: | ||
def test_run(self) -> None: | ||
pass | ||
|
||
def test_kill_running_server(self) -> None: | ||
# 1. Lancer un serveur | ||
# 2. Appeler la méthode kill_running_server | ||
# 3. Vérifier que le serveur a bien été tué | ||
pass | ||
|
||
def test_install_files__from_scratch(self, tmp_path: Path) -> 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" | ||
|
||
# Say we have dummy files in the source directory | ||
expected_files = ["dummy.txt", "folder/dummy2.txt"] | ||
for name in expected_files: | ||
dummy_file = source_dir / name | ||
dummy_file.parent.mkdir(parents=True, exist_ok=True) | ||
dummy_file.touch() | ||
|
||
# Run the test | ||
app = App(source_dir=source_dir, target_dir=target_dir) | ||
app.install_files() | ||
|
||
# Check the results | ||
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") | ||
target_dir = datadir.joinpath("copy_files/target_files") | ||
|
||
# collect the checksum of all files in the target directory | ||
old_checksum_by_name = {} | ||
for file in target_dir.rglob("*.*"): | ||
content = file.read_bytes() | ||
old_checksum_by_name[file.relative_to(target_dir)] = hashlib.md5(content).hexdigest() | ||
|
||
# Run the test | ||
app = App(source_dir=source_dir, target_dir=target_dir) | ||
app.copy_files() | ||
|
||
# Check the results | ||
for file in target_dir.rglob("*.*"): | ||
relative_path = file.relative_to(target_dir) | ||
content = file.read_bytes() | ||
old_checksum = old_checksum_by_name[relative_path] | ||
new_checksum = hashlib.md5(content).hexdigest() | ||
root_name = relative_path.parts[0] | ||
if root_name in EXCLUDED_FILES: | ||
assert old_checksum == new_checksum, f"File {file} must not have been modified" | ||
else: | ||
assert old_checksum != new_checksum, f"File {file} must have been updated" | ||
|
||
def test_check_version(self, tmp_path: Path) -> None: | ||
# 3 cas à tester : | ||
# 1. Le programme exécutable n'existe pas => InstallError | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This directory contains the resources for the `test_app` test. | ||
|
||
This directory contains one folder for each test case: | ||
|
||
- `install_files`: Contains the files that are used for source_dir and target_dir | ||
... |
1 change: 1 addition & 0 deletions
1
tests/test_app/copy_files/source_files/AntaresWeb/AntaresWebServer.exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dummy Antares Web Server v2.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy: source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy: source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
source |
1 change: 1 addition & 0 deletions
1
tests/test_app/copy_files/target_files/AntaresWeb/AntaresWebServer.exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dummy Antares Web Server v2.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy: target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy: target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
security: | ||
disabled: false | ||
jwt: | ||
key: super-secret | ||
login: | ||
admin: | ||
pwd: admin | ||
|
||
db: | ||
url: "sqlite:////home/john/antares_data/database.db" | ||
|
||
storage: | ||
tmp_dir: /tmp | ||
matrixstore: /home/john/antares_data/matrices | ||
archive_dir: /home/john/antares_data/archives | ||
allow_deletion: false | ||
workspaces: | ||
default: | ||
path: /home/john/antares_data/internal_studies/ | ||
studies: | ||
path: /home/john/antares_data/studies/ | ||
|
||
launcher: | ||
default: slurm | ||
local: | ||
binaries: | ||
850: /home/john/opt/antares-8.5.0-Ubuntu-20.04/antares-solver | ||
860: /home/john/opt/antares-8.6.0-Ubuntu-20.04/antares-8.6-solver | ||
enable_nb_cores_detection: True | ||
|
||
slurm: | ||
local_workspace: /home/john/antares_data/slurm_workspace | ||
|
||
username: antares | ||
hostname: slurm-prod-01 | ||
|
||
port: 22 | ||
private_key_file: /home/john/.ssh/id_rsa | ||
key_password: | ||
default_wait_time: 900 | ||
default_time_limit: 172800 | ||
enable_nb_cores_detection: False | ||
nb_cores: | ||
min: 1 | ||
default: 20 | ||
max: 24 | ||
default_json_db_name: launcher_db.json | ||
slurm_script_path: /applis/antares/launchAntares.sh | ||
db_primary_key: name | ||
antares_versions_on_remote_server: | ||
- '850' # 8.5.1/antares-8.5-solver | ||
- '860' # 8.6.2/antares-8.6-solver | ||
- '870' # 8.7.0/antares-8.7-solver | ||
|
||
debug: false | ||
|
||
root_path: "" | ||
|
||
server: | ||
worker_threadpool_size: 12 | ||
services: | ||
- watcher | ||
- matrix_gc | ||
|
||
logging: | ||
level: INFO |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
security: | ||
disabled: false | ||
jwt: | ||
key: super-secret | ||
login: | ||
admin: | ||
pwd: admin | ||
|
||
db: | ||
url: "sqlite:////home/john/antares_data/database.db" | ||
|
||
storage: | ||
tmp_dir: /tmp | ||
matrixstore: /home/john/antares_data/matrices | ||
archive_dir: /home/john/antares_data/archives | ||
allow_deletion: false | ||
workspaces: | ||
default: | ||
path: /home/john/antares_data/internal_studies/ | ||
studies: | ||
path: /home/john/antares_data/studies/ | ||
|
||
launcher: | ||
default: slurm | ||
local: | ||
binaries: | ||
850: /home/john/opt/antares-8.5.0-Ubuntu-20.04/antares-solver | ||
860: /home/john/opt/antares-8.6.0-Ubuntu-20.04/antares-8.6-solver | ||
|
||
slurm: | ||
local_workspace: /home/john/antares_data/slurm_workspace | ||
|
||
username: antares | ||
hostname: slurm-prod-01 | ||
|
||
port: 22 | ||
private_key_file: /home/john/.ssh/id_rsa | ||
key_password: | ||
default_wait_time: 900 | ||
default_time_limit: 172800 | ||
default_n_cpu: 12 | ||
default_json_db_name: launcher_db.json | ||
slurm_script_path: /applis/antares/launchAntares.sh | ||
db_primary_key: name | ||
antares_versions_on_remote_server: | ||
- '850' # 8.5.1/antares-8.5-solver | ||
- '860' # 8.6.2/antares-8.6-solver | ||
- '870' # 8.7.0/antares-8.7-solver | ||
|
||
debug: false | ||
|
||
root_path: "" | ||
|
||
server: | ||
worker_threadpool_size: 12 | ||
services: | ||
- watcher | ||
- matrix_gc | ||
|
||
logging: | ||
level: INFO |