60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import io
|
|||
|
|
|
||
|
|
from PIL import Image
|
||
|
|
|
||
|
|
from pigway_frame_flow.models import PhotoSourceContent
|
||
|
|
from pigway_frame_flow.providers.photo_sources import PhotoSourceInput
|
||
|
|
|
||
|
|
|
||
|
|
def test_photo_path_survives_render_and_asset_listing(client, service, monkeypatch):
|
||
|
|
photos = service.photo_sources
|
||
|
|
photos.save(
|
||
|
|
"family",
|
||
|
|
PhotoSourceInput(
|
||
|
|
name="Family",
|
||
|
|
kind="synology-photos",
|
||
|
|
location=".",
|
||
|
|
nas_root_path="/volume1/photo",
|
||
|
|
),
|
||
|
|
)
|
||
|
|
monkeypatch.setattr(photos.synology, "sid", lambda: "fixture")
|
||
|
|
monkeypatch.setattr(
|
||
|
|
photos.synology,
|
||
|
|
"items",
|
||
|
|
lambda *a, **kw: [
|
||
|
|
{
|
||
|
|
"id": 42,
|
||
|
|
"filename": "original.PNG",
|
||
|
|
"additional": {
|
||
|
|
"folder": "/家庭/20190130",
|
||
|
|
"resolution": {"width": 1600, "height": 1200},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
],
|
||
|
|
)
|
||
|
|
out = io.BytesIO()
|
||
|
|
Image.new("RGB", (1600, 1200)).save(out, "PNG")
|
||
|
|
monkeypatch.setattr(photos.synology, "download", lambda *a, **kw: out.getvalue())
|
||
|
|
assert (
|
||
|
|
photos.catalog("family")[0]["source_path"]
|
||
|
|
== "/volume1/photo/家庭/20190130/original.PNG"
|
||
|
|
)
|
||
|
|
asset = service.content_asset(
|
||
|
|
PhotoSourceContent(type="photo_source", source_id="family", item_id="42")
|
||
|
|
)
|
||
|
|
assert asset["source_path"] == "/volume1/photo/家庭/20190130/original.PNG"
|
||
|
|
assert client.get("/api/v1/assets").json()[0]["source_path"] == asset["source_path"]
|
||
|
|
assert (
|
||
|
|
client.get("/api/v1/assets/" + asset["asset_id"] + "/source").json()["source"][
|
||
|
|
"item_id"
|
||
|
|
]
|
||
|
|
== "42"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_missing_photo_path_is_not_invented(service):
|
||
|
|
out = io.BytesIO()
|
||
|
|
Image.new("RGB", (20, 20)).save(out, "JPEG")
|
||
|
|
asset = service.assets.put(out.getvalue(), "manual.jpg")
|
||
|
|
assert asset["source_path"] is None
|