full coverage

This commit is contained in:
Jesse Bannon 2023-09-30 00:07:14 -07:00
parent 745ba5114a
commit f9665ff066
2 changed files with 31 additions and 9 deletions

View file

@ -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,

View file

@ -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")