fix: Add missing commas in function calls and improve code formatting
Some checks failed
Backend CI / lint (push) Failing after 4m51s
Backend CI / test (push) Successful in 4m19s

This commit is contained in:
JSC
2025-08-12 23:37:38 +02:00
parent d3d7edb287
commit f094fbf140
18 changed files with 135 additions and 133 deletions

View File

@@ -1,6 +1,6 @@
"""Tests for admin user endpoints."""
from unittest.mock import AsyncMock, Mock, patch
from unittest.mock import Mock, patch
import pytest
from httpx import AsyncClient
@@ -76,9 +76,9 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_regular = type("User", (), {
"id": regular_user.id,
"email": regular_user.email,
@@ -93,9 +93,9 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_get_all.return_value = [mock_admin, mock_regular]
response = await authenticated_admin_client.get("/api/v1/admin/users/")
@@ -130,7 +130,7 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_get_all.return_value = [mock_admin]
@@ -185,7 +185,7 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_get_by_id.return_value = mock_user
@@ -244,9 +244,9 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
updated_mock = type("User", (), {
"id": regular_user.id,
"email": regular_user.email,
@@ -261,9 +261,9 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_get_by_id.return_value = mock_user
mock_update.return_value = updated_mock
@@ -278,7 +278,7 @@ class TestAdminUserEndpoints:
"name": "Updated Name",
"credits": 200,
"plan_id": 1,
}
},
)
assert response.status_code == 200
@@ -299,7 +299,7 @@ class TestAdminUserEndpoints:
):
response = await authenticated_admin_client.patch(
"/api/v1/admin/users/999",
json={"name": "Updated Name"}
json={"name": "Updated Name"},
)
assert response.status_code == 404
@@ -333,12 +333,12 @@ class TestAdminUserEndpoints:
"id": 1,
"name": "Basic",
"max_credits": 100,
})()
})(),
})()
mock_get_by_id.return_value = mock_user
response = await authenticated_admin_client.patch(
"/api/v1/admin/users/2",
json={"plan_id": 999}
json={"plan_id": 999},
)
assert response.status_code == 404
@@ -373,7 +373,7 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_get_by_id.return_value = mock_user
mock_update.return_value = mock_user
@@ -438,7 +438,7 @@ class TestAdminUserEndpoints:
"id": test_plan.id,
"name": test_plan.name,
"max_credits": test_plan.max_credits,
})()
})(),
})()
mock_get_by_id.return_value = mock_disabled_user
mock_update.return_value = mock_disabled_user
@@ -487,4 +487,4 @@ class TestAdminUserEndpoints:
data = response.json()
assert len(data) == 2
assert data[0]["name"] == "Basic"
assert data[1]["name"] == "Premium"
assert data[1]["name"] == "Premium"

View File

@@ -1,5 +1,6 @@
"""Tests for authentication endpoints."""
from datetime import UTC
from typing import Any
from unittest.mock import patch
@@ -495,7 +496,7 @@ class TestAuthEndpoints:
response = await test_client.post(
"/api/v1/auth/refresh",
cookies={"refresh_token": "valid_refresh_token"}
cookies={"refresh_token": "valid_refresh_token"},
)
assert response.status_code == 200
@@ -520,7 +521,7 @@ class TestAuthEndpoints:
response = await test_client.post(
"/api/v1/auth/refresh",
cookies={"refresh_token": "valid_refresh_token"}
cookies={"refresh_token": "valid_refresh_token"},
)
assert response.status_code == 500
@@ -536,7 +537,7 @@ class TestAuthEndpoints:
"""Test OAuth token exchange with invalid code."""
response = await test_client.post(
"/api/v1/auth/exchange-oauth-token",
json={"code": "invalid_code"}
json={"code": "invalid_code"},
)
assert response.status_code == 400
@@ -565,7 +566,7 @@ class TestAuthEndpoints:
is_active=test_user.is_active,
)
mock_update.return_value = updated_user
# Mock the user_to_response to return UserResponse format
from app.schemas.auth import UserResponse
mock_user_to_response.return_value = UserResponse(
@@ -589,7 +590,7 @@ class TestAuthEndpoints:
response = await test_client.patch(
"/api/v1/auth/me",
json={"name": "Updated Name"},
cookies=auth_cookies
cookies=auth_cookies,
)
assert response.status_code == 200
@@ -601,7 +602,7 @@ class TestAuthEndpoints:
"""Test update profile without authentication."""
response = await test_client.patch(
"/api/v1/auth/me",
json={"name": "Updated Name"}
json={"name": "Updated Name"},
)
assert response.status_code == 401
@@ -621,9 +622,9 @@ class TestAuthEndpoints:
"/api/v1/auth/change-password",
json={
"current_password": "old_password",
"new_password": "new_password"
"new_password": "new_password",
},
cookies=auth_cookies
cookies=auth_cookies,
)
assert response.status_code == 200
@@ -637,8 +638,8 @@ class TestAuthEndpoints:
"/api/v1/auth/change-password",
json={
"current_password": "old_password",
"new_password": "new_password"
}
"new_password": "new_password",
},
)
assert response.status_code == 401
@@ -652,9 +653,10 @@ class TestAuthEndpoints:
) -> None:
"""Test get user OAuth providers success."""
with patch("app.services.auth.AuthService.get_user_oauth_providers") as mock_providers:
from datetime import datetime
from app.models.user_oauth import UserOauth
from datetime import datetime, timezone
mock_oauth_google = UserOauth(
id=1,
user_id=test_user.id,
@@ -662,34 +664,34 @@ class TestAuthEndpoints:
provider_user_id="google123",
email="test@example.com",
name="Test User",
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
created_at=datetime.now(UTC),
updated_at=datetime.now(UTC),
)
mock_oauth_github = UserOauth(
id=2,
user_id=test_user.id,
provider="github",
provider="github",
provider_user_id="github456",
email="test@example.com",
name="Test User",
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
created_at=datetime.now(UTC),
updated_at=datetime.now(UTC),
)
mock_providers.return_value = [mock_oauth_google, mock_oauth_github]
response = await test_client.get(
"/api/v1/auth/user-providers",
cookies=auth_cookies
cookies=auth_cookies,
)
assert response.status_code == 200
data = response.json()
assert len(data) == 3 # password + 2 OAuth providers
# Check password provider (first)
assert data[0]["provider"] == "password"
assert data[0]["display_name"] == "Password"
# Check OAuth providers
assert data[1]["provider"] == "google"
assert data[1]["display_name"] == "Google"

