left4me/l4d2web/tests/test_workshop_paths.py
mwiegand f0230e17d3
feat(l4d2-web): overlay path helpers and creation
Adds workshop_paths.cache_path(steam_id) returning
$LEFT4ME_ROOT/workshop_cache/{steam_id}.vpk with digit-only validation.

Adds overlay_creation.generate_overlay_path(id) and
create_overlay_directory(overlay) with exist_ok=False so a stray dir from a
prior failed delete surfaces loudly instead of shadowing fresh content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 16:38:39 +02:00

23 lines
901 B
Python

"""Tests for workshop_paths cache-resolution helpers."""
from pathlib import Path
import pytest
from l4d2web.services import workshop_paths
def test_workshop_cache_root_uses_left4me_root(monkeypatch, tmp_path: Path) -> None:
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
assert workshop_paths.workshop_cache_root() == tmp_path / "workshop_cache"
def test_cache_path_returns_id_only_filename(monkeypatch, tmp_path: Path) -> None:
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
assert workshop_paths.cache_path("12345") == tmp_path / "workshop_cache" / "12345.vpk"
@pytest.mark.parametrize("bad", ["abc", "", "12/34", "..", "../etc", "1 2", " 1"])
def test_cache_path_rejects_non_digit_steam_id(monkeypatch, tmp_path: Path, bad: str) -> None:
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
with pytest.raises(ValueError):
workshop_paths.cache_path(bad)