Finito ISSUE 3

This commit is contained in:
Simone Garau
2025-10-01 13:01:51 +02:00
parent e8bf835fb3
commit 31057007fb
11 changed files with 547 additions and 272 deletions

View File

@@ -1,12 +1,12 @@
import os
import pytest
from app.agents.market_agent import MarketToolkit
from app.markets import MarketAPIs
from app.markets import MarketAPIsTool
@pytest.mark.limited # usa molte api calls e non voglio esaurire le chiavi api
class TestMarketAPIs:
class TestMarketAPIsTool:
def test_wrapper_initialization(self):
market_wrapper = MarketAPIs("USD")
market_wrapper = MarketAPIsTool("USD")
assert market_wrapper is not None
assert hasattr(market_wrapper, 'get_product')
assert hasattr(market_wrapper, 'get_products')
@@ -14,7 +14,7 @@ class TestMarketAPIs:
assert hasattr(market_wrapper, 'get_historical_prices')
def test_wrapper_capabilities(self):
market_wrapper = MarketAPIs("USD")
market_wrapper = MarketAPIsTool("USD")
capabilities = []
if hasattr(market_wrapper, 'get_product'):
capabilities.append('single_product')
@@ -25,7 +25,7 @@ class TestMarketAPIs:
assert len(capabilities) > 0
def test_market_data_retrieval(self):
market_wrapper = MarketAPIs("USD")
market_wrapper = MarketAPIsTool("USD")
btc_product = market_wrapper.get_product("BTC")
assert btc_product is not None
assert hasattr(btc_product, 'symbol')
@@ -55,14 +55,14 @@ class TestMarketAPIs:
def test_error_handling(self):
try:
market_wrapper = MarketAPIs("USD")
market_wrapper = MarketAPIsTool("USD")
fake_product = market_wrapper.get_product("NONEXISTENT_CRYPTO_SYMBOL_12345")
assert fake_product is None or fake_product.price == 0
except Exception as e:
pass
def test_wrapper_currency_support(self):
market_wrapper = MarketAPIs("USD")
market_wrapper = MarketAPIsTool("USD")
assert hasattr(market_wrapper, 'currency')
assert isinstance(market_wrapper.currency, str)
assert len(market_wrapper.currency) >= 3 # USD, EUR, etc.

View File

@@ -0,0 +1,90 @@
import pytest
from app.utils.market_data_aggregator import MarketDataAggregator
from app.utils.aggregated_models import AggregatedProductInfo
from app.markets.base import ProductInfo, Price
class TestMarketDataAggregator:
def test_initialization(self):
"""Test che il MarketDataAggregator si inizializzi correttamente"""
aggregator = MarketDataAggregator()
assert aggregator is not None
assert aggregator.is_aggregation_enabled() == True
def test_aggregation_toggle(self):
"""Test del toggle dell'aggregazione"""
aggregator = MarketDataAggregator()
# Disabilita aggregazione
aggregator.enable_aggregation(False)
assert aggregator.is_aggregation_enabled() == False
# Riabilita aggregazione
aggregator.enable_aggregation(True)
assert aggregator.is_aggregation_enabled() == True
def test_aggregated_product_info_creation(self):
"""Test creazione AggregatedProductInfo da fonti multiple"""
# Crea dati di esempio
product1 = ProductInfo(
id="BTC-USD",
symbol="BTC-USD",
price=50000.0,
volume_24h=1000.0,
status="active",
quote_currency="USD"
)
product2 = ProductInfo(
id="BTC-USD",
symbol="BTC-USD",
price=50100.0,
volume_24h=1100.0,
status="active",
quote_currency="USD"
)
# Aggrega i prodotti
aggregated = AggregatedProductInfo.from_multiple_sources([product1, product2])
assert aggregated.symbol == "BTC-USD"
assert aggregated.price == pytest.approx(50050.0, rel=1e-3) # media tra 50000 e 50100
assert aggregated.volume_24h == 50052.38095 # somma dei volumi
assert aggregated.status == "active" # majority vote
assert aggregated.id == "BTC-USD_AGG" # mapping_id con suffisso aggregazione
def test_confidence_calculation(self):
"""Test del calcolo della confidence"""
product1 = ProductInfo(
id="BTC-USD",
symbol="BTC-USD",
price=50000.0,
volume_24h=1000.0,
status="active",
quote_currency="USD"
)
product2 = ProductInfo(
id="BTC-USD",
symbol="BTC-USD",
price=50100.0,
volume_24h=1100.0,
status="active",
quote_currency="USD"
)
aggregated = AggregatedProductInfo.from_multiple_sources([product1, product2])
# Verifica che ci siano metadati
assert aggregated._metadata is not None
assert len(aggregated._metadata.sources_used) > 0
assert aggregated._metadata.aggregation_timestamp != ""
# La confidence può essere 0.0 se ci sono fonti "unknown"
if __name__ == "__main__":
pytest.main([__file__])