Files
o2o-weather/backend/tests/test_auth_reaction.py
T
minaChoi a9ddbaab3c feat: 피드를 시간대별 카드로 다시 짜고 하늘 배경·내 캐릭터 추가, 다른 시안 정리
- 피드: 그날 카드 12장을 03:00에 한 번에 만들고, 시간대(아침·낮·저녁·밤, 저녁은 일몰 2시간 전부터)마다 순서를 바꾸고 조건이 맞는 카드만 켠다. 새 카드 우산·특보, 내일 미리보기, 한 문장·시(예시 seed). 흐린 날 노을은 한 줄 카드.
- 캐시를 feed:{구}:{시간대}로 나누고 시간대 경계·일몰·예보 갱신 때 만료해 새 카드가 늦게 보이던 문제를 고친다.
- 히어로는 오늘 1위 각만 보여 준다.
- 각 점수·노을 점수를 7일 지나면 지운다.
- 화면 전체 하늘 배경(시간대별 색, 느린 일렁임, 밤 별)과 화면 끝까지 이어지는 위·아래 바.
- 상단바 로그인 버튼, 내 정보 창(캐릭터 6종·배경색 6종·오늘 기분 8종·닉네임·로그아웃), PATCH /v1/auth/me, 댓글·상단바에 캐릭터·배경색·기분 표시. users.character·color·mood 칸 추가.
- 카드 슬라이드와 가로 줄을 Embla 카로셀로 바꿔 PC에서도 마우스로 끌어 넘기고 화살표로 넘긴다.
- 좋아요·저장을 받아 둔 피드 데이터에도 반영해 다른 탭에 다녀와도 유지되게 고치고, 좋아요 때 하트가 터지는 애니메이션을 넣는다.
- 보내기에서 게시물을 인스타 스토리 크기(1080×1920) 이미지로 공유하거나 내려받는다 (modern-screenshot).
- 창이 열려 있는 동안 뒤 페이지 스크롤을 잠근다.
- 시안 B 확정: 시안 A 아이콘(public/a)과 쓰지 않는 전역 스타일·글꼴 삭제.
- 문서: 데이터 흐름 지도(backend/docs/data-flow-map.html), 확정 시안(docs/시안B_확정.html), 피드 기획 v2, 호출량·DB 크기 추정, data-pipeline 갱신. 보고 폴더와 예전 시안 html 삭제.
2026-10-02 15:47:20 +09:00

101 lines
5.8 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
@pytest.mark.anyio
async def test_update_me_changes_character_and_nickname_and_shows_on_comments(offline):
async with client() as c:
token = (await _signup(c))["access_token"]
h = {"Authorization": f"Bearer {token}"}
assert (await c.get("/v1/auth/me", headers=h)).json()["me"]["character"] == "rabbit"
me = (await c.patch("/v1/auth/me", headers=h, json={"character": "bear", "nickname": "곰돌이", "color": "blue"})).json()["me"]
assert (me["character"], me["nickname"], me["color"]) == ("bear", "곰돌이", "blue")
assert (await c.patch("/v1/auth/me", headers=h, json={"color": "gold"})).json()["result"]["desc"] == "INVALID_INPUT"
assert (await c.patch("/v1/auth/me", headers=h, json={"mood": "thunder"})).json()["me"]["mood"] == "thunder"
assert (await c.patch("/v1/auth/me", headers=h, json={"mood": "sleepy"})).json()["result"]["desc"] == "INVALID_INPUT"
assert (await c.patch("/v1/auth/me", headers=h, json={"character": "dragon"})).json()["result"]["desc"] == "INVALID_INPUT"
assert (await c.patch("/v1/auth/me", json={"character": "bear"})).status_code == 401
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
await c.post(f"/v1/reaction/post/{post_id}/comment", headers=h, json={"body": "안녕"})
comments = (await c.get(f"/v1/reaction/post/{post_id}/comment/list")).json()["comments"]
assert (comments[0]["character"], comments[0]["color"], comments[0]["nickname"]) == ("bear", "blue", "곰돌이")
assert comments[0]["mood"] == "thunder"
assert "mood" not in (await c.patch("/v1/auth/me", headers=h, json={"mood": ""})).json()["me"]