- 내 각: 아이콘 고르기(my_gak.icon), 카드는 아이콘·점수·아쉬운 조건만, 눌러서 상세(시간대·조건별 점수), 공유는 공통 공유 창 - 이야기: 오늘 쓴 내 글 묶음, '내 글' 칩·탭, 무한 스크롤, 사진 카메라 버튼, 지우기 확인, ⋯ 메뉴 하트 옆, 글 시간 서버 계산(1일 전) - 공유 이미지: 1:1·4:5 는 아래 얇은 띠 한 줄로 카드를 크게 - 행사: 수집 때 주소 저장(event.address), 행사 포스트에 장소·주소·기간 - 히어로 말풍선 '오늘 낮은 / 내일 낮은', 내일을 볼 때 배경도 따라감, 달 보름 순간이 낮이면 뜨는 시각으로 - 단풍 지도 피드 맨 위, 행사·계절 띠 포스트 틀 되돌림, 쇼츠 홈 버튼 가림·닫기 버튼, 하단 여백, 회색 글자 대비 - 토스 앱에선 쇼츠 플레이어를 하나만 띄움
92 lines
4.8 KiB
Python
92 lines
4.8 KiB
Python
from dataclasses import replace
|
|
from datetime import datetime, timedelta, timezone
|
|
from types import SimpleNamespace
|
|
|
|
from common.enums import PostType
|
|
from common.utils.kma_time import KST
|
|
from services.calc.moon import MoonNight, altitude, nearest, night, phase_name, view_line
|
|
from services.feed_service import FeedService, _tonight
|
|
|
|
|
|
def test_true_phases_match_published_times_within_five_minutes():
|
|
known = [(True, datetime(2024, 4, 23, 23, 49, tzinfo=timezone.utc)), (False, datetime(2024, 4, 8, 18, 21, tzinfo=timezone.utc)),
|
|
(True, datetime(2025, 10, 7, 3, 47, tzinfo=timezone.utc)), (False, datetime(2017, 8, 21, 18, 30, tzinfo=timezone.utc))]
|
|
for full, at in known:
|
|
assert abs((nearest(at, full) - at).total_seconds()) < 300
|
|
|
|
|
|
def test_phase_names():
|
|
assert phase_name(datetime(2025, 10, 7, 3, 47, tzinfo=timezone.utc)) == "보름달"
|
|
assert phase_name(datetime(2024, 4, 8, 18, 21, tzinfo=timezone.utc)) == "삭"
|
|
|
|
|
|
def test_tonight_follows_feed_day_starting_at_3am():
|
|
assert _tonight(datetime(2024, 4, 9, 1, 0, tzinfo=KST)) == datetime(2024, 4, 8, 22, 0, tzinfo=KST)
|
|
assert _tonight(datetime(2024, 4, 8, 20, 0, tzinfo=KST)) == datetime(2024, 4, 8, 22, 0, tzinfo=KST)
|
|
assert _tonight(datetime(2024, 4, 9, 9, 0, tzinfo=KST)) == datetime(2024, 4, 9, 22, 0, tzinfo=KST)
|
|
|
|
|
|
def _moon_post(now: datetime):
|
|
base = dict(post_id=1, post_type=PostType.MOON, like_count=0, comment_count=0, published_at=now)
|
|
c = SimpleNamespace(now=now, region=SimpleNamespace(short_name="분당구", lat=37.38, lon=127.12), hourly=[], board=None)
|
|
return FeedService._moon(None, base, c)
|
|
|
|
|
|
def test_moon_post_every_night_with_full_and_new_moon_stories():
|
|
full = _moon_post(datetime(2025, 10, 7, 20, 0, tzinfo=KST)) # 보름 10.07 12:47
|
|
# 가장 둥근 순간(12:47)이 낮이라 그 시각 대신 뜨는 시각·밤새 떠 있음을 말한다
|
|
assert full.title == "오늘 밤 보름달" and "12:4" not in full.slides[0].line and ("떠요" in full.slides[0].line or "밤새" in full.slides[0].line)
|
|
new = _moon_post(datetime(2024, 4, 9, 1, 0, tzinfo=KST)) # 삭 04.09 03:21, 자정 넘긴 새벽에도 그 밤
|
|
assert new.title == "오늘 밤 달 없는 밤"
|
|
plain = _moon_post(datetime(2025, 10, 4, 20, 0, tzinfo=KST)) # 보름 사흘 전
|
|
assert plain.title == "오늘 밤 차오르는 달" and plain.slides[0].rows[-1].label == "다음 보름" and plain.slides[0].rows[-1].value.startswith("10.07")
|
|
|
|
|
|
def test_moon_post_slide_carries_shape_for_drawing():
|
|
full = _moon_post(datetime(2025, 10, 7, 20, 0, tzinfo=KST)).slides[0]
|
|
assert full.moon_pct == 100
|
|
new = _moon_post(datetime(2024, 4, 9, 1, 0, tzinfo=KST)).slides[0]
|
|
assert new.moon_pct == 0
|
|
waxing = _moon_post(datetime(2025, 10, 4, 20, 0, tzinfo=KST)).slides[0]
|
|
assert 70 < waxing.moon_pct < 97 and waxing.moon_waxing is True
|
|
waning = _moon_post(datetime(2025, 10, 10, 20, 0, tzinfo=KST)).slides[0]
|
|
assert 70 < waning.moon_pct < 97 and waning.moon_waxing is False
|
|
|
|
|
|
SEOUL = (37.57, 126.98)
|
|
|
|
|
|
def _night_of(at):
|
|
"""그 시각과 23시가 가장 가까운 밤."""
|
|
return (at.astimezone(KST) - timedelta(hours=11)).date()
|
|
|
|
|
|
def test_full_moon_is_up_all_night_and_highest_near_solar_midnight():
|
|
full = nearest(datetime(2026, 10, 25, tzinfo=KST), True)
|
|
day = _night_of(full)
|
|
m = night(day, *SEOUL)
|
|
assert m.name == "보름달" and set(range(20, 29)) <= set(m.up_hours)
|
|
start = datetime.combine(day, datetime.min.time(), tzinfo=KST)
|
|
peak = max((start + timedelta(hours=22, minutes=10 * i) for i in range(24)), key=lambda t: altitude(t, *SEOUL))
|
|
assert 23 <= (peak.hour if peak.hour >= 12 else peak.hour + 24) <= 25
|
|
assert view_line(m, 0.0) == "밤새 잘 보여요"
|
|
assert view_line(m, 0.8) == "흐려서 구름에 가려요"
|
|
|
|
|
|
def test_first_quarter_sets_around_midnight_and_new_moon_is_not_seen():
|
|
new = nearest(datetime(2026, 10, 12, tzinfo=KST), False)
|
|
quarter = night(_night_of(new + timedelta(days=7.4)), *SEOUL)
|
|
assert quarter.set_at is not None and quarter.set_at.astimezone(KST).hour in (21, 22, 23, 0, 1, 2)
|
|
assert view_line(quarter, 0.0).endswith("까지 보여요")
|
|
assert view_line(night(_night_of(new), *SEOUL), 0.0) == "해와 같은 쪽에 있어 안 보여요"
|
|
hidden = MoonNight(name="초승달", lit=0.05, waxing=True, rise_at=None, set_at=None, up_hours=())
|
|
assert view_line(hidden, 0.0) == "해 진 뒤 곧 져서 밤엔 안 보여요"
|
|
assert view_line(replace(hidden, name="그믐달", waxing=False), 0.0) == "새벽 늦게 떠서 밤엔 안 보여요"
|
|
|
|
|
|
def test_waning_moon_rises_late():
|
|
full = nearest(datetime(2026, 10, 25, tzinfo=KST), True)
|
|
m = night(_night_of(full + timedelta(days=7.4)), *SEOUL)
|
|
assert m.rise_at is not None and m.rise_at.astimezone(KST).hour in (21, 22, 23, 0, 1, 2)
|
|
assert view_line(m, 0.0).endswith("에 떠요")
|