prod: UI Optimisée mise en production
- Documentation archivée et réorganisée - Backend: Ajout tests, migrations, library service, rate limiting - Frontend: Suppression Flutter, focus sur interface web HTML/JS - Tailwind CSS ajouté pour le style - Améliorations UX et corrections bugs Generated with [Claude Code](https://claude.com/claude-code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
"""Test library endpoints."""
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class TestLibraryEndpoints:
|
||||
"""Tests for /api/v1/library/* endpoints."""
|
||||
|
||||
async def test_get_empty_liked_tracks(self, client: AsyncClient, auth_headers: dict):
|
||||
"""Test getting liked tracks when empty."""
|
||||
response = await client.get("/api/v1/library/liked-tracks", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 0
|
||||
|
||||
async def test_like_track(self, client: AsyncClient, auth_headers: dict, sample_track_data):
|
||||
"""Test liking a track."""
|
||||
# Create a track first
|
||||
track_response = await client.post(
|
||||
"/api/v1/music/tracks",
|
||||
json=sample_track_data,
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert track_response.status_code == 200
|
||||
track = track_response.json()
|
||||
|
||||
# Like the track
|
||||
response = await client.post(
|
||||
f"/api/v1/library/liked-tracks/{track['id']}",
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["track_id"] == track["id"]
|
||||
|
||||
async def test_get_liked_tracks(self, client: AsyncClient, auth_headers: dict, sample_track_data):
|
||||
"""Test getting liked tracks."""
|
||||
# Create and like a track
|
||||
track_response = await client.post(
|
||||
"/api/v1/music/tracks",
|
||||
json=sample_track_data,
|
||||
headers=auth_headers,
|
||||
)
|
||||
track = track_response.json()
|
||||
|
||||
await client.post(
|
||||
f"/api/v1/library/liked-tracks/{track['id']}",
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
# Get liked tracks
|
||||
response = await client.get("/api/v1/library/liked-tracks", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 1
|
||||
assert data[0]["track_id"] == track["id"]
|
||||
|
||||
async def test_unlike_track(self, client: AsyncClient, auth_headers: dict, sample_track_data):
|
||||
"""Test unliking a track."""
|
||||
# Create and like a track
|
||||
track_response = await client.post(
|
||||
"/api/v1/music/tracks",
|
||||
json=sample_track_data,
|
||||
headers=auth_headers,
|
||||
)
|
||||
track = track_response.json()
|
||||
|
||||
await client.post(
|
||||
f"/api/v1/library/liked-tracks/{track['id']}",
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
# Unlike the track
|
||||
response = await client.delete(
|
||||
f"/api/v1/library/liked-tracks/{track['id']}",
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
async def test_get_listening_history_empty(self, client: AsyncClient, auth_headers: dict):
|
||||
"""Test getting listening history when empty."""
|
||||
response = await client.get("/api/v1/library/history", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 0
|
||||
|
||||
async def test_add_to_listening_history(self, client: AsyncClient, auth_headers: dict, sample_track_data):
|
||||
"""Test adding to listening history."""
|
||||
# Create a track first
|
||||
track_response = await client.post(
|
||||
"/api/v1/music/tracks",
|
||||
json=sample_track_data,
|
||||
headers=auth_headers,
|
||||
)
|
||||
track = track_response.json()
|
||||
|
||||
# Add to history
|
||||
response = await client.post(
|
||||
"/api/v1/library/history",
|
||||
headers=auth_headers,
|
||||
json={
|
||||
"track_id": track["id"],
|
||||
"played_for": 30,
|
||||
"completed": False,
|
||||
"source": "test",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert data["track_id"] == track["id"]
|
||||
assert data["played_for"] == 30
|
||||
|
||||
async def test_get_library_stats(self, client: AsyncClient, auth_headers: dict):
|
||||
"""Test getting library statistics."""
|
||||
response = await client.get("/api/v1/library/stats", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "liked_tracks_count" in data
|
||||
assert "total_plays" in data
|
||||
assert data["liked_tracks_count"] >= 0
|
||||
Reference in New Issue
Block a user