feat: 10/20 회의 반영 — 이야기 탭을 오늘 피드로 합침(글쓰기 칸·사진 올리기·위치 정보 삭제), 오늘의 각 카드와 히어로·각 공유 템플릿, 나만의 각을 이름+날씨 조건 저장으로, 로그인 없이 좋아요(IP 해시), 피드 순서·불쾌지수 상시·포스트 그림 배경, 새 각 아이콘
This commit is contained in:
1 parent
017022a0b0
commit
d0213f41a6
81 files changed
+3503
-593
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from router.router import app
|
||||
|
||||
REGION = "1144000000"
|
||||
IP_A = {"X-Forwarded-For": "203.0.113.10"}
|
||||
IP_B = {"X-Forwarded-For": "203.0.113.20"}
|
||||
|
||||
|
||||
def client():
|
||||
return AsyncClient(transport=ASGITransport(app=app), base_url="http://test")
|
||||
|
||||
|
||||
async def _login(c, login_id: str) -> dict:
|
||||
body = (await c.post("/v1/auth/signup", json={"login_id": login_id, "password": "password1", "nickname": login_id})).json()
|
||||
return {"Authorization": f"Bearer {body['access_token']}"}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_anon_post_like_counts_once_per_ip(offline):
|
||||
async with client() as c:
|
||||
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
|
||||
url = f"/v1/reaction/post/{post_id}/like"
|
||||
assert (await c.post(url, headers=IP_A)).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers=IP_A)).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers=IP_B)).json()["like_count"] == 2
|
||||
h = await _login(c, "anon_like_01")
|
||||
assert (await c.post(url, headers={**h, **IP_A})).json()["like_count"] == 3
|
||||
|
||||
feed_a = (await c.get("/v1/feed", params={"region": REGION}, headers=IP_A)).json()
|
||||
p = next(x for x in feed_a["posts"] if x["post_id"] == post_id)
|
||||
assert p["liked"] is True and p["like_count"] == 3 and "saved" not in p
|
||||
other = (await c.get("/v1/feed", params={"region": REGION}, headers={"X-Forwarded-For": "203.0.113.30"})).json()
|
||||
assert next(x for x in other["posts"] if x["post_id"] == post_id)["liked"] is False
|
||||
|
||||
assert (await c.delete(url, headers=IP_A)).json()["like_count"] == 2
|
||||
assert (await c.delete(url, headers=IP_A)).json()["like_count"] == 2
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_only_last_forwarded_ip_counts(offline):
|
||||
"""클라이언트가 X-Forwarded-For 앞쪽을 바꿔도 nginx 가 붙인 마지막 주소가 같으면 같은 사람이다."""
|
||||
async with client() as c:
|
||||
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
|
||||
url = f"/v1/reaction/post/{post_id}/like"
|
||||
assert (await c.post(url, headers={"X-Forwarded-For": "1.1.1.1, 203.0.113.10"})).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers={"X-Forwarded-For": "2.2.2.2, 203.0.113.10"})).json()["like_count"] == 1
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_anon_comment_like(offline):
|
||||
async with client() as c:
|
||||
post_id = (await c.get("/v1/feed", params={"region": REGION})).json()["posts"][0]["post_id"]
|
||||
h = await _login(c, "anon_like_02")
|
||||
comment_id = (await c.post(f"/v1/reaction/post/{post_id}/comment", headers=h, json={"body": "맑아요"})).json()["comment"]["comment_id"]
|
||||
url = f"/v1/reaction/comment/{comment_id}/like"
|
||||
assert (await c.post(url, headers=IP_A)).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers=IP_A)).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers=IP_B)).json()["like_count"] == 2
|
||||
assert (await c.post(url, headers=h)).json()["like_count"] == 3
|
||||
|
||||
listed = (await c.get(f"/v1/reaction/post/{post_id}/comment/list", headers=IP_A)).json()["comments"]
|
||||
assert listed[0]["liked"] is True
|
||||
listed = (await c.get(f"/v1/reaction/post/{post_id}/comment/list", headers={"X-Forwarded-For": "203.0.113.30"})).json()["comments"]
|
||||
assert listed[0]["liked"] is False
|
||||
|
||||
assert (await c.delete(url, headers=IP_B)).json()["like_count"] == 2
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_anon_talk_like():
|
||||
async with client() as c:
|
||||
h = await _login(c, "anon_like_03")
|
||||
talk_id = (await c.post("/v1/talk", json={"region_code": REGION, "body": "바람 불어요"}, headers=h)).json()["talk"]["talk_id"]
|
||||
url = f"/v1/talk/{talk_id}/like"
|
||||
assert (await c.post(url, headers=IP_A)).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers=IP_A)).json()["like_count"] == 1
|
||||
assert (await c.post(url, headers=IP_B)).json()["like_count"] == 2
|
||||
assert (await c.post(url, headers=h)).json()["like_count"] == 3
|
||||
|
||||
talks = (await c.get("/v1/talk/list", headers=IP_A)).json()["talks"]
|
||||
assert next(x for x in talks if x["talk_id"] == talk_id)["liked"] is True
|
||||
talks = (await c.get("/v1/talk/list", headers={"X-Forwarded-For": "203.0.113.30"})).json()["talks"]
|
||||
assert next(x for x in talks if x["talk_id"] == talk_id)["liked"] is False
|
||||
|
||||
assert (await c.delete(url, headers=IP_A)).json()["like_count"] == 2
|
||||
Reference in new issue
Block a user