feat(music-lab): cover.py Pexels 이미지 검색 분기 (image_source=pexels)
This commit is contained in:
@@ -91,3 +91,59 @@ async def test_dalle_b64_response_handled(tmp_storage, monkeypatch):
|
||||
prompt_template="x", mood="", track_title="X")
|
||||
assert out["used_fallback"] is False
|
||||
assert (tmp_storage / "46" / "cover.jpg").exists()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_pexels_image_source(tmp_storage, monkeypatch):
|
||||
monkeypatch.setenv("PEXELS_API_KEY", "test-pexels-key")
|
||||
img_url = "https://images.pexels.com/photos/123/photo.jpg"
|
||||
respx.get("https://api.pexels.com/v1/search").mock(
|
||||
return_value=Response(200, json={
|
||||
"photos": [{
|
||||
"id": 123,
|
||||
"src": {"large2x": img_url, "original": img_url},
|
||||
}],
|
||||
})
|
||||
)
|
||||
png_bytes = bytes.fromhex(
|
||||
"89504e470d0a1a0a0000000d49484452000000010000000108020000009077"
|
||||
"53de0000000c4944415478da6300010000050001"
|
||||
"0d0a2db40000000049454e44ae426082"
|
||||
)
|
||||
respx.get(img_url).mock(return_value=Response(200, content=png_bytes))
|
||||
|
||||
out = await cover.generate(
|
||||
pipeline_id=99, genre="lo-fi", prompt_template="ignored",
|
||||
mood="chill", track_title="Mix",
|
||||
image_source="pexels",
|
||||
)
|
||||
assert out["used_fallback"] is False
|
||||
assert out["url"].endswith("/cover.jpg")
|
||||
assert (tmp_storage / "99" / "cover.jpg").exists()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pexels_no_api_key_falls_back(tmp_storage, monkeypatch):
|
||||
monkeypatch.delenv("PEXELS_API_KEY", raising=False)
|
||||
out = await cover.generate(
|
||||
pipeline_id=98, genre="lo-fi", prompt_template="x",
|
||||
mood="", track_title="Test",
|
||||
image_source="pexels",
|
||||
)
|
||||
assert out["used_fallback"] is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_pexels_zero_results_falls_back(tmp_storage, monkeypatch):
|
||||
monkeypatch.setenv("PEXELS_API_KEY", "test-key")
|
||||
respx.get("https://api.pexels.com/v1/search").mock(
|
||||
return_value=Response(200, json={"photos": []})
|
||||
)
|
||||
out = await cover.generate(
|
||||
pipeline_id=97, genre="lo-fi", prompt_template="x",
|
||||
mood="", track_title="Test",
|
||||
image_source="pexels",
|
||||
)
|
||||
assert out["used_fallback"] is True
|
||||
|
||||
Reference in New Issue
Block a user