- FastAPI + PostgreSQL + Redis, web·worker 분리, compose 에 backend·worker·postgres·redis 추가 - 기상청 단기·초단기·중기·특보, 에어코리아, Open-Meteo, TourAPI, 특일정보 연동 (첫 조회 때 받고 캐시) - 매일 03:00 worker 가 전국 공통 피드 칸을 정하고 지난 데이터를 정리 - 시드: 시군구 256곳, 지수 23개, 노을 대표 지점·명소, 데이트 명소, 읽을거리 - pytest 66개 (테스트 전용 DB·Redis 사용) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
4.1 KiB
Python
79 lines
4.1 KiB
Python
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from router.router import app
|
|
|
|
REGION = "1144000000"
|
|
|
|
|
|
def client():
|
|
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
|
|
|
|
|
|
async def _signup(c, login_id="mina_01", nickname="망원동주민"):
|
|
return (await c.post("/v1/auth/signup", json={"login_id": login_id, "password": "password1", "nickname": nickname})).json()
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_signup_login_refresh_me():
|
|
async with client() as c:
|
|
body = await _signup(c)
|
|
assert body["result"]["success"] is True and body["me"]["nickname"] == "망원동주민"
|
|
dup = await _signup(c)
|
|
assert dup["result"]["desc"] == "AUTH_DUPLICATE_ID"
|
|
bad = (await c.post("/v1/auth/login", json={"login_id": "mina_01", "password": "wrong-pass"})).json()
|
|
assert bad["result"]["desc"] == "AUTH_FAILED"
|
|
ok = (await c.post("/v1/auth/login", json={"login_id": "mina_01", "password": "password1"})).json()
|
|
me = (await c.get("/v1/auth/me", headers={"Authorization": f"Bearer {ok['access_token']}"})).json()
|
|
assert me["me"]["login_id"] == "mina_01"
|
|
again = (await c.post("/v1/auth/refresh", json={"refresh_token": ok["refresh_token"]})).json()
|
|
assert again["access_token"]
|
|
assert (await c.post("/v1/auth/refresh", json={"refresh_token": ok["access_token"]})).json()["result"]["desc"] == "AUTH_TOKEN_INVALID"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_signup_rejects_bad_input():
|
|
async with client() as c:
|
|
body = (await c.post("/v1/auth/signup", json={"login_id": "AB", "password": "short", "nickname": "x"})).json()
|
|
assert body["result"]["desc"] == "INVALID_INPUT"
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_reactions_require_login_and_update_feed(offline):
|
|
async with client() as c:
|
|
feed = (await c.get("/v1/feed", params={"region": REGION})).json()
|
|
post_id = feed["posts"][0]["post_id"]
|
|
assert (await c.post(f"/v1/reaction/post/{post_id}/like")).status_code == 401
|
|
|
|
token = (await _signup(c))["access_token"]
|
|
h = {"Authorization": f"Bearer {token}"}
|
|
liked = (await c.post(f"/v1/reaction/post/{post_id}/like", headers=h)).json()
|
|
again = (await c.post(f"/v1/reaction/post/{post_id}/like", headers=h)).json()
|
|
assert liked["like_count"] == 1 and again["like_count"] == 1
|
|
assert (await c.post(f"/v1/reaction/post/{post_id}/save", headers=h)).json()["saved"] is True
|
|
|
|
comment = (await c.post(f"/v1/reaction/post/{post_id}/comment", headers=h, json={"body": " 빨래 지금 널어요! "})).json()["comment"]
|
|
assert comment["body"] == "빨래 지금 널어요!" and comment["mine"] is True
|
|
too_long = (await c.post(f"/v1/reaction/post/{post_id}/comment", headers=h, json={"body": "가" * 61})).json()
|
|
assert too_long["result"]["desc"] == "INVALID_INPUT"
|
|
assert (await c.post(f"/v1/reaction/comment/{comment['comment_id']}/like", headers=h)).json()["like_count"] == 1
|
|
|
|
listed = (await c.get(f"/v1/reaction/post/{post_id}/comment/list")).json()
|
|
assert [x["body"] for x in listed["comments"]] == ["빨래 지금 널어요!"] and listed["comments"][0]["mine"] is False
|
|
|
|
mine = (await c.get("/v1/feed", params={"region": REGION}, headers=h)).json()
|
|
p = next(x for x in mine["posts"] if x["post_id"] == post_id)
|
|
assert p["liked"] is True and p["saved"] is True and p["like_count"] == 1 and p["comment_count"] == 1
|
|
|
|
other = (await _signup(c, "other_02", "다른사람"))["access_token"]
|
|
assert (await c.delete(f"/v1/reaction/comment/{comment['comment_id']}", headers={"Authorization": f"Bearer {other}"})).json()["result"]["desc"] == "NOT_FOUND"
|
|
assert (await c.delete(f"/v1/reaction/comment/{comment['comment_id']}", headers=h)).json()["result"]["success"] is True
|
|
assert (await c.get("/v1/reaction/save/list", headers=h)).json()["posts"][0]["post_id"] == post_id
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_bad_token_is_401():
|
|
async with client() as c:
|
|
res = await c.get("/v1/auth/me", headers={"Authorization": "Bearer not-a-token"})
|
|
assert res.status_code == 401
|