@@ -7,32 +7,35 @@ def test_db_ohlc_lifecycle(test_db):
77 Scrive OHLC, legge OHLC e verifica.
88 Usa il DB reale (che viene pulito dalla fixture).
99 """
10- # 1. Prepare Data
11- # Tuple: (ticker, date, open, high, low, close, volume)
10+ # Calcoliamo date dinamiche
11+ today = date .today ()
12+ yesterday = today - timedelta (days = 1 )
13+ two_days_ago = today - timedelta (days = 2 )
14+
15+ # 1. Prepare Data (Usiamo le date calcolate)
1216 raw_data = [
13- ("TEST_A" , date ( 2024 , 1 , 1 ) , 100 , 110 , 90 , 105 , 1000 ),
14- ("TEST_A" , date ( 2024 , 1 , 2 ), 105 , 115 , 95 , 110 , 2000 ),
15- ("TEST_B" , date ( 2024 , 1 , 1 ), 50 , 55 , 45 , 52 , 500 )
17+ ("TEST_A" , two_days_ago , 100 , 110 , 90 , 105 , 1000 ),
18+ ("TEST_A" , yesterday , 105 , 115 , 95 , 110 , 2000 ),
19+ ("TEST_B" , two_days_ago , 50 , 55 , 45 , 52 , 500 )
1620 ]
1721
1822 # 2. Insert (Upsert)
1923 test_db .upsert_ohlc (raw_data )
2024
2125 fetched = test_db .get_ohlc (["TEST_A" ], "2024-01-01" , "2024-01-05" )
2226
23- # 3. Retrieve
24- # Chiediamo solo TEST_A
25- fetched = test_db .get_ohlc (["TEST_A" ], "2024-01-01" , "2024-01-05" )
27+ ## 3. Retrieve (Range specifico)
28+ # Convertiamo le date in stringa ISO per sicurezza nella query
29+ fetched = test_db .get_ohlc (["TEST_A" ], two_days_ago . isoformat (), today . isoformat () )
2630
2731 assert len (fetched ) == 2
2832 assert fetched [0 ]['ticker' ] == "TEST_A"
29- assert float (fetched [0 ]['close' ]) == 105.0 # Postgres torna Decimal, convertiamo o confrontiamo bene
33+ assert float (fetched [0 ]['close' ]) == 105.0
3034
31- # Chiediamo tutti gli storici
35+ # 4. Retrieve ALL (Il punto che falliva)
36+ # Ora funzionerà perché i dati sono di "ieri", quindi sicuramente negli ultimi 365 giorni
3237 all_data_map = test_db .get_ohlc_all_tickers (days = 365 )
3338
34- print (f"DEBUG FETCHED: { all_data_map } " )
35-
3639 assert "TEST_A" in all_data_map
3740 assert "TEST_B" in all_data_map
3841 assert len (all_data_map ["TEST_A" ]) == 2
0 commit comments