galaxis-po/backend/tests/unit/test_index_collector.py

27 lines
758 B
Python
Raw Normal View History

"""Unit tests for IndexCollector."""
from unittest.mock import patch
import pandas as pd
from app.services.collectors.index_collector import IndexCollector
def make_mock_df():
data = {
"시가": [2500.0],
"고가": [2550.0],
"저가": [2480.0],
"종가": [2520.0],
"거래량": [500000000],
"거래대금": [5000000000000],
}
df = pd.DataFrame(data, index=pd.DatetimeIndex([pd.Timestamp("2024-01-02")], name="날짜"))
return df
def test_index_collector_collect(db):
with patch("pykrx.stock.get_index_ohlcv", return_value=make_mock_df()):
collector = IndexCollector(db, start_date="20240102", end_date="20240102")
count = collector.collect()
assert count >= 1