refactor(media): Vereinsflache Ablage; private als u{profile} unter Verein

- club: library/club/c{id}/{sha} (kein shared/)
- private: library/club/c{id}/u{profile}/{sha} statt …/private/
- Dedupe private: sha + club_id + uploaded_by_profile_id
- version 0.8.54

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-05-08 10:00:37 +02:00
1 parent 3f0d02edab
commit 8d85649cf8
6 files changed
+103 -39

No files matched your search

+21 -10
View File
@@ -8,25 +8,36 @@ from media_storage import library_storage_key
_HEX64 = "a" * 64
def test_library_storage_key_private_under_club() -> None:
assert library_storage_key("private", 7, _HEX64, ".jpg") == f"library/club/c7/private/{_HEX64}.jpg"
def test_library_storage_key_private_is_uploader_under_club() -> None:
assert (
library_storage_key("private", 7, _HEX64, ".jpg", uploader_profile_id=99)
== f"library/club/c7/u99/{_HEX64}.jpg"
)
def test_library_storage_key_shared_under_club() -> None:
assert library_storage_key("club", 42, _HEX64, ".png") == f"library/club/c42/shared/{_HEX64}.png"
def test_library_storage_key_club_flat_under_club() -> None:
assert library_storage_key("club", 42, _HEX64, ".png") == f"library/club/c42/{_HEX64}.png"
def test_library_storage_key_official() -> None:
assert library_storage_key("official", None, _HEX64, ".mp4") == f"library/official/{_HEX64}.mp4"
assert (
library_storage_key("official", None, _HEX64, ".mp4", uploader_profile_id=1)
== f"library/official/{_HEX64}.mp4"
)
def test_library_storage_key_normalizes_visibility() -> None:
assert library_storage_key(" CLUB ", 1, _HEX64, "pdf") == f"library/club/c1/shared/{_HEX64}.pdf"
assert library_storage_key(" CLUB ", 1, _HEX64, "pdf") == f"library/club/c1/{_HEX64}.pdf"
def test_library_storage_key_private_requires_uploader() -> None:
with pytest.raises(ValueError, match="uploader_profile_id"):
library_storage_key("private", 1, _HEX64, ".jpg")
def test_library_storage_key_private_requires_club() -> None:
with pytest.raises(ValueError, match="Verein"):
library_storage_key("private", None, _HEX64, ".jpg")
library_storage_key("private", None, _HEX64, ".jpg", uploader_profile_id=1)
def test_library_storage_key_club_requires_id() -> None:
@@ -46,9 +57,9 @@ def test_library_storage_key_invalid_visibility() -> None:
def test_library_storage_key_invalid_sha() -> None:
with pytest.raises(ValueError, match="64"):
library_storage_key("private", 1, "deadbeef", ".jpg")
library_storage_key("private", 1, "deadbeef", ".jpg", uploader_profile_id=1)
def test_library_storage_key_extension_sanitized() -> None:
def test_library_storage_key_extension() -> None:
with pytest.raises(ValueError):
library_storage_key("private", 1, _HEX64, "../x")
library_storage_key("private", 1, _HEX64, "../x", uploader_profile_id=1)