"""Test Symbol, Stock, and Coin class construction.""" from unittest.mock import patch import pandas as pd from common.Symbol import Symbol, Stock, Coin class TestSymbol: """Test base Symbol class.""" def test_symbol_creation(self): """Test basic Symbol creation.""" symbol = Symbol("TEST") assert symbol.symbol == "TEST" assert symbol.id == "TEST" assert symbol.name == "TEST" def test_symbol_currency_default(self): """Test that currency defaults to USD.""" symbol = Symbol("TEST") assert symbol.currency == "usd" class TestStock: """Test Stock class functionality.""" def test_stock_creation(self): """Test Stock object creation with proper dictionary structure.""" stock_info = {"ticker": "AAPL", "title": "Apple Inc.", "mkt_cap_rank": 1} stock = Stock(stock_info) assert stock.symbol == "AAPL" assert stock.id == "AAPL" assert stock.name == "Apple Inc." assert stock.tag == "$AAPL" assert stock.market_cap_rank == 1 # Verify inheritance assert isinstance(stock, Symbol) assert isinstance(stock, Stock) def test_stock_with_different_data(self): """Test Stock creation with different stock data.""" stock_info = {"ticker": "TSLA", "title": "Tesla, Inc.", "mkt_cap_rank": 5} stock = Stock(stock_info) assert stock.symbol == "TSLA" assert stock.id == "TSLA" assert stock.name == "Tesla, Inc." assert stock.tag == "$TSLA" assert stock.market_cap_rank == 5 def test_stock_tag_format(self): """Test that stock tags are properly formatted with $ prefix.""" stock_info = {"ticker": "NVDA", "title": "NVIDIA Corporation", "mkt_cap_rank": 3} stock = Stock(stock_info) assert stock.tag == "$NVDA" assert stock.tag.startswith("$") class TestCoin: """Test Coin class functionality.""" def test_coin_creation_single_row(self): """Test Coin object creation with single row DataFrame.""" coin_data = pd.DataFrame({"symbol": ["btc"], "id": ["bitcoin"], "name": ["Bitcoin"], "type_id": ["$$btc"]}) coin = Coin(coin_data) assert coin.symbol == "btc" assert coin.id == "bitcoin" assert coin.name == "Bitcoin" assert coin.tag == "$$BTC" # Verify inheritance assert isinstance(coin, Symbol) assert isinstance(coin, Coin) def test_coin_creation_ethereum(self): """Test Coin creation with Ethereum data.""" coin_data = pd.DataFrame({"symbol": ["eth"], "id": ["ethereum"], "name": ["Ethereum"], "type_id": ["$$eth"]}) coin = Coin(coin_data) assert coin.symbol == "eth" assert coin.id == "ethereum" assert coin.name == "Ethereum" assert coin.tag == "$$ETH" def test_coin_multiple_rows_takes_first(self): """Test that when multiple rows exist, only the first is used.""" coin_data = pd.DataFrame( { "symbol": ["btc", "btc2"], "id": ["bitcoin", "bitcoin-cash"], "name": ["Bitcoin", "Bitcoin Cash"], "type_id": ["$$btc", "$$bch"], } ) # Mock the head method to return first row with patch.object(coin_data, "head") as mock_head: first_row = pd.DataFrame({"symbol": ["btc"], "id": ["bitcoin"], "name": ["Bitcoin"], "type_id": ["$$btc"]}) mock_head.return_value = first_row coin = Coin(coin_data) mock_head.assert_called_once_with(1) # The coin should use the first row data assert coin.symbol == "btc" assert coin.id == "bitcoin" def test_coin_tag_uppercase(self): """Test that coin tags are properly uppercased.""" coin_data = pd.DataFrame({"symbol": ["ada"], "id": ["cardano"], "name": ["Cardano"], "type_id": ["$$ada"]}) coin = Coin(coin_data) assert coin.tag == "$$ADA" assert coin.tag.isupper() def test_coin_dataframe_access(self): """Test that coin properly accesses DataFrame values.""" coin_data = pd.DataFrame({"symbol": ["dot"], "id": ["polkadot"], "name": ["Polkadot"], "type_id": ["$$dot"]}) coin = Coin(coin_data) # Test that values are extracted correctly from DataFrame assert isinstance(coin.symbol, str) assert isinstance(coin.id, str) assert isinstance(coin.name, str) assert isinstance(coin.tag, str)