Files
swingmusic-extended/test_enhanced_spotify.py
T
Tomas Dvorak cbf646e25b Fix CI/CD pipeline and code quality issues
## Major Changes
- Fixed all TypeScript errors in web client for successful compilation
- Resolved 82+ Python lint errors across backend services
- Updated Flutter SDK compatibility for mobile app
- Fixed security workflow configuration

## Web Client Fixes
- Fixed import path in DragonflyDashboard.vue (dragonflyApi import)
- All TypeScript compilation now passes without errors

## Backend Lint Fixes
- Updated type annotations to modern Python syntax (dict instead of Dict, X | None instead of Optional[X])
- Replaced try-except-pass with contextlib.suppress(Exception)
- Removed unused imports (Dict, Optional, Any, Iterator, etc.)
- Fixed bare except clauses to use Exception
- Sorted and formatted imports with ruff
- Applied ruff format to 27 files

## Workflow Fixes
- Updated Flutter SDK constraint from ^3.10.4 to ^3.5.0 (compatible with Flutter 3.24.0)
- Changed pip-audit format from github to json in security.yml
- Added comprehensive CI workflows (readiness-gate.yml, security.yml)

## Infrastructure
- Added DragonflyDB caching system integration
- Enhanced Docker configuration with multi-stage builds
- Added pytest configuration and test infrastructure
- Improved production readiness with proper error handling

## Verification
- backend-lint job:  Succeeded
- web job:  Succeeded
- Ready for GitHub deployment

All CI/CD issues resolved. Codebase now passes all quality checks.
2026-03-21 10:01:14 +01:00

172 lines
5.5 KiB
Python

#!/usr/bin/env python3
"""
Test enhanced Spotify Web Player client with SpotiFLAC-style authentication
"""
import json
import logging
import sys
import os
# Add the src directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from swingmusic.services.spotify_web_player_client import get_spotify_web_player_client
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def test_track_lookup():
"""Test track lookup with enhanced client"""
logger.info("Testing enhanced Spotify Web Player client...")
client = get_spotify_web_player_client()
# Test track lookup
logger.info("Testing track lookup...")
track = client.get_track("4cOdK2wGLETOMrsVzAojDx") # Shape of You
if track:
logger.info("✅ Track lookup SUCCESS!")
logger.info(f"Track ID: {track.id}")
logger.info(f"Track Name: {track.name}")
logger.info(f"Artists: {[a.get('name', 'Unknown') for a in track.artists] if track.artists else 'None'}")
logger.info(f"Album: {track.album.get('name', 'Unknown') if track.album else 'None'}")
logger.info(f"Duration: {track.duration_ms}ms")
return True
else:
logger.error("❌ Track lookup FAILED")
return False
def test_album_lookup():
"""Test album lookup"""
logger.info("Testing album lookup...")
client = get_spotify_web_player_client()
album = client.get_album("1DFixLWUoKaZYxZkLUKQu9") # Divide
if album:
logger.info("✅ Album lookup SUCCESS!")
logger.info(f"Album ID: {album.id}")
logger.info(f"Album Name: {album.name}")
logger.info(f"Artists: {[a.get('name', 'Unknown') for a in album.artists] if album.artists else 'None'}")
logger.info(f"Total Tracks: {album.total_tracks}")
logger.info(f"Tracks: {len(album.tracks)}")
return True
else:
logger.error("❌ Album lookup FAILED")
return False
def test_artist_lookup():
"""Test artist lookup"""
logger.info("Testing artist lookup...")
client = get_spotify_web_player_client()
artist = client.get_artist("6eYc60kCoA2GEmdGGWrHdS") # Ed Sheeran
if artist:
logger.info("✅ Artist lookup SUCCESS!")
logger.info(f"Artist ID: {artist.id}")
logger.info(f"Artist Name: {artist.name}")
logger.info(f"Followers: {artist.followers}")
logger.info(f"Genres: {artist.genres}")
return True
else:
logger.error("❌ Artist lookup FAILED")
return False
def test_playlist_lookup():
"""Test playlist lookup"""
logger.info("Testing playlist lookup...")
client = get_spotify_web_player_client()
playlist = client.get_playlist("37i9dQZF1DXcBWIGoYBM5M") # Today's Top Hits
if playlist:
logger.info("✅ Playlist lookup SUCCESS!")
logger.info(f"Playlist ID: {playlist.id}")
logger.info(f"Playlist Name: {playlist.name}")
logger.info(f"Total Tracks: {playlist.total_tracks}")
logger.info(f"Tracks: {len(playlist.tracks)}")
return True
else:
logger.error("❌ Playlist lookup FAILED")
return False
def test_rate_limiting():
"""Test rate limiting with multiple requests"""
logger.info("Testing rate limiting with multiple requests...")
client = get_spotify_web_player_client()
# Make multiple rapid requests
track_ids = [
"4cOdK2wGLETOMrsVzAojDx", # Shape of You
"7qiZfU4dY1Kw1wLspXdn04", # Blinding Lights
"1nF1idY9ao7g8pdp5BlP0X", # Dance Monkey
]
success_count = 0
for i, track_id in enumerate(track_ids):
logger.info(f"Request {i+1}/{len(track_ids)}...")
track = client.get_track(track_id)
if track:
success_count += 1
logger.info(f" ✅ Got: {track.name}")
else:
logger.error(f" ❌ Failed to get track {track_id}")
logger.info(f"Rate limiting test: {success_count}/{len(track_ids)} successful")
return success_count == len(track_ids)
def main():
"""Run all tests"""
print("=" * 60)
print("Enhanced Spotify Web Player Client Test")
print("=" * 60)
tests = [
("Track Lookup", test_track_lookup),
("Album Lookup", test_album_lookup),
("Artist Lookup", test_artist_lookup),
("Playlist Lookup", test_playlist_lookup),
("Rate Limiting", test_rate_limiting),
]
results = {}
for test_name, test_func in tests:
print(f"\n{test_name}")
print("-" * 40)
try:
results[test_name] = test_func()
except Exception as e:
logger.error(f"Test {test_name} failed with exception: {e}")
results[test_name] = False
# Summary
print("\n" + "=" * 60)
print("Test Results Summary")
print("=" * 60)
for test_name, success in results.items():
status = "✅ PASS" if success else "❌ FAIL"
print(f"{test_name}: {status}")
total_tests = len(results)
passed_tests = sum(results.values())
print(f"\nOverall: {passed_tests}/{total_tests} tests passed")
if passed_tests == total_tests:
print("🎉 All tests passed! Enhanced client working perfectly.")
elif passed_tests > 0:
print("⚠️ Some tests passed, but there are issues to address.")
else:
print("❌ All tests failed. Major issues need to be resolved.")
print("=" * 60)
if __name__ == "__main__":
main()