feat: Add unique constraint on sound hash and update related tests
This commit is contained in:
@@ -17,7 +17,7 @@ class TestSoundRepository:
|
||||
async def sound_repository(
|
||||
self,
|
||||
test_session: AsyncSession,
|
||||
) -> AsyncGenerator[SoundRepository, None]: # type: ignore[misc]
|
||||
) -> AsyncGenerator[SoundRepository, None]:
|
||||
"""Create a sound repository instance."""
|
||||
yield SoundRepository(test_session)
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestSoundRepository:
|
||||
async def test_sound(
|
||||
self,
|
||||
test_session: AsyncSession,
|
||||
) -> AsyncGenerator[Sound, None]: # type: ignore[misc]
|
||||
) -> AsyncGenerator[Sound, None]:
|
||||
"""Create a test sound."""
|
||||
sound_data = {
|
||||
"name": "Test Sound",
|
||||
@@ -47,7 +47,7 @@ class TestSoundRepository:
|
||||
async def normalized_sound(
|
||||
self,
|
||||
test_session: AsyncSession,
|
||||
) -> AsyncGenerator[Sound, None]: # type: ignore[misc]
|
||||
) -> AsyncGenerator[Sound, None]:
|
||||
"""Create a normalized test sound."""
|
||||
sound_data = {
|
||||
"name": "Normalized Sound",
|
||||
@@ -76,7 +76,9 @@ class TestSoundRepository:
|
||||
test_sound: Sound,
|
||||
) -> None:
|
||||
"""Test getting sound by ID when it exists."""
|
||||
sound = await sound_repository.get_by_id(test_sound.id)
|
||||
sound_id = test_sound.id
|
||||
assert sound_id is not None
|
||||
sound = await sound_repository.get_by_id(sound_id)
|
||||
|
||||
assert sound is not None
|
||||
assert sound.id == test_sound.id
|
||||
@@ -240,6 +242,7 @@ class TestSoundRepository:
|
||||
await sound_repository.delete(sound)
|
||||
|
||||
# Verify sound is deleted
|
||||
assert sound_id is not None
|
||||
deleted_sound = await sound_repository.get_by_id(sound_id)
|
||||
assert deleted_sound is None
|
||||
|
||||
@@ -353,7 +356,7 @@ class TestSoundRepository:
|
||||
sound_repository: SoundRepository,
|
||||
test_sound: Sound,
|
||||
) -> None:
|
||||
"""Test creating sound with duplicate hash is allowed."""
|
||||
"""Test creating sound with duplicate hash should fail."""
|
||||
# Store the hash to avoid lazy loading issues
|
||||
original_hash = test_sound.hash
|
||||
|
||||
@@ -368,9 +371,6 @@ class TestSoundRepository:
|
||||
"is_normalized": False,
|
||||
}
|
||||
|
||||
# Should succeed - duplicate hashes are allowed
|
||||
duplicate_sound = await sound_repository.create(duplicate_sound_data)
|
||||
|
||||
assert duplicate_sound.id is not None
|
||||
assert duplicate_sound.name == "Duplicate Hash Sound"
|
||||
assert duplicate_sound.hash == original_hash # Same hash is allowed
|
||||
# Should fail due to unique constraint on hash
|
||||
with pytest.raises(Exception): # SQLAlchemy IntegrityError or similar
|
||||
await sound_repository.create(duplicate_sound_data)
|
||||
Reference in New Issue
Block a user