-
-
Notifications
You must be signed in to change notification settings - Fork 5
Support historical asset payloads #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattiapearl
wants to merge
3
commits into
deadlock-api:master
Choose a base branch
from
mattiapearl:fix-historical-assets-compat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,19 @@ | ||
| import os | ||
|
|
||
| from deadlock_assets_api.models.v2.generic_data import GenericDataV2 | ||
|
|
||
|
|
||
| def backfill_historical_generic_data(out_folder: str, client_versions: list[int]) -> None: | ||
| for version_id in client_versions: | ||
| version_folder = f"{out_folder}/versions/{version_id}" | ||
| os.makedirs(version_folder, exist_ok=True) | ||
|
|
||
| generic_source = f"res/builds/{version_id}/v2/generic_data.json" | ||
| generic_target = f"{version_folder}/generic_data.json" | ||
| if not os.path.exists(generic_source) or os.path.exists(generic_target): | ||
| continue | ||
|
|
||
| with open(generic_source) as f: | ||
| generic_data = GenericDataV2.model_validate_json(f.read()) | ||
| with open(generic_target, "w") as f: | ||
| f.write(generic_data.model_dump_json(exclude_none=True)) |
This file contains hidden or 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 hidden or 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 hidden or 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,93 @@ | ||
| import importlib | ||
| import json | ||
| import sys | ||
| import types | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from fastapi import HTTPException | ||
| from pydantic import TypeAdapter | ||
|
|
||
| from deadlock_assets_api.models.v2.generic_data import GenericDataV2 | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
|
|
||
| def prepare_runtime(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.chdir(tmp_path) | ||
| deploy = tmp_path / "deploy" | ||
| deploy.mkdir() | ||
| (deploy / "client_versions.json").write_text(json.dumps([6016, 5959])) | ||
|
|
||
| css_parser = types.ModuleType("css_parser") | ||
| css_parser.parseFile = lambda *_args, **_kwargs: types.SimpleNamespace(cssRules=[]) | ||
| css_parser.parseString = lambda *_args, **_kwargs: types.SimpleNamespace(cssRules=[]) | ||
| css_module = types.ModuleType("css_parser.css") | ||
| css_module.CSSRuleList = list | ||
| css_module.CSSStyleRule = type("CSSStyleRule", (), {}) | ||
| css_module.ColorValue = type("ColorValue", (), {}) | ||
| css_module.CSSUnknownRule = type("CSSUnknownRule", (), {}) | ||
| monkeypatch.setitem(sys.modules, "css_parser", css_parser) | ||
| monkeypatch.setitem(sys.modules, "css_parser.css", css_module) | ||
| stringcase = types.ModuleType("stringcase") | ||
| stringcase.snakecase = lambda value: value | ||
| monkeypatch.setitem(sys.modules, "stringcase", stringcase) | ||
|
|
||
| for module_name in [ | ||
| "deadlock_assets_api.models.enums", | ||
| "deadlock_assets_api.utils", | ||
| ]: | ||
| sys.modules.pop(module_name, None) | ||
|
|
||
|
|
||
| def test_generic_data_model_accepts_old_minimal_snapshots() -> None: | ||
| payload = json.loads((REPO_ROOT / "res/builds/5959/v2/generic_data.json").read_text()) | ||
|
|
||
| generic_data = GenericDataV2.model_validate(payload) | ||
|
|
||
| assert generic_data.item_price_per_tier == [0, 800, 1600, 3200, 6400, 9999] | ||
| assert generic_data.lane_info is None | ||
| assert generic_data.weapon_groups is None | ||
|
|
||
|
|
||
| def test_generic_data_model_accepts_legacy_street_brawl_draft_shape() -> None: | ||
| payload = json.loads((REPO_ROOT / "res/builds/6351/v2/generic_data.json").read_text()) | ||
|
|
||
| generic_data = GenericDataV2.model_validate(payload) | ||
|
|
||
| first_round = generic_data.street_brawl.item_draft_rounds_per_game_round[0].item_draft_rounds[0] | ||
| assert first_round.normal_mod_tier.value == 2 | ||
| assert first_round.rare_mod_tier.value == 1 | ||
| assert generic_data.street_brawl.item_drafts is None | ||
|
|
||
|
|
||
| def test_missing_generated_file_returns_404_instead_of_500( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| prepare_runtime(tmp_path, monkeypatch) | ||
| utils = importlib.import_module("deadlock_assets_api.utils") | ||
|
|
||
| with pytest.raises(HTTPException) as exc_info: | ||
| utils.read_parse_data_ta( | ||
| "deploy/versions/5959/images_data.json", TypeAdapter(dict[str, str]) | ||
| ) | ||
|
|
||
| assert exc_info.value.status_code == 404 | ||
|
|
||
|
|
||
| def test_backfills_historical_generic_data(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| prepare_runtime(tmp_path, monkeypatch) | ||
| source_folder = tmp_path / "res/builds/5959/v2" | ||
| source_folder.mkdir(parents=True) | ||
| source_folder.joinpath("generic_data.json").write_text( | ||
| (REPO_ROOT / "res/builds/5959/v2/generic_data.json").read_text() | ||
| ) | ||
|
|
||
| historical = importlib.import_module("deadlock_assets_api.historical") | ||
|
|
||
| historical.backfill_historical_generic_data("deploy", [6016, 5959]) | ||
|
|
||
| generic_data = json.loads((tmp_path / "deploy/versions/5959/generic_data.json").read_text()) | ||
| assert generic_data["item_price_per_tier"] == [0, 800, 1600, 3200, 6400, 9999] | ||
| assert "lane_info" not in generic_data |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of setting default to empty dicts/list I would much rather have them be
NoneThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok