Refactor sound and extraction services to include user and timestamp fields
- Updated ExtractionInfo to include user_id, created_at, and updated_at fields. - Modified ExtractionService to return user and timestamp information in extraction responses. - Enhanced sound serialization in PlayerState to include extraction URL if available. - Adjusted PlaylistRepository to load sound extractions when retrieving playlist sounds. - Added tests for new fields in extraction and sound endpoints, ensuring proper response structure. - Created new test file endpoints for sound downloads and thumbnail retrievals, including success and error cases. - Refactored various test cases for consistency and clarity, ensuring proper mocking and assertions.
This commit is contained in:
@@ -49,7 +49,8 @@ class TestCreditService:
|
||||
mock_repo.get_by_id.return_value = sample_user
|
||||
|
||||
result = await credit_service.check_credits(
|
||||
1, CreditActionType.VLC_PLAY_SOUND,
|
||||
1,
|
||||
CreditActionType.VLC_PLAY_SOUND,
|
||||
)
|
||||
|
||||
assert result is True
|
||||
@@ -75,7 +76,8 @@ class TestCreditService:
|
||||
mock_repo.get_by_id.return_value = poor_user
|
||||
|
||||
result = await credit_service.check_credits(
|
||||
1, CreditActionType.VLC_PLAY_SOUND,
|
||||
1,
|
||||
CreditActionType.VLC_PLAY_SOUND,
|
||||
)
|
||||
|
||||
assert result is False
|
||||
@@ -92,7 +94,8 @@ class TestCreditService:
|
||||
mock_repo.get_by_id.return_value = None
|
||||
|
||||
result = await credit_service.check_credits(
|
||||
999, CreditActionType.VLC_PLAY_SOUND,
|
||||
999,
|
||||
CreditActionType.VLC_PLAY_SOUND,
|
||||
)
|
||||
|
||||
assert result is False
|
||||
@@ -100,7 +103,9 @@ class TestCreditService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validate_and_reserve_credits_success(
|
||||
self, credit_service, sample_user,
|
||||
self,
|
||||
credit_service,
|
||||
sample_user,
|
||||
) -> None:
|
||||
"""Test successful credit validation and reservation."""
|
||||
mock_session = credit_service.db_session_factory()
|
||||
@@ -122,7 +127,8 @@ class TestCreditService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validate_and_reserve_credits_insufficient(
|
||||
self, credit_service,
|
||||
self,
|
||||
credit_service,
|
||||
) -> None:
|
||||
"""Test credit validation with insufficient credits."""
|
||||
mock_session = credit_service.db_session_factory()
|
||||
@@ -152,7 +158,8 @@ class TestCreditService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validate_and_reserve_credits_user_not_found(
|
||||
self, credit_service,
|
||||
self,
|
||||
credit_service,
|
||||
) -> None:
|
||||
"""Test credit validation when user is not found."""
|
||||
mock_session = credit_service.db_session_factory()
|
||||
@@ -225,7 +232,9 @@ class TestCreditService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_deduct_credits_failed_action_requires_success(
|
||||
self, credit_service, sample_user,
|
||||
self,
|
||||
credit_service,
|
||||
sample_user,
|
||||
) -> None:
|
||||
"""Test credit deduction when action failed but requires success."""
|
||||
mock_session = credit_service.db_session_factory()
|
||||
|
||||
Reference in New Issue
Block a user