import sys import unittest from datetime import date from pathlib import Path from unittest.mock import patch SCRIPTS = Path(__file__).resolve().parents[1] sys.path.insert(0, str(SCRIPTS)) import ipo_alert class IpoAlertTests(unittest.TestCase): def setUp(self): self.row = { 'ipoCode': 'A250030', 'compName': '진코스텍', 'poStartDate': '2026-10-02', 'poEndDate': '2026-10-06', 'lcalDate': '2026-10-15', 'fixPubPrice': '23500', 'orgNm': '하나증권', } self.detail = { 'ipoInfo': { 'compName': '진코스텍', 'poStartDate': '2026-10-02', 'poEndDate': '2026-10-06', 'lcalDate': '2026-10-15', }, 'registrationStatement': {'sbscMrgnRatio': '50.00'}, 'demandForecastingResult': {'fixPubPrice': '23500'}, 'joinManagers': [{'orgNm': '하나증권', 'sbscMinNum': '10'}], } def test_subscription_format_uses_first_day_and_minimum_cash(self): text = ipo_alert.format_alert('subscription', self.row, self.detail) self.assertIn('종목명 : 진코스텍', text) self.assertIn('증권사 : 하나증권', text) self.assertIn('청약일 : 2026-10-02 ~ 2026-10-06', text) self.assertIn('증거금 : 117,500원(최소 10주)', text) self.assertNotIn('23,500원', text) self.assertNotIn('50%', text) self.assertIn('수수료 2,000원(온라인 일반 기준)', text) def test_listing_uses_listing_date(self): text = ipo_alert.format_alert('listing', self.row, self.detail) self.assertIn('[신규 상장]', text) self.assertIn('상장일 : 2026-10-15', text) def test_collect_subscription_matches_only_first_day(self): payload = { 'examinationList': [], 'demandForecastingList': [], 'forecastingCompleteList': [], 'subscriptionList': [self.row], 'subscriptionCompleteList': [], 'listingList': [], } with patch.object(ipo_alert, 'fetch', return_value=ipo_alert.json.dumps(payload)), patch.object( ipo_alert, '_detail', return_value=self.detail ): first = ipo_alert.collect_for_date('subscription', date(2026, 10, 2)) second = ipo_alert.collect_for_date('subscription', date(2026, 10, 3)) self.assertEqual(len(first), 1) self.assertEqual(second, []) if __name__ == '__main__': unittest.main()