-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4befa4
commit 82f65cf
Showing
1 changed file
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ruff: noqa: S101 | ||
|
||
from importlib import resources | ||
from tempfile import NamedTemporaryFile | ||
from unittest.mock import patch | ||
|
||
from aana.configs.db import run_alembic_migrations | ||
from aana.configs.settings import settings | ||
from aana.models.core.video import Video | ||
from aana.utils.db import save_video | ||
|
||
|
||
def test_save_video(): | ||
"""Tests saving a video against an in-memory SQLite database.""" | ||
# Use a temp file and change the settings to use it for the SQLite data path. | ||
with NamedTemporaryFile(dir=settings.tmp_data_dir) as tmp: | ||
settings.db_config.datastore_config["path"] = tmp.name | ||
# Reset the engine if it has been created | ||
del settings.db_config.engine | ||
settings.db_config.engine = None | ||
|
||
run_alembic_migrations(settings) | ||
|
||
# We also have to patch the "engine" variable in aana.utils.db | ||
# because it gets set before the test is run due to import depedencies. | ||
# TODO: We should stop using the engine as an importable name | ||
with patch("aana.utils.db.engine", settings.db_config.get_engine()): | ||
media_id = "foobar" | ||
duration = 550.25 | ||
path = resources.path("aana.tests.files.videos", "squirrel.mp4") | ||
video = Video(path=path, media_id=media_id) | ||
result = save_video(video, duration) | ||
assert result["video_id"] | ||
assert result["media_id"] == media_id |