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:
@@ -202,13 +202,17 @@ class TestCreditTransactionRepository:
|
||||
"""Test getting transactions by user ID with pagination."""
|
||||
# Get first 2 transactions
|
||||
first_page = await credit_transaction_repository.get_by_user_id(
|
||||
test_user_id, limit=2, offset=0,
|
||||
test_user_id,
|
||||
limit=2,
|
||||
offset=0,
|
||||
)
|
||||
assert len(first_page) == PAGE_SIZE
|
||||
|
||||
# Get next 2 transactions
|
||||
second_page = await credit_transaction_repository.get_by_user_id(
|
||||
test_user_id, limit=2, offset=2,
|
||||
test_user_id,
|
||||
limit=2,
|
||||
offset=2,
|
||||
)
|
||||
assert len(second_page) == PAGE_SIZE
|
||||
|
||||
@@ -251,14 +255,17 @@ class TestCreditTransactionRepository:
|
||||
"""Test getting transactions by action type with pagination."""
|
||||
# Test with limit
|
||||
transactions = await credit_transaction_repository.get_by_action_type(
|
||||
"vlc_play_sound", limit=1,
|
||||
"vlc_play_sound",
|
||||
limit=1,
|
||||
)
|
||||
assert len(transactions) == 1
|
||||
assert transactions[0].action_type == "vlc_play_sound"
|
||||
|
||||
# Test with offset
|
||||
transactions = await credit_transaction_repository.get_by_action_type(
|
||||
"vlc_play_sound", limit=1, offset=1,
|
||||
"vlc_play_sound",
|
||||
limit=1,
|
||||
offset=1,
|
||||
)
|
||||
assert len(transactions) <= 1 # Might be 0 if only 1 VLC transaction in total
|
||||
|
||||
@@ -269,7 +276,9 @@ class TestCreditTransactionRepository:
|
||||
test_transactions: list[CreditTransaction],
|
||||
) -> None:
|
||||
"""Test getting only successful transactions."""
|
||||
successful_transactions = await credit_transaction_repository.get_successful_transactions()
|
||||
successful_transactions = (
|
||||
await credit_transaction_repository.get_successful_transactions()
|
||||
)
|
||||
|
||||
# Should only return successful transactions
|
||||
assert all(t.success is True for t in successful_transactions)
|
||||
@@ -285,8 +294,10 @@ class TestCreditTransactionRepository:
|
||||
test_user_id: int,
|
||||
) -> None:
|
||||
"""Test getting successful transactions filtered by user."""
|
||||
successful_transactions = await credit_transaction_repository.get_successful_transactions(
|
||||
user_id=test_user_id,
|
||||
successful_transactions = (
|
||||
await credit_transaction_repository.get_successful_transactions(
|
||||
user_id=test_user_id,
|
||||
)
|
||||
)
|
||||
|
||||
# Should only return successful transactions for test_user
|
||||
@@ -305,14 +316,18 @@ class TestCreditTransactionRepository:
|
||||
"""Test getting successful transactions with pagination."""
|
||||
# Get first 2 successful transactions
|
||||
first_page = await credit_transaction_repository.get_successful_transactions(
|
||||
user_id=test_user_id, limit=2, offset=0,
|
||||
user_id=test_user_id,
|
||||
limit=2,
|
||||
offset=0,
|
||||
)
|
||||
assert len(first_page) == PAGE_SIZE
|
||||
assert all(t.success is True for t in first_page)
|
||||
|
||||
# Get next successful transaction
|
||||
second_page = await credit_transaction_repository.get_successful_transactions(
|
||||
user_id=test_user_id, limit=2, offset=2,
|
||||
user_id=test_user_id,
|
||||
limit=2,
|
||||
offset=2,
|
||||
)
|
||||
assert len(second_page) == 1 # Should be 1 remaining
|
||||
assert all(t.success is True for t in second_page)
|
||||
@@ -328,7 +343,9 @@ class TestCreditTransactionRepository:
|
||||
all_transactions = await credit_transaction_repository.get_all()
|
||||
|
||||
# Should return all transactions
|
||||
assert len(all_transactions) >= MIN_ALL_TRANSACTIONS # 4 from test_transactions + 1 other_user_transaction
|
||||
assert (
|
||||
len(all_transactions) >= MIN_ALL_TRANSACTIONS
|
||||
) # 4 from test_transactions + 1 other_user_transaction
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_transaction(
|
||||
@@ -374,7 +391,8 @@ class TestCreditTransactionRepository:
|
||||
}
|
||||
|
||||
updated_transaction = await credit_transaction_repository.update(
|
||||
transaction, update_data,
|
||||
transaction,
|
||||
update_data,
|
||||
)
|
||||
|
||||
assert updated_transaction.id == transaction.id
|
||||
@@ -412,7 +430,9 @@ class TestCreditTransactionRepository:
|
||||
|
||||
# Verify transaction is deleted
|
||||
assert transaction_id is not None
|
||||
deleted_transaction = await credit_transaction_repository.get_by_id(transaction_id)
|
||||
deleted_transaction = await credit_transaction_repository.get_by_id(
|
||||
transaction_id,
|
||||
)
|
||||
assert deleted_transaction is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user