Refactor test cases for improved readability and consistency
- Adjusted function signatures in various test files to enhance clarity by aligning parameters. - Updated patching syntax for better readability across test cases. - Improved formatting and spacing in test assertions and mock setups. - Ensured consistent use of async/await patterns in async test functions. - Enhanced comments for better understanding of test intentions.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Tests for playlist API endpoints."""
|
||||
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from httpx import AsyncClient
|
||||
@@ -348,7 +347,8 @@ class TestPlaylistEndpoints:
|
||||
}
|
||||
|
||||
response = await authenticated_client.put(
|
||||
f"/api/v1/playlists/{playlist_id}", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -386,7 +386,8 @@ class TestPlaylistEndpoints:
|
||||
payload = {"name": "Updated Playlist", "description": "Updated description"}
|
||||
|
||||
response = await authenticated_client.put(
|
||||
f"/api/v1/playlists/{playlist_id}", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -613,7 +614,8 @@ class TestPlaylistEndpoints:
|
||||
payload = {"sound_id": sound_id}
|
||||
|
||||
response = await authenticated_client.post(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -670,7 +672,8 @@ class TestPlaylistEndpoints:
|
||||
payload = {"sound_id": sound_id, "position": 5}
|
||||
|
||||
response = await authenticated_client.post(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -718,13 +721,15 @@ class TestPlaylistEndpoints:
|
||||
|
||||
# Add sound first time
|
||||
response = await authenticated_client.post(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds",
|
||||
json=payload,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Try to add same sound again
|
||||
response = await authenticated_client.post(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds",
|
||||
json=payload,
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert "already in this playlist" in response.json()["detail"]
|
||||
@@ -758,7 +763,8 @@ class TestPlaylistEndpoints:
|
||||
payload = {"sound_id": 99999}
|
||||
|
||||
response = await authenticated_client.post(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
assert response.status_code == 404
|
||||
@@ -806,7 +812,8 @@ class TestPlaylistEndpoints:
|
||||
# Add sound first
|
||||
payload = {"sound_id": sound_id}
|
||||
await authenticated_client.post(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
# Remove sound
|
||||
@@ -918,11 +925,15 @@ class TestPlaylistEndpoints:
|
||||
# Reorder sounds - use positions that don't cause constraints
|
||||
# When swapping, we need to be careful about unique constraints
|
||||
payload = {
|
||||
"sound_positions": [[sound1_id, 10], [sound2_id, 5]], # Use different positions to avoid constraints
|
||||
"sound_positions": [
|
||||
[sound1_id, 10],
|
||||
[sound2_id, 5],
|
||||
], # Use different positions to avoid constraints
|
||||
}
|
||||
|
||||
response = await authenticated_client.put(
|
||||
f"/api/v1/playlists/{playlist_id}/sounds/reorder", json=payload,
|
||||
f"/api/v1/playlists/{playlist_id}/sounds/reorder",
|
||||
json=payload,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user