"""Tests for exchange factory."""

import pytest
from unittest.mock import patch, Mock
from src.exchanges.factory import ExchangeFactory
from src.exchanges.coinbase import CoinbaseExchange


class TestExchangeFactory:
    """Tests for ExchangeFactory."""
    
    def test_register_exchange(self):
        """Test exchange registration."""
        ExchangeFactory.register_exchange("test_exchange", CoinbaseExchange)
        assert "test_exchange" in ExchangeFactory.list_available()
    
    def test_get_exchange(self):
        """Test getting exchange instance."""
        with patch('src.exchanges.factory.get_key_manager') as mock_km:
            mock_km.return_value.get_exchange_keys.return_value = {
                'api_key': 'test_key',
                'secret_key': 'test_secret',
                'permissions': 'read_only'
            }
            
            exchange = ExchangeFactory.get_exchange("coinbase")
            assert exchange is not None
            assert isinstance(exchange, CoinbaseExchange)
    
    def test_get_nonexistent_exchange(self):
        """Test getting non-existent exchange."""
        with pytest.raises(ValueError, match="not registered"):
            ExchangeFactory.get_exchange("nonexistent")
    
    def test_list_available(self):
        """Test listing available exchanges."""
        exchanges = ExchangeFactory.list_available()
        assert isinstance(exchanges, list)
        assert "coinbase" in exchanges

