chore: checkpoint baseline (routers, tests, pyproject)
This commit is contained in:
parent
a58498a315
commit
986f1dfef4
37 changed files with 2527 additions and 1664 deletions
147
tests/test_sidecar.py
Normal file
147
tests/test_sidecar.py
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
"""Tests for sidecar file generation."""
|
||||
|
||||
import json
|
||||
|
||||
from src.sidecar import generate_filename, write_immich_sidecar
|
||||
|
||||
|
||||
class TestWriteImmichSidecar:
|
||||
def test_creates_sidecar_file(self, tmp_path):
|
||||
media_file = tmp_path / "test.jpg"
|
||||
media_file.write_bytes(b"fake image data")
|
||||
|
||||
sidecar_path = write_immich_sidecar(
|
||||
filepath=str(media_file),
|
||||
subreddit="pics",
|
||||
author="testuser",
|
||||
title="A great photo",
|
||||
score=150,
|
||||
created_utc=1700000000.0,
|
||||
media_type="image",
|
||||
permalink="/r/pics/comments/abc/a_great_photo/",
|
||||
flair="OC",
|
||||
source_type="subreddit",
|
||||
)
|
||||
|
||||
assert sidecar_path.endswith(".json")
|
||||
with open(sidecar_path) as f:
|
||||
data = json.load(f)
|
||||
|
||||
assert "dateTimeOriginal" in data
|
||||
assert data["description"] == "A great photo"
|
||||
assert data["albums"] == ["r/pics"]
|
||||
assert "reddit" in data["tags"]
|
||||
assert "pics" in data["tags"]
|
||||
assert "OC" in data["tags"]
|
||||
assert data["rating"] == 3 # score 150 -> rating 3
|
||||
assert data["people"] == ["testuser"]
|
||||
assert "reddit.com" in data["externalUrl"]
|
||||
|
||||
def test_rating_buckets(self, tmp_path):
|
||||
media_file = tmp_path / "test.jpg"
|
||||
media_file.write_bytes(b"fake")
|
||||
|
||||
test_cases = [
|
||||
(5, 1),
|
||||
(10, 2),
|
||||
(50, 3),
|
||||
(200, 4),
|
||||
(1000, 5),
|
||||
(5000, 5),
|
||||
]
|
||||
for score, expected_rating in test_cases:
|
||||
path = write_immich_sidecar(
|
||||
filepath=str(media_file),
|
||||
subreddit="test",
|
||||
author="user",
|
||||
title="test",
|
||||
score=score,
|
||||
created_utc=1700000000.0,
|
||||
media_type="image",
|
||||
)
|
||||
with open(path) as f:
|
||||
data = json.load(f)
|
||||
assert data["rating"] == expected_rating, f"Score {score} should give rating {expected_rating}"
|
||||
|
||||
def test_deleted_author_no_people(self, tmp_path):
|
||||
media_file = tmp_path / "test.jpg"
|
||||
media_file.write_bytes(b"fake")
|
||||
|
||||
write_immich_sidecar(
|
||||
filepath=str(media_file),
|
||||
subreddit="test",
|
||||
author="[deleted]",
|
||||
title="test",
|
||||
score=10,
|
||||
created_utc=1700000000.0,
|
||||
media_type="image",
|
||||
)
|
||||
with open(str(media_file) + ".json") as f:
|
||||
data = json.load(f)
|
||||
assert "people" not in data
|
||||
|
||||
def test_no_permalink_no_external_url(self, tmp_path):
|
||||
media_file = tmp_path / "test.jpg"
|
||||
media_file.write_bytes(b"fake")
|
||||
|
||||
write_immich_sidecar(
|
||||
filepath=str(media_file),
|
||||
subreddit="test",
|
||||
author="user",
|
||||
title="test",
|
||||
score=10,
|
||||
created_utc=1700000000.0,
|
||||
media_type="image",
|
||||
)
|
||||
with open(str(media_file) + ".json") as f:
|
||||
data = json.load(f)
|
||||
assert "externalUrl" not in data
|
||||
|
||||
|
||||
class TestGenerateFilename:
|
||||
def test_basic_filename(self):
|
||||
name = generate_filename(
|
||||
subreddit="pics",
|
||||
author="testuser",
|
||||
created_utc=1700000000.0,
|
||||
post_id="abc123",
|
||||
ext=".jpg",
|
||||
)
|
||||
assert "pics" in name
|
||||
assert "testuser" in name
|
||||
assert "abc123" in name
|
||||
assert name.endswith(".jpg")
|
||||
|
||||
def test_gallery_index(self):
|
||||
name = generate_filename(
|
||||
subreddit="pics",
|
||||
author="testuser",
|
||||
created_utc=1700000000.0,
|
||||
post_id="abc123",
|
||||
ext=".jpg",
|
||||
gallery_index=3,
|
||||
)
|
||||
assert "_3.jpg" in name
|
||||
|
||||
def test_deleted_author(self):
|
||||
name = generate_filename(
|
||||
subreddit="pics",
|
||||
author="[deleted]",
|
||||
created_utc=1700000000.0,
|
||||
post_id="abc123",
|
||||
ext=".jpg",
|
||||
)
|
||||
assert "unknown" in name
|
||||
|
||||
def test_sanitized_names(self):
|
||||
name = generate_filename(
|
||||
subreddit="pics/test",
|
||||
author="user name!@#",
|
||||
created_utc=1700000000.0,
|
||||
post_id="abc123",
|
||||
ext=".jpg",
|
||||
)
|
||||
# Should not contain special characters
|
||||
assert "/" not in name
|
||||
assert "!" not in name
|
||||
assert "@" not in name
|
||||
Loading…
Add table
Add a link
Reference in a new issue