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:
@@ -30,7 +30,7 @@ class InsufficientCreditsError(Exception):
|
||||
self.required = required
|
||||
self.available = available
|
||||
super().__init__(
|
||||
f"Insufficient credits: {required} required, {available} available"
|
||||
f"Insufficient credits: {required} required, {available} available",
|
||||
)
|
||||
|
||||
|
||||
@@ -138,10 +138,10 @@ class CreditService:
|
||||
|
||||
"""
|
||||
action = get_credit_action(action_type)
|
||||
|
||||
|
||||
# Only deduct if action requires success and was successful, or doesn't require success
|
||||
should_deduct = (action.requires_success and success) or not action.requires_success
|
||||
|
||||
|
||||
if not should_deduct:
|
||||
logger.info(
|
||||
"Skipping credit deduction for user %s: action %s failed and requires success",
|
||||
@@ -150,7 +150,7 @@ class CreditService:
|
||||
)
|
||||
# Still create a transaction record for auditing
|
||||
return await self._create_transaction_record(
|
||||
user_id, action, 0, success, metadata
|
||||
user_id, action, 0, success, metadata,
|
||||
)
|
||||
|
||||
session = self.db_session_factory()
|
||||
@@ -380,4 +380,4 @@ class CreditService:
|
||||
raise ValueError(msg)
|
||||
return user.credits
|
||||
finally:
|
||||
await session.close()
|
||||
await session.close()
|
||||
|
||||
Reference in New Issue
Block a user