fix(stock): 매매알람 이력 days 필터 포맷을 ISO로 통일 (경계일 과다포함 수정, 리뷰 Important)
This commit is contained in:
@@ -31,3 +31,18 @@ def test_alert_history_records_and_reads(db):
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["ticker"] == "005930" and rows[0]["kind"] == "buy"
|
||||
assert rows[0]["detail"]["vol"] == 2.1
|
||||
|
||||
def test_alert_history_days_filter_format_consistency(db):
|
||||
"""fired_at은 ISO(T/Z)로 저장 — 필터도 ISO여야 경계일 비교가 정확.
|
||||
7일 경계 밖(정확히 7일 전 자정) 레코드는 제외되어야 한다. 포맷 불일치면 잘못 포함됨."""
|
||||
db.add_alert_history("005930", "삼성", "buy", "buy_breakout", 71500, {}) # now
|
||||
conn = sqlite3.connect(db.DB_PATH)
|
||||
conn.execute(
|
||||
"INSERT INTO trade_alert_history(ticker,name,kind,condition,price,detail_json,fired_at) "
|
||||
"VALUES('000660','SK','sell','sell_stop_loss',60000,'{}', "
|
||||
"strftime('%Y-%m-%dT%H:%M:%fZ','now','-7 days','start of day'))"
|
||||
)
|
||||
conn.commit(); conn.close()
|
||||
tickers = [r["ticker"] for r in db.get_alert_history(days=7)]
|
||||
assert "005930" in tickers
|
||||
assert "000660" not in tickers
|
||||
|
||||
Reference in New Issue
Block a user