feat: 서울문화포털 축제(동네·구청·공원)와 팝가 축제도 수집
This commit is contained in:
1 parent
ce6efe979a
commit
c7152563b9
9 files changed
+178
-9
No files matched your search
@@ -65,6 +65,14 @@ async def _async(v):
|
||||
return v
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_seoul_crawl(monkeypatch):
|
||||
"""서울문화포털은 키 없이 바로 긁어 오므로, 테스트가 실제 사이트를 부르지 않게 기본으로 막는다."""
|
||||
import services.week_service as week_service
|
||||
|
||||
monkeypatch.setattr(week_service, "fetch_seoul_festivals", lambda *a: _async([]))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def offline(monkeypatch):
|
||||
"""외부 API 를 모두 맑고 잔잔한 가짜 값으로 바꾼다."""
|
||||
|
||||
@@ -28,6 +28,11 @@ def test_parse_popup_maps_store():
|
||||
}
|
||||
|
||||
|
||||
def test_parse_popup_maps_festival():
|
||||
row = parse_popup(_page(504, "FESTIVAL", "2026-10-02", "2026-10-11", "경기 수원시 팔달구 테스트로 1"), 504, date(2026, 10, 1))
|
||||
assert (row["kind"], row["icon"], row["sido_code"]) == (EventKind.FESTIVAL, "fireworks", "41")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind,end,address", [
|
||||
("PERFORMANCE", "2026-10-11", "서울 성동구 테스트로 1"),
|
||||
("STORE", "2026-09-30", "서울 성동구 테스트로 1"),
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
from datetime import date
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
import services.week_service as week_service
|
||||
from services.external.seoul_culture import LIST_URL, fetch_seoul_festivals, parse_seoul_festivals
|
||||
from services.week_service import _seoul
|
||||
|
||||
ITEM = {
|
||||
"cultcode": 159216, "title": "[중랑문화재단] 2026 중랑용마폭포축제", "strtdate": "2026-10-10", "endDate": "2026-10-10",
|
||||
"atchFileId": "abc", "xCoord": "37.5118239", "yCoord": "127.0591590", "facName": "용마폭포공원", "addr": "서울특별시 중랑구",
|
||||
}
|
||||
|
||||
|
||||
def test_parse_reads_lat_from_x_and_builds_image_and_link():
|
||||
[row] = parse_seoul_festivals([ITEM, {**ITEM, "cultcode": None}, {**ITEM, "cultcode": 2, "strtdate": ""}])
|
||||
assert row["source_id"] == "seoul:159216" and row["sido_code"] == "11"
|
||||
assert (row["lat"], row["lon"]) == (37.51182, 127.05916)
|
||||
assert row["place_name"] == "용마폭포공원" and row["start_date"] == date(2026, 10, 10)
|
||||
assert row["image_url"].endswith("atchFileId=abc&thumb=Y") and "cultcode=159216" in row["source_url"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_fetch_pages_until_empty(monkeypatch):
|
||||
monkeypatch.setattr("services.external.seoul_culture.REQUEST_GAP_SEC", 0)
|
||||
pages = []
|
||||
|
||||
def handler(req: httpx.Request) -> httpx.Response:
|
||||
assert str(req.url) == LIST_URL
|
||||
page = int(dict(x.split("=") for x in req.content.decode().split("&"))["pageIndex"])
|
||||
pages.append(page)
|
||||
return httpx.Response(200, json={"resultList": [ITEM] * 10 if page < 3 else []})
|
||||
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as client:
|
||||
items = await fetch_seoul_festivals(client, date(2026, 10, 8), 30)
|
||||
assert len(items) == 20 and pages == [1, 2, 3]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_seoul_skips_festivals_tour_api_already_has_and_other_sidos(monkeypatch):
|
||||
other = {**ITEM, "cultcode": 2, "title": "2026 서울어텀페스타"}
|
||||
|
||||
async def fake(client, since, days):
|
||||
return [ITEM, other]
|
||||
|
||||
monkeypatch.setattr(week_service, "fetch_seoul_festivals", fake)
|
||||
known = [{"name": "제3회 중랑용마폭포축제"}]
|
||||
rows = await _seoul(None, "11", date(2026, 10, 8), known)
|
||||
assert [r["name"] for r in rows] == ["2026 서울어텀페스타"]
|
||||
assert await _seoul(None, "41", date(2026, 10, 8), known) == []
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_seoul_failure_keeps_other_sources(monkeypatch):
|
||||
async def broken(client, since, days):
|
||||
raise httpx.ConnectError("down")
|
||||
|
||||
monkeypatch.setattr(week_service, "fetch_seoul_festivals", broken)
|
||||
assert await _seoul(None, "11", date(2026, 10, 8), []) == []
|
||||
Reference in new issue
Block a user