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:
@@ -40,6 +40,7 @@ def requires_credits(
|
||||
return True
|
||||
|
||||
"""
|
||||
|
||||
def decorator(func: F) -> F:
|
||||
@functools.wraps(func)
|
||||
async def wrapper(*args: Any, **kwargs: Any) -> Any: # noqa: ANN401
|
||||
@@ -70,7 +71,8 @@ def requires_credits(
|
||||
|
||||
# Validate credits before execution
|
||||
await credit_service.validate_and_reserve_credits(
|
||||
user_id, action_type,
|
||||
user_id,
|
||||
action_type,
|
||||
)
|
||||
|
||||
# Execute the function
|
||||
@@ -86,10 +88,14 @@ def requires_credits(
|
||||
finally:
|
||||
# Deduct credits based on success
|
||||
await credit_service.deduct_credits(
|
||||
user_id, action_type, success=success, metadata=metadata,
|
||||
user_id,
|
||||
action_type,
|
||||
success=success,
|
||||
metadata=metadata,
|
||||
)
|
||||
|
||||
return wrapper # type: ignore[return-value]
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -111,6 +117,7 @@ def validate_credits_only(
|
||||
Decorated function that validates credits only
|
||||
|
||||
"""
|
||||
|
||||
def decorator(func: F) -> F:
|
||||
@functools.wraps(func)
|
||||
async def wrapper(*args: Any, **kwargs: Any) -> Any: # noqa: ANN401
|
||||
@@ -141,6 +148,7 @@ def validate_credits_only(
|
||||
return await func(*args, **kwargs)
|
||||
|
||||
return wrapper # type: ignore[return-value]
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -173,7 +181,8 @@ 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.user_id,
|
||||
self.action_type,
|
||||
)
|
||||
self.validated = True
|
||||
return self
|
||||
@@ -189,7 +198,10 @@ 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=success, metadata=self.metadata,
|
||||
self.user_id,
|
||||
self.action_type,
|
||||
success=success,
|
||||
metadata=self.metadata,
|
||||
)
|
||||
|
||||
def mark_success(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user