fix: Lint fixes of last tests

This commit is contained in:
JSC
2025-08-01 09:30:15 +02:00
parent dc29915fbc
commit fceff92ca1
20 changed files with 326 additions and 313 deletions

View File

@@ -1,4 +1,5 @@
"""Tests for credit service."""
# ruff: noqa: ANN001, ANN201, PLR2004, E501
import json
from unittest.mock import AsyncMock, patch
@@ -39,7 +40,7 @@ class TestCreditService:
)
@pytest.mark.asyncio
async def test_check_credits_sufficient(self, credit_service, sample_user):
async def test_check_credits_sufficient(self, credit_service, sample_user) -> None:
"""Test checking credits when user has sufficient credits."""
mock_session = credit_service.db_session_factory()
@@ -55,7 +56,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_check_credits_insufficient(self, credit_service):
async def test_check_credits_insufficient(self, credit_service) -> None:
"""Test checking credits when user has insufficient credits."""
mock_session = credit_service.db_session_factory()
poor_user = User(
@@ -78,7 +79,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_check_credits_user_not_found(self, credit_service):
async def test_check_credits_user_not_found(self, credit_service) -> None:
"""Test checking credits when user is not found."""
mock_session = credit_service.db_session_factory()
@@ -93,7 +94,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_validate_and_reserve_credits_success(self, credit_service, sample_user):
async def test_validate_and_reserve_credits_success(self, credit_service, sample_user) -> None:
"""Test successful credit validation and reservation."""
mock_session = credit_service.db_session_factory()
@@ -112,7 +113,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_validate_and_reserve_credits_insufficient(self, credit_service):
async def test_validate_and_reserve_credits_insufficient(self, credit_service) -> None:
"""Test credit validation with insufficient credits."""
mock_session = credit_service.db_session_factory()
poor_user = User(
@@ -139,7 +140,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_validate_and_reserve_credits_user_not_found(self, credit_service):
async def test_validate_and_reserve_credits_user_not_found(self, credit_service) -> None:
"""Test credit validation when user is not found."""
mock_session = credit_service.db_session_factory()
@@ -156,7 +157,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_deduct_credits_success(self, credit_service, sample_user):
async def test_deduct_credits_success(self, credit_service, sample_user) -> None:
"""Test successful credit deduction."""
mock_session = credit_service.db_session_factory()
@@ -167,7 +168,7 @@ class TestCreditService:
mock_repo.get_by_id.return_value = sample_user
mock_socket_manager.send_to_user = AsyncMock()
transaction = await credit_service.deduct_credits(
await credit_service.deduct_credits(
1, CreditActionType.VLC_PLAY_SOUND, success=True, metadata={"test": "data"},
)
@@ -202,7 +203,7 @@ class TestCreditService:
assert json.loads(added_transaction.metadata_json) == {"test": "data"}
@pytest.mark.asyncio
async def test_deduct_credits_failed_action_requires_success(self, credit_service, sample_user):
async def test_deduct_credits_failed_action_requires_success(self, credit_service, sample_user) -> None:
"""Test credit deduction when action failed but requires success."""
mock_session = credit_service.db_session_factory()
@@ -213,7 +214,7 @@ class TestCreditService:
mock_repo.get_by_id.return_value = sample_user
mock_socket_manager.send_to_user = AsyncMock()
transaction = await credit_service.deduct_credits(
await credit_service.deduct_credits(
1, CreditActionType.VLC_PLAY_SOUND, success=False, # Action failed
)
@@ -235,7 +236,7 @@ class TestCreditService:
assert added_transaction.success is False
@pytest.mark.asyncio
async def test_deduct_credits_insufficient(self, credit_service):
async def test_deduct_credits_insufficient(self, credit_service) -> None:
"""Test credit deduction with insufficient credits."""
mock_session = credit_service.db_session_factory()
poor_user = User(
@@ -266,7 +267,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_add_credits(self, credit_service, sample_user):
async def test_add_credits(self, credit_service, sample_user) -> None:
"""Test adding credits to user account."""
mock_session = credit_service.db_session_factory()
@@ -277,7 +278,7 @@ class TestCreditService:
mock_repo.get_by_id.return_value = sample_user
mock_socket_manager.send_to_user = AsyncMock()
transaction = await credit_service.add_credits(
await credit_service.add_credits(
1, 5, "Bonus credits", {"reason": "signup"},
)
@@ -308,7 +309,7 @@ class TestCreditService:
assert added_transaction.description == "Bonus credits"
@pytest.mark.asyncio
async def test_add_credits_invalid_amount(self, credit_service):
async def test_add_credits_invalid_amount(self, credit_service) -> None:
"""Test adding invalid amount of credits."""
with pytest.raises(ValueError, match="Amount must be positive"):
await credit_service.add_credits(1, 0, "Invalid")
@@ -317,7 +318,7 @@ class TestCreditService:
await credit_service.add_credits(1, -5, "Invalid")
@pytest.mark.asyncio
async def test_get_user_balance(self, credit_service, sample_user):
async def test_get_user_balance(self, credit_service, sample_user) -> None:
"""Test getting user credit balance."""
mock_session = credit_service.db_session_factory()
@@ -332,7 +333,7 @@ class TestCreditService:
mock_session.close.assert_called_once()
@pytest.mark.asyncio
async def test_get_user_balance_user_not_found(self, credit_service):
async def test_get_user_balance_user_not_found(self, credit_service) -> None:
"""Test getting balance for non-existent user."""
mock_session = credit_service.db_session_factory()
@@ -350,7 +351,7 @@ class TestCreditService:
class TestInsufficientCreditsError:
"""Test InsufficientCreditsError exception."""
def test_insufficient_credits_error_creation(self):
def test_insufficient_credits_error_creation(self) -> None:
"""Test creating InsufficientCreditsError."""
error = InsufficientCreditsError(5, 2)
assert error.required == 5