Refactor test files for improved readability and consistency
- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
This commit is contained in:
@@ -5,7 +5,7 @@ from collections.abc import Awaitable, Callable
|
||||
from typing import Any, TypeVar
|
||||
|
||||
from app.models.credit_action import CreditActionType
|
||||
from app.services.credit import CreditService, InsufficientCreditsError
|
||||
from app.services.credit import CreditService
|
||||
|
||||
F = TypeVar("F", bound=Callable[..., Awaitable[Any]])
|
||||
|
||||
@@ -69,7 +69,7 @@ def requires_credits(
|
||||
|
||||
# Validate credits before execution
|
||||
await credit_service.validate_and_reserve_credits(
|
||||
user_id, action_type, metadata
|
||||
user_id, action_type, metadata,
|
||||
)
|
||||
|
||||
# Execute the function
|
||||
@@ -85,7 +85,7 @@ def requires_credits(
|
||||
finally:
|
||||
# Deduct credits based on success
|
||||
await credit_service.deduct_credits(
|
||||
user_id, action_type, success, metadata
|
||||
user_id, action_type, success, metadata,
|
||||
)
|
||||
|
||||
return wrapper # type: ignore[return-value]
|
||||
@@ -173,7 +173,7 @@ class CreditManager:
|
||||
async def __aenter__(self) -> "CreditManager":
|
||||
"""Enter context manager - validate credits."""
|
||||
await self.credit_service.validate_and_reserve_credits(
|
||||
self.user_id, self.action_type, self.metadata
|
||||
self.user_id, self.action_type, self.metadata,
|
||||
)
|
||||
self.validated = True
|
||||
return self
|
||||
@@ -184,9 +184,9 @@ class CreditManager:
|
||||
# If no exception occurred, consider it successful
|
||||
success = exc_type is None and self.success
|
||||
await self.credit_service.deduct_credits(
|
||||
self.user_id, self.action_type, success, self.metadata
|
||||
self.user_id, self.action_type, success, self.metadata,
|
||||
)
|
||||
|
||||
def mark_success(self) -> None:
|
||||
"""Mark the operation as successful."""
|
||||
self.success = True
|
||||
self.success = True
|
||||
|
||||
Reference in New Issue
Block a user