feat: main 병합 + 인스타 올리기 API(/v1/card/{id}/instagram), 관리자 올릴 곳 선택(로컬·킹서버), 만든 카드 화면

This commit is contained in:
minaChoi committed 2026-10-23 15:48:09 +09:00
commit 572b2a05c8
188 files changed
+16605 -741

No files matched your search

+49
View File
@@ -93,3 +93,52 @@ async def test_list_cards_newest_first_with_image_urls(offline, admin_key):
first = res["items"][0]
assert first["title"] == "둘째 카드" and first["status"] == CardStatus.PUBLISHED.value and first["post_id"] and len(first["image_urls"]) == 3
assert res["items"][1]["status"] == CardStatus.WAITING.value and res["items"][1].get("published_at") is None
@pytest.mark.anyio
async def test_instagram_publish_carousel_and_store_media_id(offline, admin_key, monkeypatch):
import httpx
from services.external import instagram
monkeypatch.setattr(settings, "instagram_access_token", "tok")
monkeypatch.setattr(settings, "instagram_user_id", "1789")
monkeypatch.setattr(settings, "public_base_url", "https://weather.example")
calls: list[tuple[str, dict]] = []
def handler(request: httpx.Request) -> httpx.Response:
data = dict(httpx.QueryParams(request.content.decode())) if request.method == "POST" else dict(request.url.params)
calls.append((request.url.path, data))
assert data["access_token"] == "tok"
if request.url.path.endswith("/1789/media"):
if data.get("media_type") == "CAROUSEL":
assert data["children"] == "c1,c2,c3" and data["caption"].startswith("오늘의 썸 타로")
return httpx.Response(200, json={"id": "car"})
assert data["image_url"].startswith("https://weather.example/v1/card/") and data["is_carousel_item"] == "true"
return httpx.Response(200, json={"id": f"c{len([c for c in calls if 'is_carousel_item' in c[1]])}"})
if request.url.path.endswith("/car"):
return httpx.Response(200, json={"status_code": "FINISHED"})
if request.url.path.endswith("/media_publish"):
assert data["creation_id"] == "car"
return httpx.Response(200, json={"id": "media99"})
return httpx.Response(404, json={"error": {"message": "no"}})
real = httpx.AsyncClient
monkeypatch.setattr(instagram.httpx, "AsyncClient", lambda **kw: real(transport=httpx.MockTransport(handler)))
async with client() as c:
made = (await c.post("/v1/card", json=body(publish=True), headers=admin_key)).json()
res = (await c.post(f"/v1/card/{made['card_id']}/instagram", headers=admin_key)).json()
again = (await c.post(f"/v1/card/{made['card_id']}/instagram", headers=admin_key)).json()
listed = (await c.get("/v1/card", headers=admin_key)).json()["items"][0]
assert res["result"]["success"] and res["ig_media_id"] == "media99"
assert again["ig_media_id"] == "media99" and len([p for p, _ in calls if p.endswith("/media_publish")]) == 1
assert listed["ig_media_id"] == "media99"
@pytest.mark.anyio
async def test_instagram_requires_token(offline, admin_key, monkeypatch):
monkeypatch.setattr(settings, "instagram_access_token", "")
async with client() as c:
made = (await c.post("/v1/card", json=body(), headers=admin_key)).json()
res = (await c.post(f"/v1/card/{made['card_id']}/instagram", headers=admin_key)).json()
assert res["result"]["success"] is False and "INSTAGRAM" in res["msg"]