54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
#!/usr/bin/env -S uv run --script
|
|
# /// script
|
|
# dependencies = ["pytest", "httpx>=0.27,<1"]
|
|
# ///
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import Mock, patch
|
|
|
|
import pytest
|
|
|
|
import immichup
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"filename, expected_studio",
|
|
[
|
|
("Irina Dreyt -- @Mavrin__0007-upscaled.jpg", "Mavrin"),
|
|
("Irina Dreyt -- @Mavrin__0155.jpg", "Mavrin"),
|
|
("Irina Dreyt -- @MAVRIN__0007-UPSCALED.jpg", "MAVRIN"),
|
|
("Irina Dreyt -- @Mavrin -- Shoot__0007-upscaled.jpg", "Mavrin"),
|
|
("Irina Dreyt -- @Studio_Name-2.jpg", "Studio"),
|
|
("Irina Dreyt -- Shoot__0007-upscaled.jpg", None),
|
|
],
|
|
)
|
|
def test_studio_excludes_image_number_and_upscale_suffix(
|
|
filename: str,
|
|
expected_studio: str | None,
|
|
) -> None:
|
|
assert immichup.parse_filename(image_path=Path(filename)) == (["Irina Dreyt"], expected_studio)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"filename",
|
|
[
|
|
"Irina Dreyt -- @Mavrin__0007-upscaled.jpg",
|
|
"Irina Dreyt -- @MAVRIN__0155.jpg",
|
|
],
|
|
)
|
|
def test_studio_album_and_tag_use_lowercase_name_without_image_suffix(filename: str) -> None:
|
|
path = Path(filename)
|
|
client = Mock(spec=immichup.ImmichClient)
|
|
with patch.object(immichup, "read_jpeg_dimensions", return_value=(600, 800)):
|
|
assert immichup.process_image(path=path, client=client, dry_run=False)
|
|
client.upload_image.assert_called_once_with(
|
|
path,
|
|
["irina dreyt", "@mavrin"],
|
|
["irina dreyt", "mavrin", "aspect:portrait"],
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(pytest.main(args=[str(Path(__file__).resolve()), *sys.argv[1:]]))
|