4cb319b393
slugify() produces ASCII-only lowercase slugs from arbitrary text (used for artist slugs and tag slugs). paths.derive_subdir/derive_top_level_artist extract the destination layout and folder→artist convention from an import source path. hash_suffixed_name builds IR-style 'stem__hash10.ext' filenames. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
from backend.app.utils.paths import (
|
|
derive_subdir,
|
|
derive_top_level_artist,
|
|
hash_suffixed_name,
|
|
)
|
|
|
|
|
|
IMPORT = Path("/import")
|
|
|
|
|
|
def test_derive_subdir_nested():
|
|
assert derive_subdir(Path("/import/Alice/sub/x.png"), IMPORT) == "Alice/sub"
|
|
|
|
|
|
def test_derive_subdir_one_level():
|
|
assert derive_subdir(Path("/import/Alice/x.png"), IMPORT) == "Alice"
|
|
|
|
|
|
def test_derive_subdir_root():
|
|
assert derive_subdir(Path("/import/x.png"), IMPORT) == ""
|
|
|
|
|
|
def test_derive_subdir_outside_root():
|
|
assert derive_subdir(Path("/elsewhere/x.png"), IMPORT) == ""
|
|
|
|
|
|
def test_hash_suffixed_name():
|
|
h = "abcdef1234567890" + "0" * 48
|
|
assert hash_suffixed_name("photo", h, ".png") == "photo__abcdef1234.png"
|
|
|
|
|
|
def test_derive_top_level_artist_present():
|
|
assert derive_top_level_artist(Path("/import/Alice/x.png"), IMPORT) == "Alice"
|
|
|
|
|
|
def test_derive_top_level_artist_nested():
|
|
assert derive_top_level_artist(Path("/import/Alice/sub/x.png"), IMPORT) == "Alice"
|
|
|
|
|
|
def test_derive_top_level_artist_root():
|
|
assert derive_top_level_artist(Path("/import/x.png"), IMPORT) is None
|