Fixing logic error where multiprocessing dict was being ignored during initialization. Fixing test which expected the config to be a dict.

This commit is contained in:
Roland 2024-05-19 15:46:43 -06:00
parent 3ff4f2eee4
commit f9227f234c
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 13 additions and 9 deletions

View file

@ -21,6 +21,8 @@ def strip_extra_from_url(url: str) -> str:
return url
# TODO Move this to a global location. We want an Archive's URL to mat a Video's URL.
def normalize_video_url(url: str) -> str:
"""Convert video URLs to what is expected to be in the yt-dlp info json."""
url = url.strip()

View file

@ -10,11 +10,10 @@ from modules.videos.models import Channel, Video
from wrolpi.common import get_absolute_media_path, get_wrolpi_config
from wrolpi.downloader import Download, DownloadFrequency
from wrolpi.files import lib as files_lib
from wrolpi.api_utils import api_app
from wrolpi.vars import PROJECT_DIR
from .. import common
from ..common import convert_image, update_view_counts, get_video_duration, generate_video_poster, is_valid_poster
from ..lib import save_channels_config, get_channels_config, import_channels_config
from ..lib import save_channels_config, get_channels_config, import_channels_config, ChannelsConfig
def test_get_absolute_media_path():
@ -133,7 +132,7 @@ def test_generate_video_poster(video_file):
assert duration == 5
def test_import_channel_downloads(test_session, channel_factory, test_channels_config):
def test_import_channel_downloads(test_async_client, test_session, channel_factory, test_channels_config):
"""Importing the Channels' config should create any missing download records"""
channel1 = channel_factory(source_id='foo')
channel2 = channel_factory(source_id='bar')
@ -145,10 +144,13 @@ def test_import_channel_downloads(test_session, channel_factory, test_channels_c
assert len(test_session.query(Channel).all()) == 2
assert test_session.query(Download).all() == []
def update_channel_config(conf, source_id, d):
for c in conf.channels:
def update_channel_config(conf: ChannelsConfig, source_id, d):
# Creat a copy of the old config, replace the data of the provided Channel.
old_config = conf._config.copy()
for c in old_config['channels']:
if c['source_id'] == source_id:
c.update(d)
conf.channels = old_config['channels']
conf.save()
# Config has no channels with a download_frequency.

View file

@ -317,7 +317,7 @@ class ConfigFile:
def initialize(self, multiprocessing_dict: Optional[DictProxy] = None):
"""Initializes this config dict using the default config and the config file."""
# Use the provided multiprocessing.Manager().dict(), or dict() for testing.
self._config = multiprocessing_dict or dict()
self._config = multiprocessing_dict if multiprocessing_dict is not None else dict()
# Use the default settings to initialize the config.
self._config.update(deepcopy(self.default_config))
@ -376,7 +376,7 @@ class ConfigFile:
config = dict()
config.update({k: v for k, v in self._config.items() if v is not None})
logger.debug(f'Saving config: {config_file}')
logger_.debug(f'Saving config: {config_file}')
with config_file.open('wt') as fh:
yaml.dump(config, fh, width=self.width)
# Wait for data to be written before releasing lock.
@ -1032,7 +1032,7 @@ async def get_fastest_mirror(urls: List[str]) -> str:
try:
speed = await speed_test(url)
except Exception as e:
logger.error(f'Speedtest of {url} failed', exc_info=e)
logger_.error(f'Speedtest of {url} failed', exc_info=e)
continue
if speed > fastest_speed:
@ -1744,4 +1744,4 @@ def get_title_from_html(html: str, url: str = None) -> str:
try:
return soup.title.string.strip()
except Exception: # noqa
logger.debug(f'Unable to extract title {url}')
logger_.debug(f'Unable to extract title {url}')