Files
sdb2-backend/app/models/sound.py
JSC 7dee6e320e
Some checks failed
Backend CI / lint (push) Successful in 9m25s
Backend CI / test (push) Failing after 4m48s
Add tests for extraction API endpoints and enhance existing tests
- Implement tests for admin extraction API endpoints including status retrieval, deletion of extractions, and permission checks.
- Add tests for user extraction deletion, ensuring proper handling of permissions and non-existent extractions.
- Enhance sound endpoint tests to include duplicate handling in responses.
- Refactor favorite service tests to utilize mock dependencies for better maintainability and clarity.
- Update sound scanner tests to improve file handling and ensure proper deletion of associated files.
2025-08-25 21:40:31 +02:00

45 lines
1.7 KiB
Python

from typing import TYPE_CHECKING
from sqlmodel import Field, Relationship, UniqueConstraint
from app.models.base import BaseModel
if TYPE_CHECKING:
from app.models.extraction import Extraction
from app.models.favorite import Favorite
from app.models.playlist_sound import PlaylistSound
from app.models.sound_played import SoundPlayed
class Sound(BaseModel, table=True):
"""Database model for a sound."""
type: str = Field(nullable=False)
name: str = Field(nullable=False)
filename: str = Field(nullable=False)
duration: int = Field(default=0, ge=0, nullable=False)
size: int = Field(default=0, ge=0, nullable=False)
hash: str = Field(nullable=False)
normalized_filename: str | None = Field(default=None)
normalized_duration: int | None = Field(default=None, ge=0)
normalized_size: int | None = Field(default=None, ge=0)
normalized_hash: str | None = Field(default=None)
thumbnail: str | None = Field(default=None)
play_count: int = Field(default=0, ge=0, nullable=False)
is_normalized: bool = Field(default=False, nullable=False)
is_music: bool = Field(default=False, nullable=False)
is_deletable: bool = Field(default=True, nullable=False)
# constraints
__table_args__ = (UniqueConstraint("hash", name="uq_sound_hash"),)
# relationships
playlist_sounds: list["PlaylistSound"] = Relationship(
back_populates="sound", cascade_delete=True,
)
extractions: list["Extraction"] = Relationship(back_populates="sound")
play_history: list["SoundPlayed"] = Relationship(
back_populates="sound", cascade_delete=True,
)
favorites: list["Favorite"] = Relationship(back_populates="sound")