Testing that a video can be deleted without a channel.

This commit is contained in:
Roland 2021-12-21 09:19:26 -07:00
parent 9fa7a7960d
commit 8b590d6867
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
5 changed files with 31 additions and 6 deletions

View file

@ -5,7 +5,7 @@ import subprocess
import tempfile
from functools import partial
from pathlib import Path
from typing import Union, Tuple, List, Set, Iterable
from typing import Union, Tuple, List, Set, Iterable, Optional
import PIL
from PIL import Image
@ -148,7 +148,7 @@ def get_absolute_video_files(video: Video) -> List[MediaPath]:
return list(_get())
def get_video_info_json(video) -> Union[dict, None]:
def get_video_info_json(video) -> Optional[dict]:
"""Get the info_json object from a video's meta-file. Return an empty dict if not possible."""
if not video.channel or not video.channel.directory:
return

View file

@ -1,7 +1,7 @@
import pytest
from modules.videos.channel.lib import spread_channel_downloads
from modules.videos.models import Channel
from modules.videos.models import Channel, Video
from wrolpi.downloader import DownloadFrequency
@ -31,3 +31,13 @@ def download_channel(simple_channel) -> Channel:
simple_channel.download_frequency = DownloadFrequency.weekly
spread_channel_downloads()
return simple_channel
@pytest.fixture
def simple_video(test_session, test_directory, simple_channel) -> Video:
video_path = test_directory / 'simple_video.mp4'
video = Video(video_path=video_path, channel_id=simple_channel.id)
test_session.add(video)
test_session.commit()
video = test_session.query(Video).filter_by(id=video.id).one()
return video

View file

@ -10,3 +10,18 @@ def test_timezone(test_session):
test_session.add(video)
test_session.commit()
assert video.upload_date.tzinfo
def test_delete_video_no_channel(test_session, simple_video):
"""
A Video can be deleted even if it does not have a channel.
"""
assert simple_video.channel
video_id = simple_video.id
simple_video.channel_id = None
test_session.commit()
simple_video: Video = test_session.query(Video).filter_by(id=video_id).one()
assert not simple_video.channel
simple_video.delete()