mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 05:09:58 -05:00
You cannot delete a tagged FileGroup.
This commit is contained in:
parent
14c69f5295
commit
6fe536558a
9 changed files with 48 additions and 12 deletions
|
|
@ -154,8 +154,6 @@ async def archive_modeler():
|
|||
.outerjoin(Archive, Archive.file_group_id == FileGroup.id) \
|
||||
.limit(20)
|
||||
|
||||
logger.debug(f'{len(list(invalid_archives))=}')
|
||||
|
||||
processed = 0
|
||||
for file_group, archive in results:
|
||||
processed += 1
|
||||
|
|
|
|||
|
|
@ -67,11 +67,9 @@ class Archive(Base, ModelHelper):
|
|||
return self.archive_datetime > other.archive_datetime
|
||||
|
||||
def delete(self):
|
||||
self.unlink()
|
||||
self.file_group.delete()
|
||||
|
||||
session = Session.object_session(self)
|
||||
|
||||
session.delete(self.file_group)
|
||||
session.delete(self)
|
||||
|
||||
if self.domain:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from wrolpi.common import Base, ModelHelper, logger, get_media_directory, backgr
|
|||
from wrolpi.dates import now, TZDateTime
|
||||
from wrolpi.db import get_db_curs, get_db_session, optional_session
|
||||
from wrolpi.downloader import Download, download_manager
|
||||
from wrolpi.errors import UnknownVideo
|
||||
from wrolpi.errors import UnknownVideo, FileGroupIsTagged
|
||||
from wrolpi.files.lib import refresh_files, get_mimetype, split_path_stem_and_suffix
|
||||
from wrolpi.files.models import FileGroup
|
||||
from wrolpi.media_path import MediaPathType
|
||||
|
|
@ -78,10 +78,11 @@ class Video(ModelHelper, Base):
|
|||
def delete(self):
|
||||
"""Remove all files and File records related to this video. Delete this Video record.
|
||||
Add it to it's Channel's skip list."""
|
||||
self.file_group.delete()
|
||||
|
||||
self.add_to_skip_list()
|
||||
session = Session.object_session(self)
|
||||
session.delete(self)
|
||||
self.file_group.delete()
|
||||
|
||||
def add_to_skip_list(self):
|
||||
"""Add this video to it's Channel's skip list."""
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import pytest
|
|||
|
||||
from modules.videos.models import Video
|
||||
from wrolpi.dates import now
|
||||
from wrolpi.errors import FileGroupIsTagged
|
||||
from wrolpi.files import lib as files_lib
|
||||
from wrolpi.files.models import FileGroup
|
||||
|
||||
|
|
@ -43,6 +44,22 @@ def test_delete_video(test_session, video_factory):
|
|||
assert test_session.query(FileGroup).count() == 0, 'Video files were not deleted.'
|
||||
|
||||
|
||||
def test_delete_video_with_tag(test_session, video_factory, tag_factory):
|
||||
"""You cannot delete a video with a tag."""
|
||||
video = video_factory(with_video_file=True, with_poster_ext='png')
|
||||
tag = tag_factory()
|
||||
video.add_tag(tag)
|
||||
test_session.commit()
|
||||
|
||||
with pytest.raises(FileGroupIsTagged):
|
||||
video.delete()
|
||||
|
||||
# Video was not deleted.
|
||||
test_session.commit()
|
||||
assert test_session.query(Video).count() == 1
|
||||
assert test_session.query(FileGroup).count() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_video_channel_refresh(test_session, test_directory, channel_factory, video_factory):
|
||||
"""A Video will be associated with a Channel when it's files are in that Channel's directory."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue