chore: main 병합 — 단풍·띠 좋아요, 밀림 수정, 글 주제·사진 Blob, 애드센스
This commit is contained in:
commit
e30f41de68
31 files changed
+831
-88
No files matched your search
@@ -4,7 +4,9 @@ import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from router.router import app
|
||||
from services.talk_service import DAILY_MAX, HIDE_AT, parse_cursor, spread_authors, weather_line
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from services.talk_service import DAILY_MAX, GROUP_MAX, HIDE_AT, parse_cursor, pick_group, spread_authors, weather_line
|
||||
|
||||
REGION = "1144000000"
|
||||
BUSAN = "2611000000"
|
||||
@@ -143,3 +145,49 @@ def test_spread_authors_and_cursor():
|
||||
assert [x.author.user_id for x in spread_authors([v("a"), v("a"), v("a"), v("b"), v("c")])] == ["a", "b", "a", "c", "a"]
|
||||
assert parse_cursor("1760000000_42") == (1760000000, 42)
|
||||
assert parse_cursor("12") is None and parse_cursor("x_1") is None
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_topic_is_saved_and_filters_list():
|
||||
async with client() as c:
|
||||
h = await _login(c, "talk_tp1")
|
||||
sky = (await c.post("/v1/talk", json={"region_code": REGION, "body": "노을 분홍빛", "topic": 2}, headers=h)).json()["talk"]
|
||||
plain = (await _write(c, h, "그냥 동네 이야기"))["talk"]
|
||||
assert sky["topic"] == 2 and plain["topic"] == 1
|
||||
only_sky = _ids((await c.get("/v1/talk/list", params={"topic": 2})).json())
|
||||
only_foliage = _ids((await c.get("/v1/talk/list", params={"topic": 4})).json())
|
||||
assert sky["talk_id"] in only_sky and plain["talk_id"] not in only_sky
|
||||
assert sky["talk_id"] not in only_foliage
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_groups_have_near_group_and_topic_group_from_three_people():
|
||||
async with client() as c:
|
||||
for i in range(3):
|
||||
h = await _login(c, f"talk_gr{i}")
|
||||
for j in range(2):
|
||||
await c.post("/v1/talk", json={"region_code": REGION, "body": f"단풍 물들었어요 {i}-{j}", "topic": 4}, headers=h)
|
||||
groups = {g["topic"]: g["talks"] for g in (await c.get("/v1/talk/groups", params={"region": REGION})).json()["groups"]}
|
||||
assert 0 in groups and 4 in groups
|
||||
assert all(t["topic"] == 4 for t in groups[4])
|
||||
for talks in groups.values():
|
||||
names = [t["nickname"] for t in talks]
|
||||
assert len(names) == len(set(names)) and len(talks) <= GROUP_MAX
|
||||
|
||||
|
||||
def _view(talk_id, user, region, hours_ago, likes=0, reports=0):
|
||||
now = datetime(2026, 10, 23, 12, tzinfo=timezone.utc)
|
||||
talk = SimpleNamespace(talk_id=talk_id, region_code=region, created_at=now - timedelta(hours=hours_ago), like_count=likes, report_count=reports)
|
||||
return SimpleNamespace(talk=talk, author=SimpleNamespace(user_id=user))
|
||||
|
||||
|
||||
def test_pick_group_orders_near_fresh_first_one_per_person_clean_first():
|
||||
now = datetime(2026, 10, 23, 12, tzinfo=timezone.utc)
|
||||
far = _view(1, "a", BUSAN, 1)
|
||||
same_sido = _view(2, "b", "1111000000", 1)
|
||||
same_gu = _view(3, "c", REGION, 1)
|
||||
old_popular = _view(4, "d", REGION, 30, likes=50)
|
||||
again = _view(5, "c", REGION, 0)
|
||||
assert [v.talk.talk_id for v in pick_group([far, same_sido, same_gu, old_popular, again], REGION, now)] == [5, 2, 1, 4]
|
||||
reported = _view(6, "e", REGION, 0, reports=1)
|
||||
assert pick_group([reported, far], REGION, now)[0].talk.talk_id == 1
|
||||
Reference in new issue
Block a user