Fixing bug where test directory was deleted. Creating dedicated Download Channel instead of using Simple Channel.

This commit is contained in:
Roland 2021-12-21 09:27:45 -07:00
parent 8b590d6867
commit fded1e7492
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 22 additions and 9 deletions

View file

@ -12,10 +12,10 @@ def simple_channel(test_session, test_directory) -> Channel:
"""
channel = Channel(
directory=test_directory,
name='Example Channel 1',
name='Simple Channel',
url='https://example.com/channel1',
download_frequency=None, # noqa
link='examplechannel1',
link='simplechannel',
)
test_session.add(channel)
test_session.commit()
@ -23,19 +23,31 @@ def simple_channel(test_session, test_directory) -> Channel:
@pytest.fixture
def download_channel(simple_channel) -> Channel:
def download_channel(test_session, test_directory) -> Channel:
"""
Get a test Channel that has a download frequency.
"""
# Add a frequency to the test channel, then give it a download.
simple_channel.download_frequency = DownloadFrequency.weekly
channel = Channel(
directory=test_directory,
name='Download Channel',
url='https://example.com/channel1',
download_frequency=DownloadFrequency.weekly,
link='downloadchannel',
)
test_session.add(channel)
test_session.commit()
spread_channel_downloads()
return simple_channel
return channel
@pytest.fixture
def simple_video(test_session, test_directory, simple_channel) -> Video:
"""
A Video with a video file whose channel is the Simple Channel.
"""
video_path = test_directory / 'simple_video.mp4'
video_path.touch()
video = Video(video_path=video_path, channel_id=simple_channel.id)
test_session.add(video)
test_session.commit()

View file

@ -75,10 +75,11 @@ def test_directory() -> pathlib.Path:
"""
Overwrite the media directory with a temporary directory.
"""
tmp_dir = tempfile.TemporaryDirectory()
tmp_path = pathlib.Path(tmp_dir.name)
set_test_media_directory(tmp_path)
return tmp_path
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = pathlib.Path(tmp_dir)
assert tmp_path.is_dir()
set_test_media_directory(tmp_path)
yield tmp_path
@pytest.fixture(autouse=True)