Skip to content

Commit

Permalink
tests: add more scenarii and factorize test (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Dec 29, 2023
2 parents 2b80aa0 + 9503f46 commit 7632071
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 71 deletions.
21 changes: 21 additions & 0 deletions tests/fixtures/scenarios/good_scenario_profiles_http.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a sample of a YAML file for the QGIS Deployment Toolbelt scenario.
# For now, it's more a roadmap than a real description of what it's implemented.

metadata:
title: "Tests scenario of QGIS Deployment Toolbelt"
id: test-scenario-profiles-sync-http
description: >-
This is an example a scenario YAML file for the QGIS Deployment Toolbelt to
demonstrate capabilities.
settings:
LOCAL_WORK_DIR: ~/.cache/qgis-deployment-toolbelt/tests/
SCENARIO_VALIDATION: true

steps:
- name: Synchronize QGIS profiles from remote location
uses: qprofiles-manager
with:
protocol: http
source: https://raw.githubusercontent.com/Guts/qgis-deployment-cli/examples/
sync_mode: overwrite
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# For now, it's more a roadmap than a real description of what it's implemented.

metadata:
title: "Sample scenario of QGIS Deployment Toolbelt"
id: sample-scenario-good-only-different
title: "Test scenario of QGIS Deployment Toolbelt"
id: test-scenario-profiles-sync-only_different_version
description: >-
This is an example a scenario YAML file for the QGIS Deployment Toolbelt to
demonstrate capabilities.
settings:
DEBUG: false
LOCAL_WORK_DIR: ~/.cache/qgis-deployment-toolbelt/Oslandia/
LOCAL_WORK_DIR: ~/.cache/qgis-deployment-toolbelt/tests/
QGIS_EXE_PATH:
linux: /usr/bin/qgis
mac: /usr/bin/qgis
Expand All @@ -21,7 +21,7 @@ steps:
- name: Synchronize QGIS profiles from remote location
uses: qprofiles-manager
with:
protocol: git
protocol: git_remote
branch: main
source: https://gitlab.com/charente-eaux/ocarhy/profils-qgis.git
source: https://github.com/Guts/qgis-deployment-cli.git
sync_mode: only_different_version
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# For now, it's more a roadmap than a real description of what it's implemented.

metadata:
title: "Sample scenario of QGIS Deployment Toolbelt"
id: sample-scenario-good-only-missing
title: "Tests scenario of QGIS Deployment Toolbelt"
id: test-scenario-profiles-sync-only_missing
description: >-
This is an example a scenario YAML file for the QGIS Deployment Toolbelt to
demonstrate capabilities.
settings:
DEBUG: false
LOCAL_WORK_DIR: ~/.cache/qgis-deployment-toolbelt/Oslandia/
LOCAL_WORK_DIR: ~/.cache/qgis-deployment-toolbelt/tests/
QGIS_EXE_PATH:
linux: /usr/bin/qgis
mac: /usr/bin/qgis
Expand All @@ -21,7 +21,7 @@ steps:
- name: Synchronize QGIS profiles from remote location
uses: qprofiles-manager
with:
protocol: git
protocol: git_remote
branch: main
source: https://gitlab.com/charente-eaux/ocarhy/profils-qgis.git
source: https://github.com/Guts/qgis-deployment-cli.git
sync_mode: only_missing
28 changes: 12 additions & 16 deletions tests/fixtures/scenarios/good_scenario_sample.qdt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@
# For now, it's more a roadmap than a real description of what it's implemented.

metadata:
title: "Sample scenario of QGIS Deployment Toolbelt"
id: sample-scenario-good
title: "Test scenario of QGIS Deployment Toolbelt"
id: test-basic-scenario-good
description: >-
This is an example a scenario YAML file for the QGIS Deployment Toolbelt to
demonstrate capabilities.
settings:
DEBUG: false
LOCAL_WORK_DIR: ~/.cache/qgis-deployment-toolbelt/tests/
QGIS_EXE_PATH:
linux: /usr/bin/qgis
mac: /usr/bin/qgis
windows: "%PROGRAMFILES%/QGIS/3_22/bin/qgis-bin.exe"
SCENARIO_VALIDATION: true

steps:
- name: Set environment variables
uses: manage-env-vars
with:
- name: PYQGIS_STARTUP
- name: TEST_PYQGIS_STARTUP
action: "add"
value: "~/scripts/qgis_startup.py"
scope: "user"
- name: QDT_TEST_FAKE_ENV_VAR_BOOL
- name: TEST_QDT_TEST_FAKE_ENV_VAR_BOOL
action: "add"
value: true
scope: "user"
Expand All @@ -34,8 +30,8 @@ steps:
uses: qprofiles-manager
with:
action: download
source: https://gitlab.com/charente-eaux/ocarhy/profils-qgis.git
protocol: git
source: https://github.com/Guts/qgis-deployment-cli.git
protocol: git_remote
branch: main

- name: Download plugins
Expand All @@ -49,20 +45,20 @@ steps:
with:
action: create_or_restore
profile_ref: downloaded
source: ~/.cache/qgis-deployment-toolbelt/plugins

- name: Create shortcuts for profiles
uses: shortcuts-manager
with:
action: create_or_restore
include:
- profile: oslandia
label: "QGIS - Profil Oslandia"
additional_arguments: "--noversioncheck"
- profile: qdt_demo
label: "TEST QDT - Demo profile"
desktop: true
start_menu: true
- profile: QDT Viewer Mode
label: "TEST QDT - Viewer profile"
desktop: true
start_menu: true
icon: "qgis_icon_oslandia.ico"
qgis_path: "%PROGRAMFILES%\\QGIS\\3_22\\bin\\qgis-bin.exe"

- name: Set splash screen
uses: splash-screen-manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

metadata:
title: "Test scenario removing splash screens"
id: sample-scenario-good-splash-removal
id: test-scenario-good-splash-removal
description: >-
Test scenario with splash screen removing
Expand All @@ -21,8 +21,8 @@ steps:
uses: qprofiles-manager
with:
action: download
source: https://gitlab.com/charente-eaux/ocarhy/profils-qgis.git
protocol: git
source: https://github.com/Guts/qgis-deployment-cli.git
protocol: git_remote
branch: main

- name: Download plugins
Expand All @@ -43,13 +43,14 @@ steps:
with:
action: create_or_restore
include:
- profile: oslandia
label: "QGIS - Profil Oslandia"
additional_arguments: "--noversioncheck"
- profile: qdt_demo
label: "TEST QDT - Demo profile"
desktop: true
start_menu: true
- profile: QDT Viewer Mode
label: "TEST QDT - Viewer profile"
desktop: true
start_menu: true
icon: "qgis_icon_oslandia.ico"
qgis_path: "%PROGRAMFILES%\\QGIS\\3_22\\bin\\qgis-bin.exe"

- name: Set splash screen
uses: splash-screen-manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# For now, it's more a roadmap than a real description of what it's implemented.

metadata:
title: "Sample scenario of QGIS Deployment Toolbelt"
id: sample-scenario-good
title: "Test scenario containing unexisting jobs"
id: test-scenario-good-unexisting-jobs
description: >-
This is an example a scenario YAML file for the QGIS Deployment Toolbelt to
demonstrate capabilities.
Expand Down Expand Up @@ -34,8 +34,8 @@ steps:
uses: qprofiles-manager
with:
action: download
source: https://gitlab.com/charente-eaux/ocarhy/profils-qgis.git
protocol: git
source: https://github.com/Guts/qgis-deployment-cli.git
protocol: git_remote
branch: main

- name: Download plugins
Expand All @@ -56,13 +56,14 @@ steps:
with:
action: create_or_restore
include:
- profile: oslandia
label: "QGIS - Profil Oslandia"
additional_arguments: "--noversioncheck"
- profile: qdt_demo
label: "TEST QDT - Demo profile"
desktop: true
start_menu: true
- profile: QDT Viewer Mode
label: "TEST QDT - Viewer profile"
desktop: true
start_menu: true
icon: "qgis_icon_oslandia.ico"
qgis_path: "%PROGRAMFILES%\\QGIS\\3_22\\bin\\qgis-bin.exe"

- name: Set splash screen
uses: splash-screen-manager
Expand Down
74 changes: 46 additions & 28 deletions tests/test_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@
sample_scenario_good: Path = Path(
"tests/fixtures/scenarios/good_scenario_sample.qdt.yml"
)
sample_scenario_good_with_unexisting_jobs: Path = Path(
"tests/fixtures/scenarios/good_scenario_with_unexisting_jobs.qdt.yml"
)
sample_scenario_good_splash_removal: Path = Path(
"tests/fixtures/scenarios/good_scenario_splash_screen_remove.qdt.yml"
)

sample_scenario_false: Path = Path(
"tests/fixtures/scenarios/false_scenario_sample.qdt.yml"
)
sample_scenario_imaginary: Path = Path(
"tests/fixtures/scenarios/imaginary_scenario_sample.qdt.yml"
)

good_scenarios = [
["deploy", f"--scenario={scenario_path.resolve()}"]
for scenario_path in Path("tests/fixtures/scenarios/").glob("good_*.qdt.yml")
]

# #############################################################################
# ######## Classes #################
# ##################################
Expand Down Expand Up @@ -66,42 +78,48 @@ def test_cli_version(capsys, option):
assert err == ""


def test_main_run(capsys):
@pytest.mark.parametrize("option", good_scenarios)
def test_main_run(capsys, option):
"""Test main cli command"""
# runner = CliRunner()
# result = runner.invoke(
# qgis_deployment_toolbelt,
# [],
# )
# assert result.exit_code == 0

# result = runner.invoke(
# qgis_deployment_toolbelt,
# [f"--scenario={str(sample_scenario_imaginary.resolve())}"],
# )
# assert result.exit_code == 1
with pytest.raises(SystemExit):
cli.main(option)

out, err = capsys.readouterr()
assert err == ""


def test_main_run_unexising_jobs(capsys):
"""Test main cli command"""
with pytest.raises(SystemExit):
cli.main(["deploy", f"--scenario={str(sample_scenario_good.resolve())}"])
cli.main(
[
"deploy",
f"--scenario={str(sample_scenario_good_with_unexisting_jobs.resolve())}",
]
)

out, err = capsys.readouterr()
assert err == ""


# def test_main_run_with_disable_validation_option():
# """Test main cli command with the disable validation option"""
# runner = CliRunner()
# result = runner.invoke(
# qgis_deployment_toolbelt,
# [f"--scenario={str(sample_scenario_good.resolve())}", "--disable-validation"],
# )
# assert result.exit_code == 0

# result = runner.invoke(
# qgis_deployment_toolbelt,
# [f"--scenario={str(sample_scenario_false.resolve())}", "--disable-validation"],
# )
# assert result.exit_code == 1
def test_main_run_failed(capsys):
"""Test main cli command"""
with pytest.raises(FileExistsError):
cli.main(["deploy", f"--scenario={str(sample_scenario_false.resolve())}"])

out, err = capsys.readouterr()
assert err == ""


def test_main_run_removing_splash(capsys):
"""Test main cli command"""
with pytest.raises(SystemExit):
cli.main(
["deploy", f"--scenario={sample_scenario_good_splash_removal.resolve()}"]
)

out, err = capsys.readouterr()
assert err == ""


# #############################################################################
Expand Down

0 comments on commit 7632071

Please sign in to comment.