From ec8f6a3d363896c3a6e2618c82757498bc43a064 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Fri, 10 Jul 2026 17:09:49 +0900 Subject: [PATCH] chore: add config tests --- .../fixtures/api/client_allows_downloads.vdf | 13 ++++ .../api/client_disallows_downloads.vdf | 13 ++++ .../api/steamapps/appmanifest_111.acf | 53 ++++++++++++++++ .../api/steamapps/appmanifest_222.acf | 53 ++++++++++++++++ .../api/steamapps/appmanifest_333.acf | 53 ++++++++++++++++ tests/test_app_download_settings.py | 62 +++++++++++++++++++ 6 files changed, 247 insertions(+) create mode 100644 tests/fixtures/api/client_allows_downloads.vdf create mode 100644 tests/fixtures/api/client_disallows_downloads.vdf create mode 100644 tests/fixtures/api/steamapps/appmanifest_111.acf create mode 100644 tests/fixtures/api/steamapps/appmanifest_222.acf create mode 100644 tests/fixtures/api/steamapps/appmanifest_333.acf create mode 100644 tests/test_app_download_settings.py diff --git a/tests/fixtures/api/client_allows_downloads.vdf b/tests/fixtures/api/client_allows_downloads.vdf new file mode 100644 index 0000000..5660c44 --- /dev/null +++ b/tests/fixtures/api/client_allows_downloads.vdf @@ -0,0 +1,13 @@ +"InstallConfigStore" +{ + "Software" + { + "Valve" + { + "Steam" + { + "AllowDownloadsDuringGameplay" "1" + } + } + } +} diff --git a/tests/fixtures/api/client_disallows_downloads.vdf b/tests/fixtures/api/client_disallows_downloads.vdf new file mode 100644 index 0000000..4c0d409 --- /dev/null +++ b/tests/fixtures/api/client_disallows_downloads.vdf @@ -0,0 +1,13 @@ +"InstallConfigStore" +{ + "Software" + { + "Valve" + { + "Steam" + { + "AllowDownloadsDuringGameplay" "0" + } + } + } +} diff --git a/tests/fixtures/api/steamapps/appmanifest_111.acf b/tests/fixtures/api/steamapps/appmanifest_111.acf new file mode 100644 index 0000000..4b27b4d --- /dev/null +++ b/tests/fixtures/api/steamapps/appmanifest_111.acf @@ -0,0 +1,53 @@ +"AppState" +{ + "appid" "111" + "Universe" "1" + "name" "TEST APP" + "StateFlags" "4" + "installdir" "TESTAPP" + "LastUpdated" "0" + "LastPlayed" "0" + "SizeOnDisk" "0" + "StagingSize" "0" + "buildid" "0" + "LastOwner" "0" + "DownloadType" "2" + "UpdateResult" "0" + "BytesToDownload" "0" + "BytesDownloaded" "0" + "BytesToStage" "0" + "BytesStaged" "0" + "TargetBuildID" "0" + "AutoUpdateBehavior" "0" + "AllowOtherDownloadsWhileRunning" "1" + "ScheduledAutoUpdate" "0" + "FullValidateAfterNextUpdate" "1" + "InstalledDepots" + { + "1110" + { + "manifest" "0" + "size" "0" + } + } + "SharedDepots" + { + "228983" "228980" + "228985" "228980" + "228988" "228980" + "228990" "228980" + "229004" "228980" + } + "UserConfig" + { + "language" "english" + "platform_override_dest" "linux" + "platform_override_source" "windows" + } + "MountedConfig" + { + "language" "english" + "platform_override_dest" "linux" + "platform_override_source" "windows" + } +} diff --git a/tests/fixtures/api/steamapps/appmanifest_222.acf b/tests/fixtures/api/steamapps/appmanifest_222.acf new file mode 100644 index 0000000..600d369 --- /dev/null +++ b/tests/fixtures/api/steamapps/appmanifest_222.acf @@ -0,0 +1,53 @@ +"AppState" +{ + "appid" "222" + "Universe" "1" + "name" "TEST APP" + "StateFlags" "4" + "installdir" "TESTAPP" + "LastUpdated" "0" + "LastPlayed" "0" + "SizeOnDisk" "0" + "StagingSize" "0" + "buildid" "0" + "LastOwner" "0" + "DownloadType" "2" + "UpdateResult" "0" + "BytesToDownload" "0" + "BytesDownloaded" "0" + "BytesToStage" "0" + "BytesStaged" "0" + "TargetBuildID" "0" + "AutoUpdateBehavior" "0" + "AllowOtherDownloadsWhileRunning" "2" + "ScheduledAutoUpdate" "0" + "FullValidateAfterNextUpdate" "1" + "InstalledDepots" + { + "2220" + { + "manifest" "0" + "size" "0" + } + } + "SharedDepots" + { + "228983" "228980" + "228985" "228980" + "228988" "228980" + "228990" "228980" + "229004" "228980" + } + "UserConfig" + { + "language" "english" + "platform_override_dest" "linux" + "platform_override_source" "windows" + } + "MountedConfig" + { + "language" "english" + "platform_override_dest" "linux" + "platform_override_source" "windows" + } +} diff --git a/tests/fixtures/api/steamapps/appmanifest_333.acf b/tests/fixtures/api/steamapps/appmanifest_333.acf new file mode 100644 index 0000000..80f6de8 --- /dev/null +++ b/tests/fixtures/api/steamapps/appmanifest_333.acf @@ -0,0 +1,53 @@ +"AppState" +{ + "appid" "333" + "Universe" "1" + "name" "TEST APP" + "StateFlags" "4" + "installdir" "TESTAPP" + "LastUpdated" "0" + "LastPlayed" "0" + "SizeOnDisk" "0" + "StagingSize" "0" + "buildid" "0" + "LastOwner" "0" + "DownloadType" "2" + "UpdateResult" "0" + "BytesToDownload" "0" + "BytesDownloaded" "0" + "BytesToStage" "0" + "BytesStaged" "0" + "TargetBuildID" "0" + "AutoUpdateBehavior" "0" + "AllowOtherDownloadsWhileRunning" "0" + "ScheduledAutoUpdate" "0" + "FullValidateAfterNextUpdate" "1" + "InstalledDepots" + { + "3330" + { + "manifest" "0" + "size" "0" + } + } + "SharedDepots" + { + "228983" "228980" + "228985" "228980" + "228988" "228980" + "228990" "228980" + "229004" "228980" + } + "UserConfig" + { + "language" "english" + "platform_override_dest" "linux" + "platform_override_source" "windows" + } + "MountedConfig" + { + "language" "english" + "platform_override_dest" "linux" + "platform_override_source" "windows" + } +} diff --git a/tests/test_app_download_settings.py b/tests/test_app_download_settings.py new file mode 100644 index 0000000..caaec6d --- /dev/null +++ b/tests/test_app_download_settings.py @@ -0,0 +1,62 @@ +import pytest +import tempfile + +from _pytest.monkeypatch import MonkeyPatch +from pathlib import Path + +from dzgui.api.acf import ACF +from dzgui.api.steam import get_app_allows_downloads +from tests.fixtures import fixture_path + +pytestmark = pytest.mark.apitest + + +def mock_path(p: Path, appid: int) -> Path: + return Path(fixture_path("api")) + + +def mock_config_allows(p: Path) -> Path: + return Path(fixture_path("api/client_allows_downloads.vdf")) + + +def mock_config_disallows(p: Path) -> Path: + return Path(fixture_path("api/client_disallows_downloads.vdf")) + + +def mock_config_missing(p: Path) -> Path: + return Path(fixture_path("")) + + +@pytest.fixture +def client_allows() -> Path: + return Path(fixture_path("api/client_allows_downloads.vdf")) + + +@pytest.fixture +def steam_path() -> Path: + return Path(fixture_path("api")) + + +@pytest.fixture(scope="module", autouse=True) +def patch_api() -> None: + mp = MonkeyPatch() + mp.setattr("dzgui.api.steam.get_app_path", mock_path) + yield + mp.undo() + + +def test_app_allows_downloads(steam_path) -> None: + assert get_app_allows_downloads(steam_path, 111) is True + + +def test_app_disallows_downloads(steam_path): + assert get_app_allows_downloads(steam_path, 222) is False + + +def test_app_delegates_downloads(monkeypatch, steam_path, client_allows): + monkeypatch.setattr("dzgui.api.steam.get_config", mock_config_disallows) + assert get_app_allows_downloads(steam_path, 333) is False + monkeypatch.setattr("dzgui.api.steam.get_config", mock_config_allows) + assert get_app_allows_downloads(steam_path, 333) is True + monkeypatch.setattr("dzgui.api.steam.get_config", mock_config_missing) + assert get_app_allows_downloads(steam_path, 333) is True