-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache YouTube video titles in the DB
- Loading branch information
Showing
7 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from tests.factories.video import VideoFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from factory import Faker, Sequence | ||
from factory.alchemy import SQLAlchemyModelFactory | ||
|
||
from via.models import Video, VideoType | ||
|
||
|
||
class VideoFactory(SQLAlchemyModelFactory): | ||
class Meta: | ||
model = Video | ||
|
||
type = Faker("random_element", elements=VideoType) | ||
video_id = Sequence(lambda n: f"video_id_{n}") | ||
title = Sequence(lambda n: f"video_title_{n}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
from via.models.video import Video, VideoType | ||
|
||
|
||
def includeme(_config): # pragma: no cover | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import enum | ||
|
||
from sqlalchemy import Enum, UniqueConstraint | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from via.db import Base | ||
|
||
|
||
class VideoType(enum.Enum): | ||
YOUTUBE = 1 | ||
|
||
|
||
class Video(Base): | ||
__tablename__ = "video" | ||
__table_args__ = (UniqueConstraint("type", "video_id"),) | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True, init=False) | ||
type: Mapped[int] = mapped_column(Enum(VideoType)) | ||
video_id: Mapped[str] | ||
title: Mapped[str] = mapped_column(repr=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters