From f9227f234c339e289e84e709f21c2526493ae5f0 Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 19 May 2024 15:46:43 -0600 Subject: [PATCH] Fixing logic error where multiprocessing dict was being ignored during initialization. Fixing test which expected the config to be a dict. --- modules/videos/normalize_video_url.py | 2 ++ modules/videos/test/test_common.py | 12 +++++++----- wrolpi/common.py | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/videos/normalize_video_url.py b/modules/videos/normalize_video_url.py index b2831705..9b949bc2 100644 --- a/modules/videos/normalize_video_url.py +++ b/modules/videos/normalize_video_url.py @@ -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() diff --git a/modules/videos/test/test_common.py b/modules/videos/test/test_common.py index 2900c570..6fc47e1b 100644 --- a/modules/videos/test/test_common.py +++ b/modules/videos/test/test_common.py @@ -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. diff --git a/wrolpi/common.py b/wrolpi/common.py index 6682575f..37bfd6d7 100644 --- a/wrolpi/common.py +++ b/wrolpi/common.py @@ -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}')