Preserving FileGroup.title when moving.

This commit is contained in:
Roland 2024-08-06 20:04:24 -06:00
parent 2a83517d93
commit d8ef7e175e
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 23 additions and 9 deletions

View file

@ -1,9 +1,7 @@
import pathlib
import pytest
from modules.videos.models import Video, Channel
from wrolpi.common import get_relative_to_media_directory, get_wrolpi_config
from modules.videos.models import Video
from wrolpi.common import get_relative_to_media_directory
@pytest.mark.asyncio()
@ -25,13 +23,19 @@ async def test_channel_move(test_async_client, test_session, test_directory, cha
"""A Channel can be moved to another directory, any files in the Channel's directory are moved."""
channel = channel_factory(name='Channel Name')
video = video_factory(title='Vid', channel_id=channel.id)
extra_file = (channel.directory / 'extra.txt')
extra_file.write_text('extra stuff')
test_session.commit()
assert video.channel_id == channel.id
assert str(get_relative_to_media_directory(video.video_path)) == 'videos/Channel Name/Vid.mp4'
# Destination must already exist.
foo = test_directory / 'foo/New Channel Directory'
foo.mkdir(parents=True)
# Move the Channel.
await channel.move(foo, test_session)
assert channel.directory == foo
assert channel.directory != (test_directory / 'New Channel Directory')
video = test_session.query(Video).one()
@ -39,3 +43,7 @@ async def test_channel_move(test_async_client, test_session, test_directory, cha
assert str(video.video_path).startswith(str(channel.directory))
# Old directory is deleted.
assert not (test_directory / 'Channel Name').exists()
# Extra file was moved.
assert not extra_file.is_file()
assert (test_directory / 'foo/New Channel Directory/extra.txt').is_file()
assert (test_directory / 'foo/New Channel Directory/extra.txt').read_text() == 'extra stuff'