50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
|
|
"""library_storage_key: Mandantenpfade unter MEDIA_ROOT."""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from media_storage import library_storage_key
|
||
|
|
|
||
|
|
_HEX64 = "a" * 64
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_private() -> None:
|
||
|
|
assert library_storage_key("private", None, _HEX64, ".jpg") == f"library/private/{_HEX64}.jpg"
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_official() -> None:
|
||
|
|
assert library_storage_key("official", None, _HEX64, ".mp4") == f"library/official/{_HEX64}.mp4"
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_club() -> None:
|
||
|
|
assert library_storage_key("club", 42, _HEX64, ".png") == f"library/club/c42/{_HEX64}.png"
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_normalizes_visibility() -> None:
|
||
|
|
assert library_storage_key(" CLUB ", 1, _HEX64, "pdf") == f"library/club/c1/{_HEX64}.pdf"
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_club_requires_id() -> None:
|
||
|
|
with pytest.raises(ValueError, match="club_id"):
|
||
|
|
library_storage_key("club", None, _HEX64, ".jpg")
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_club_id_positive() -> None:
|
||
|
|
with pytest.raises(ValueError, match="positiv"):
|
||
|
|
library_storage_key("club", 0, _HEX64, ".jpg")
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_invalid_visibility() -> None:
|
||
|
|
with pytest.raises(ValueError, match="Sichtbarkeit"):
|
||
|
|
library_storage_key("public", None, _HEX64, ".jpg")
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_invalid_sha() -> None:
|
||
|
|
with pytest.raises(ValueError, match="64"):
|
||
|
|
library_storage_key("private", None, "deadbeef", ".jpg")
|
||
|
|
|
||
|
|
|
||
|
|
def test_library_storage_key_extension_sanitized() -> None:
|
||
|
|
with pytest.raises(ValueError):
|
||
|
|
library_storage_key("private", None, _HEX64, "../x")
|