View File

@@ -529,7 +529,7 @@ class TestPlaylistRepository:
)
test_session.add(sound)
sounds.append(sound)
await test_session.commit()
await test_session.refresh(playlist)
for sound in sounds:
@@ -547,7 +547,7 @@ class TestPlaylistRepository:
# Verify the final positions
playlist_sounds = await playlist_repository.get_playlist_sound_entries(playlist_id)
assert len(playlist_sounds) == 3
assert playlist_sounds[0].sound_id == sound_ids[0] # Original sound 0 stays at position 0
assert playlist_sounds[0].position == 0
@@ -605,7 +605,7 @@ class TestPlaylistRepository:
)
test_session.add(sound)
sounds.append(sound)
await test_session.commit()
await test_session.refresh(playlist)
for sound in sounds:
@@ -623,7 +623,7 @@ class TestPlaylistRepository:
# Verify the final positions
playlist_sounds = await playlist_repository.get_playlist_sound_entries(playlist_id)
assert len(playlist_sounds) == 3
assert playlist_sounds[0].sound_id == sound_ids[2] # New sound 2 inserted at position 0
assert playlist_sounds[0].position == 0

View File

@@ -409,7 +409,7 @@ class TestCreditService:
@pytest.mark.asyncio
async def test_recharge_user_credits_success(
self, credit_service, sample_user
self, credit_service, sample_user,
) -> None:
"""Test successful credit recharge for a user."""
mock_session = credit_service.db_session_factory()

View File

@@ -1,6 +1,6 @@
"""Tests for dashboard service."""
from datetime import UTC, datetime, timedelta
from datetime import UTC, datetime
from unittest.mock import AsyncMock, Mock, patch
import pytest
@@ -63,7 +63,7 @@ class TestDashboardService:
):
"""Test getting soundboard statistics with exception."""
mock_sound_repository.get_soundboard_statistics = AsyncMock(
side_effect=Exception("Database error")
side_effect=Exception("Database error"),
)
with pytest.raises(Exception, match="Database error"):
@@ -105,7 +105,7 @@ class TestDashboardService:
):
"""Test getting track statistics with exception."""
mock_sound_repository.get_track_statistics = AsyncMock(
side_effect=Exception("Database error")
side_effect=Exception("Database error"),
)
with pytest.raises(Exception, match="Database error"):
@@ -198,7 +198,7 @@ class TestDashboardService:
):
"""Test getting top sounds with exception."""
mock_sound_repository.get_top_sounds = AsyncMock(
side_effect=Exception("Database error")
side_effect=Exception("Database error"),
)
with pytest.raises(Exception, match="Database error"):
@@ -274,4 +274,4 @@ class TestDashboardService:
def test_get_date_filter_unknown_period(self, dashboard_service):
"""Test date filter for unknown period."""
result = dashboard_service._get_date_filter("unknown_period")
assert result is None
assert result is None

View File

@@ -25,9 +25,9 @@ class TestSchedulerService:
@pytest.mark.asyncio
async def test_start_scheduler(self, scheduler_service) -> None:
"""Test starting the scheduler service."""
with patch.object(scheduler_service.scheduler, 'add_job') as mock_add_job, \
patch.object(scheduler_service.scheduler, 'start') as mock_start:
with patch.object(scheduler_service.scheduler, "add_job") as mock_add_job, \
patch.object(scheduler_service.scheduler, "start") as mock_start:
await scheduler_service.start()
# Verify job was added
@@ -47,7 +47,7 @@ class TestSchedulerService:
@pytest.mark.asyncio
async def test_stop_scheduler(self, scheduler_service) -> None:
"""Test stopping the scheduler service."""
with patch.object(scheduler_service.scheduler, 'shutdown') as mock_shutdown:
with patch.object(scheduler_service.scheduler, "shutdown") as mock_shutdown:
await scheduler_service.stop()
mock_shutdown.assert_called_once()
@@ -61,7 +61,7 @@ class TestSchedulerService:
"total_credits_added": 500,
}
with patch.object(scheduler_service.credit_service, 'recharge_all_users_credits') as mock_recharge:
with patch.object(scheduler_service.credit_service, "recharge_all_users_credits") as mock_recharge:
mock_recharge.return_value = mock_stats
await scheduler_service._daily_credit_recharge()
@@ -71,10 +71,10 @@ class TestSchedulerService:
@pytest.mark.asyncio
async def test_daily_credit_recharge_failure(self, scheduler_service) -> None:
"""Test daily credit recharge task with failure."""
with patch.object(scheduler_service.credit_service, 'recharge_all_users_credits') as mock_recharge:
with patch.object(scheduler_service.credit_service, "recharge_all_users_credits") as mock_recharge:
mock_recharge.side_effect = Exception("Database error")
# Should not raise exception, just log it
await scheduler_service._daily_credit_recharge()
mock_recharge.assert_called_once()
mock_recharge.assert_called_once()