Files
swingmusic-extended/test_valid_track.py
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

155 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""
Test with valid track IDs and check what SpotiFLAC uses
"""
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'))
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def test_valid_tracks():
"""Test with known valid track IDs"""
logger.info("Testing with valid track IDs...")
try:
from swingmusic.services.spotify_web_player_client import get_spotify_web_player_client
client = get_spotify_web_player_client()
# Try some popular, current tracks
test_tracks = [
"4iV5W9uYEdYUVa79Axb7Rh", # "Blinding Lights" - The Weeknd
"5A0JkUj1sQjcxuhQsLtbCs", # "Flowers" - Miley Cyrus
"7qk1KxQ2qVxQaL4x1x2qYc", # "Anti-Hero" - Taylor Swift
"2XoaZweJkkKtR2AqI2x2hN", # "As It Was" - Harry Styles
]
for track_id in test_tracks:
logger.info(f"Testing track ID: {track_id}")
track = client.get_track(track_id)
if track and track.name:
logger.info(f"✅ SUCCESS: {track.name}")
logger.info(f" Artists: {[a.get('name', 'Unknown') for a in track.artists] if track.artists else 'None'}")
logger.info(f" Duration: {track.duration_ms}ms")
return True
else:
logger.info(f"❌ No data for track {track_id}")
return False
except Exception as e:
logger.error(f"Test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_spotiflac_endpoint():
"""Test using the exact same endpoint as SpotiFLAC"""
logger.info("Testing SpotiFLAC-style endpoint...")
try:
from swingmusic.services.spotify_web_player_client import get_spotify_web_player_client
client = get_spotify_web_player_client()
# Use the exact same payload structure as SpotiFLAC
payload = {
"variables": {
"uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" # Blinding Lights
},
"operationName": "getTrack",
"extensions": {
"persistedQuery": {
"version": 1,
"sha256Hash": "612585ae06ba435ad26369870deaae23b5c8800a256cd8a57e08eddc25a37294"
}
}
}
headers = {
"Authorization": f"Bearer {client._token.access_token}",
"Client-Token": client._token.client_token,
"Spotify-App-Version": client._token.client_version,
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36",
}
# Try both v1 and v2 endpoints
for version in ["v1", "v2"]:
url = f"https://api-partner.spotify.com/pathfinder/{version}/query"
logger.info(f"Trying {url}...")
response = client.session.post(url, json=payload, headers=headers, timeout=30)
logger.info(f"Response status: {response.status_code}")
if response.status_code == 200:
data = response.json()
logger.info(f"{version} API response received")
# Check the data structure
if "data" in data:
track_data = data["data"].get("trackUnion", {})
if track_data.get("__typename") == "Track":
logger.info(f"✅ Found track: {track_data.get('name')}")
logger.info(f" Full data keys: {list(track_data.keys())}")
return True
elif track_data.get("__typename") == "NotFound":
logger.warning(f"⚠️ Track not found: {track_data.get('message')}")
else:
logger.warning(f"⚠️ Unexpected type: {track_data.get('__typename')}")
logger.info(f" Available keys: {list(track_data.keys())}")
else:
logger.warning(f"⚠️ No data key in response")
logger.info(f" Available keys: {list(data.keys())}")
else:
logger.error(f"{version} API failed: {response.status_code}")
logger.error(f" Response: {response.text[:200]}")
return False
except Exception as e:
logger.error(f"Test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
print("=" * 60)
print("Valid Track ID Test")
print("=" * 60)
# Test 1: Valid track IDs
print("\n1. Testing Valid Track IDs")
print("-" * 40)
success1 = test_valid_tracks()
# Test 2: SpotiFLAC endpoint
print("\n2. Testing SpotiFLAC Endpoint")
print("-" * 40)
success2 = test_spotiflac_endpoint()
# Summary
print("\n" + "=" * 60)
print("Test Results Summary")
print("=" * 60)
print(f"Valid Track IDs: {'✅ WORKING' if success1 else '❌ FAILED'}")
print(f"SpotiFLAC Endpoint: {'✅ WORKING' if success2 else '❌ FAILED'}")
if success1 or success2:
print("✅ Real data retrieval is working!")
else:
print("❌ Real data retrieval needs fixes")
print("=" * 60)
if __name__ == "__main__":
main()