mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Testing that a video can be deleted without a channel.
This commit is contained in:
parent
9fa7a7960d
commit
8b590d6867
5 changed files with 31 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from functools import wraps
|
|||
from itertools import islice
|
||||
from multiprocessing import Event, Queue
|
||||
from pathlib import Path
|
||||
from typing import Union, Callable, Tuple, Dict, Mapping, List, Iterable
|
||||
from typing import Union, Callable, Tuple, Dict, Mapping, List, Iterable, Optional
|
||||
from urllib.parse import urlunsplit, urlparse
|
||||
|
||||
import yaml
|
||||
|
|
@ -433,7 +433,7 @@ def get_relative_to_media_directory(path: str) -> Path:
|
|||
return absolute.relative_to(get_media_directory())
|
||||
|
||||
|
||||
def minimize_dict(d: dict, keys: Iterable) -> Union[dict, None]:
|
||||
def minimize_dict(d: dict, keys: Iterable) -> Optional[dict]:
|
||||
"""
|
||||
Return a new dictionary that contains only the keys provided.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ def test_session() -> Session:
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def test_directory():
|
||||
def test_directory() -> pathlib.Path:
|
||||
"""
|
||||
Overwrite the media directory with a temporary directory.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue