diff --git a/custom_components/hacs/hacsbase/configuration.py b/custom_components/hacs/hacsbase/configuration.py index 41ff8a453a5..674fa39df60 100644 --- a/custom_components/hacs/hacsbase/configuration.py +++ b/custom_components/hacs/hacsbase/configuration.py @@ -35,11 +35,14 @@ class Configuration: def from_dict(configuration: dict, options: dict): """Set attributes from dicts.""" if isinstance(options, bool) or isinstance(configuration.get("options"), bool): - raise HacsUserScrewupException("That is not valid.") + raise HacsUserScrewupException("Configuration is not valid.") if options is None: options = {} + if not configuration: + raise HacsUserScrewupException("Configuration is not valid.") + return Configuration( config=configuration, options=options, diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 768f1c23805..9942c6b2173 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -2,6 +2,7 @@ # pylint: disable=missing-docstring import pytest from custom_components.hacs.hacsbase.configuration import Configuration +from custom_components.hacs.hacsbase.exceptions import HacsUserScrewupException def test_configuration_and_option(): @@ -40,13 +41,15 @@ def test_configuration_and_option(): assert not config.experimental -def test_configuration_only_pass_dict(): - assert Configuration.from_dict({"token": "xxxxxxxxxx"}, {}) +def test_edge_option_only_pass_empty_dict_as_configuration(): + with pytest.raises(HacsUserScrewupException): + assert Configuration.from_dict({}, {"experimental": True}) -def test_option_only_pass_dict(): - assert Configuration.from_dict({}, {"experimental": True}) +def test_edge_configuration_only_pass_none_as_option(): + assert Configuration.from_dict({"token": "xxxxxxxxxx"}, None) -def test_configuration_only_pass_none(): - assert Configuration.from_dict({"token": "xxxxxxxxxx"}, None) +def test_edge_options_true(): + with pytest.raises(HacsUserScrewupException): + assert Configuration.from_dict({"options": True}, None)