Files
auto-stock/tests/test_volume_overflow.py

53 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""
Verify that StockAnalysis and MarketData volume columns can handle values larger
than 2**31-1. This script will fail prior to applying the bigint migration.
"""
import asyncio
from datetime import date
from app.core.database import AsyncSessionLocal
from app.models.models import StockAnalysis, MarketData
async def test_big_volume():
async with AsyncSessionLocal() as session:
# create and commit a record with a large volume value
huge_vol = 2962426126 # value that previously triggered overflow
sa = StockAnalysis(
stock_code="TEST",
stock_name="Test Corp",
analysis_date=date.today(),
current_price=100,
change_rate=0,
volume=huge_vol,
)
session.add(sa)
# also test MarketData
md = MarketData(
stock_code="TEST",
price=100,
change_rate=0,
volume=huge_vol,
)
session.add(md)
await session.commit()
print("Inserted records with large volume successfully")
# fetch back and verify
fetched_sa = await session.get(StockAnalysis, sa.id)
fetched_md = await session.get(MarketData, md.id)
print("StockAnalysis volume type:", type(fetched_sa.volume), fetched_sa.volume)
print("MarketData volume type:", type(fetched_md.volume), fetched_md.volume)
assert fetched_sa.volume == huge_vol
assert fetched_md.volume == huge_vol
if __name__ == "__main__":
asyncio.run(test_big_volume())