left4me/l4d2web/tests/test_overlay_creation.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

35 lines
1.3 KiB
Python

"""Tests for overlay path generation and directory creation."""
from pathlib import Path
import pytest
from l4d2web.models import Overlay
from l4d2web.services import overlay_creation
def test_generate_overlay_path_returns_str_id() -> None:
assert overlay_creation.generate_overlay_path(42) == "42"
def test_generate_overlay_path_validates_through_overlay_ref(monkeypatch) -> None:
# Sanity: numeric paths pass validate_overlay_ref. Anything bizarre would raise.
assert overlay_creation.generate_overlay_path(1) == "1"
def test_create_overlay_directory_makes_subtree(monkeypatch, tmp_path: Path) -> None:
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
overlay = Overlay(id=7, name="test", path="7", type="workshop", user_id=None)
overlay_creation.create_overlay_directory(overlay)
expected = tmp_path / "overlays" / "7"
assert expected.is_dir()
def test_create_overlay_directory_raises_if_already_exists(
monkeypatch, tmp_path: Path
) -> None:
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
overlay = Overlay(id=7, name="test", path="7", type="workshop", user_id=None)
(tmp_path / "overlays" / "7").mkdir(parents=True)
# exist_ok=False guards against a stray directory shadowing fresh content.
with pytest.raises(FileExistsError):
overlay_creation.create_overlay_directory(overlay)