diff --git a/src/ytdl_sub/subscriptions/subscription_validators.py b/src/ytdl_sub/subscriptions/subscription_validators.py index 3f01e15d..10dac9ef 100644 --- a/src/ytdl_sub/subscriptions/subscription_validators.py +++ b/src/ytdl_sub/subscriptions/subscription_validators.py @@ -91,14 +91,22 @@ class SubscriptionValueValidator(SubscriptionOutput, StringValidator): self, name, value, + config: ConfigFile, presets: List[str], indent_overrides: List[str], subscription_value: Optional[str], ): super().__init__(name=name, value=value, presets=presets, indent_overrides=indent_overrides) + + if self._leaf_name in config.presets.keys: + raise self._validation_exception( + f"{self._leaf_name} conflicts with an existing preset name and cannot be " + f"used as a subscription name" + ) + if subscription_value is None: raise self._validation_exception( - f"Subscription {name} is a string, but the subscription value " + f"Subscription {self._leaf_name} is a string, but the subscription value " f"is not set to an override variable" ) @@ -136,15 +144,11 @@ class SubscriptionValidator(SubscriptionOutput): obj_name = f"{name}.{key}" if name else key if isinstance(obj, str): - if key in config.presets.keys: - raise self._validation_exception( - f"{key} conflicts with an existing preset name and cannot be " - f"used as a subscription name" - ) self._children.append( SubscriptionValueValidator( name=obj_name, value=obj, + config=config, presets=presets, indent_overrides=indent_overrides, subscription_value=subscription_value, diff --git a/tests/unit/config/test_subscription.py b/tests/unit/config/test_subscription.py index ced0ff70..491744f6 100644 --- a/tests/unit/config/test_subscription.py +++ b/tests/unit/config/test_subscription.py @@ -272,12 +272,30 @@ def test_subscription_file_bad_value(config_file: ConfigFile): def test_subscription_file_using_value_when_not_defined(config_file: ConfigFile): with mock_load_yaml( - preset_dict={"sub_name": "single value, __value__ not defined"} + preset_dict={"[INDENTS_IN_ERR_MSG]": {"sub_name": "single value, __value__ not defined"}} ), pytest.raises( ValidationException, match=re.escape( - f"Subscription sub_name is a string, but " - f"the subscription value is not set to an override variable" + "Validation error in [INDENTS_IN_ERR_MSG].sub_name: Subscription " + "sub_name is a string, but the subscription value is not set to an override variable" + ), + ): + _ = Subscription.from_file_path(config=config_file, subscription_path="mocked") + + +def test_subscription_file_using_conflicting_preset_name(config_file: ConfigFile): + with mock_load_yaml( + preset_dict={ + "[INDENTS_IN_ERR_MSG]": { + "[ANOTHER]": {"jellyfin_tv_show_by_date": "single value, __value__ not defined"} + } + } + ), pytest.raises( + ValidationException, + match=re.escape( + "Validation error in [INDENTS_IN_ERR_MSG].[ANOTHER].jellyfin_tv_show_by_date: " + "jellyfin_tv_show_by_date conflicts with an existing preset name and cannot be used " + "as a subscription name" ), ): _ = Subscription.from_file_path(config=config_file, subscription_path="mocked")