- 행사 수집을 화면 요청에서 빼고 worker 가 월 04:00(켤 때 7일 기록 없으면 한 번) 전국 17개 시도를 받는다 - 문화정보원 음악/콘서트(B000) 추가, 쪽·시도 사이 1초 간격으로 초당 요청 제한 회피 - 팝가(popga.co.kr) 팝업스토어 수집: 사이트맵 + 상세 JSON-LD, 바뀐 페이지만 다시 읽음 - 수집이 끝나면 Teams Workflows webhook 으로 종류별 건수 알림 (TEAMS_WEBHOOK_URL) - event.kind(1=축제 2=전시 3=콘서트 4=팝업) 칸과 종류별 아이콘 추가 - 피드 행사 카드·띠를 축제→팝업→전시→콘서트 차례로 섞음 - 포스트 종류별 내용·피드 기획 문서 갱신 같은 작업 폴더의 다른 작업(외부 API 가드, 노을·달 계산, 각 API, 문서 파일 이름 정리 등)도 함께 담김.
65 lines
3.4 KiB
Python
65 lines
3.4 KiB
Python
import json
|
|
from datetime import date
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from common.enums import EventKind
|
|
from services.external import popga
|
|
from services.external.popga import fetch_popup_index, parse_popup, sido_of
|
|
|
|
|
|
def _page(popup_id: int, kind: str, start: str, end: str, address: str = "서울 성동구 테스트로 1") -> str:
|
|
ld = {
|
|
"@context": "https://schema.org", "@type": "Event", "name": "테스트 팝업 & 굿즈", "startDate": start, "endDate": end,
|
|
"location": {"@type": "Place", "name": "테스트 빌딩 1F", "address": {"@type": "PostalAddress", "streetAddress": address},
|
|
"geo": {"@type": "GeoCoordinates", "latitude": 37.5446123, "longitude": 127.0557456}},
|
|
}
|
|
payload = f'self.__next_f.push([1,"{{\\"data\\":{{\\"id\\":{popup_id},\\"type\\":\\"{kind}\\",\\"source\\":null}}}}"])'
|
|
return f'<html><script type="application/ld+json">{json.dumps(ld, ensure_ascii=False)}</script><script>{payload}</script></html>'
|
|
|
|
|
|
def test_parse_popup_maps_store():
|
|
row = parse_popup(_page(501, "STORE", "2026-10-02", "2026-10-11"), 501, date(2026, 10, 1))
|
|
assert row == {
|
|
"source_id": "popga:501", "sido_code": "11", "name": "테스트 팝업 & 굿즈", "place_name": "테스트 빌딩 1F",
|
|
"start_date": date(2026, 10, 2), "end_date": date(2026, 10, 11), "is_confirmed": True,
|
|
"source_url": "https://popga.co.kr/popup/501", "image_url": None, "lat": 37.54461, "lon": 127.05575, "kind": EventKind.POPUP, "icon": "popup",
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("kind,end,address", [
|
|
("PERFORMANCE", "2026-10-11", "서울 성동구 테스트로 1"),
|
|
("STORE", "2026-09-30", "서울 성동구 테스트로 1"),
|
|
("STORE", "2026-10-11", "알 수 없는 주소"),
|
|
])
|
|
def test_parse_popup_skips_non_store_ended_or_unknown_sido(kind, end, address):
|
|
assert parse_popup(_page(502, kind, "2026-09-01", end, address), 502, date(2026, 10, 1)) is None
|
|
|
|
|
|
def test_parse_popup_reads_type_of_its_own_id():
|
|
page = _page(503, "STORE", "2026-10-02", "2026-10-11").replace('\\"id\\":503,\\"type\\":\\"STORE\\"', '\\"id\\":999,\\"type\\":\\"STORE\\"')
|
|
assert parse_popup(page, 503, date(2026, 10, 1)) is None
|
|
|
|
|
|
@pytest.mark.parametrize("address,code", [
|
|
("서울 마포구 테스트로 1", "11"), ("서울특별시 마포구", "11"), ("경기 수원시", "41"), ("경상남도 진주시", "48"),
|
|
("강원특별자치도 춘천시", "51"), ("전북특별자치도 전주시", "52"), ("", None),
|
|
])
|
|
def test_sido_of(address, code):
|
|
assert sido_of(address) == code
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_fetch_popup_index_reads_popup_pages_only(monkeypatch):
|
|
monkeypatch.setattr(popga, "REQUEST_GAP_SEC", 0)
|
|
pages = {
|
|
"/sitemap.xml": "<sitemapindex><sitemap><loc>https://popga.co.kr/sitemap/2.xml</loc></sitemap>"
|
|
"<sitemap><loc>https://popga.co.kr/sitemap/5.xml</loc></sitemap></sitemapindex>",
|
|
"/sitemap/2.xml": "<urlset><url><loc>https://popga.co.kr/popup/12</loc><lastmod>2026-10-06T00:00:00Z</lastmod></url>"
|
|
"<url><loc>https://popga.co.kr/popup/11</loc></url></urlset>",
|
|
"/sitemap/5.xml": "<urlset><url><loc>https://popga.co.kr/popup/12/review/3</loc><lastmod>2026-10-06</lastmod></url></urlset>",
|
|
}
|
|
async with httpx.AsyncClient(transport=httpx.MockTransport(lambda req: httpx.Response(200, text=pages[req.url.path]))) as client:
|
|
assert await fetch_popup_index(client) == {12: "2026-10-06T00:00:00Z", 11: ""}
|