#!/usr/bin/env python3
"""
Test script for the NHL API client
"""
import json
from nhl_api_client import NHLAPIClient
def test_nhl_client():
"""Test the NHL API client with a few basic calls."""
client = NHLAPIClient()
print("Testing NHL API Client...")
print("=" * 50)
# Test 1: Get current standings
try:
print("1. Testing current standings...")
standings = client.get_standings_now()
print(f"✓ Successfully retrieved standings data")
if isinstance(standings, dict):
print(f" Response keys: {list(standings.keys())}")
else:
print(f" Response type: {type(standings)}")
except Exception as e:
print(f"✗ Failed to get standings: {e}")
print()
# Test 2: Get player spotlight
try:
print("2. Testing player spotlight...")
spotlight = client.get_player_spotlight()
print(f"✓ Successfully retrieved player spotlight")
if isinstance(spotlight, dict):
print(f" Response keys: {list(spotlight.keys())}")
elif isinstance(spotlight, list):
print(f" Response is a list with {len(spotlight)} items")
else:
print(f" Response type: {type(spotlight)}")
except Exception as e:
print(f"✗ Failed to get player spotlight: {e}")
print()
# Test 3: Get current scores
try:
print("3. Testing current scores...")
scores = client.get_daily_scores_now()
print(f"✓ Successfully retrieved current scores")
if isinstance(scores, dict):
print(f" Response keys: {list(scores.keys())}")
else:
print(f" Response type: {type(scores)}")
except Exception as e:
print(f"✗ Failed to get current scores: {e}")
print()
# Test 4: Get team codes utility
try:
print("4. Testing team codes...")
team_codes = ["ANA", "BOS", "TOR", "MTL", "NYR"] # Sample team codes
print(f"✓ Sample team codes: {team_codes}")
print(f" Season format: YYYYYYYY (e.g., 20232024 for 2023-24 season)")
print(f" Game types: 2=regular season, 3=playoffs")
except Exception as e:
print(f"✗ Failed to get team codes: {e}")
print()
# Test 5: Test a specific player query
try:
print("5. Testing specific player info (Connor McDavid - ID: 8478402)...")
player_info = client.get_player_info(8478402)
print(f"✓ Successfully retrieved player info")
if isinstance(player_info, dict):
print(f" Response keys: {list(player_info.keys())}")
if 'firstName' in player_info and 'lastName' in player_info:
print(f" Player: {player_info.get('firstName', '')} {player_info.get('lastName', '')}")
else:
print(f" Response type: {type(player_info)}")
except Exception as e:
print(f"✗ Failed to get player info: {e}")
print()
print("=" * 50)
print("NHL API Client test completed!")
if __name__ == "__main__":
test_nhl_client()