You cannot delete a tagged FileGroup.

This commit is contained in:
Roland 2023-04-12 11:42:13 -06:00
parent 14c69f5295
commit 6fe536558a
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
9 changed files with 48 additions and 12 deletions

View file

@ -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

View file

@ -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:

View file

@ -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."""

View file

@ -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."""