mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 21:56:29 +00:00
Break loop when we have the correct file (#2796)
* Break loop when we have the correct file * Fix tests
This commit is contained in:
parent
d3e4bb7219
commit
e9c123459f
@ -82,8 +82,8 @@ class Repository(CoreSysAttributes):
|
|||||||
# If exists?
|
# If exists?
|
||||||
for filetype in FILE_SUFFIX_CONFIGURATION:
|
for filetype in FILE_SUFFIX_CONFIGURATION:
|
||||||
repository_file = Path(self.git.path / f"repository{filetype}")
|
repository_file = Path(self.git.path / f"repository{filetype}")
|
||||||
if not repository_file.exists():
|
if repository_file.exists():
|
||||||
continue
|
break
|
||||||
|
|
||||||
if not repository_file.exists():
|
if not repository_file.exists():
|
||||||
return False
|
return False
|
||||||
@ -91,7 +91,8 @@ class Repository(CoreSysAttributes):
|
|||||||
# If valid?
|
# If valid?
|
||||||
try:
|
try:
|
||||||
SCHEMA_REPOSITORY_CONFIG(read_json_or_yaml_file(repository_file))
|
SCHEMA_REPOSITORY_CONFIG(read_json_or_yaml_file(repository_file))
|
||||||
except (ConfigurationFileError, vol.Invalid):
|
except (ConfigurationFileError, vol.Invalid) as err:
|
||||||
|
_LOGGER.warning("Could not validate repository configuration %s", err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -13,9 +13,10 @@ async def test_add_valid_repository(coresys, store_manager):
|
|||||||
"""Test add custom repository."""
|
"""Test add custom repository."""
|
||||||
current = coresys.config.addons_repositories
|
current = coresys.config.addons_repositories
|
||||||
with patch("supervisor.store.repository.Repository.load", return_value=None), patch(
|
with patch("supervisor.store.repository.Repository.load", return_value=None), patch(
|
||||||
"pathlib.Path.read_text",
|
"supervisor.utils.common.read_yaml_file",
|
||||||
return_value=json.dumps({"name": "Awesome repository"}),
|
return_value={"name": "Awesome repository"},
|
||||||
), patch("pathlib.Path.exists", return_value=True):
|
), patch("pathlib.Path.exists", return_value=True):
|
||||||
|
|
||||||
await store_manager.update_repositories(current + ["http://example.com"])
|
await store_manager.update_repositories(current + ["http://example.com"])
|
||||||
assert store_manager.get_from_url("http://example.com").validate()
|
assert store_manager.get_from_url("http://example.com").validate()
|
||||||
assert "http://example.com" in coresys.config.addons_repositories
|
assert "http://example.com" in coresys.config.addons_repositories
|
||||||
@ -26,10 +27,8 @@ async def test_add_valid_repository_url(coresys, store_manager):
|
|||||||
"""Test add custom repository."""
|
"""Test add custom repository."""
|
||||||
current = coresys.config.addons_repositories
|
current = coresys.config.addons_repositories
|
||||||
with patch("supervisor.store.repository.Repository.load", return_value=None), patch(
|
with patch("supervisor.store.repository.Repository.load", return_value=None), patch(
|
||||||
"pathlib.Path.read_text",
|
"supervisor.utils.common.read_yaml_file",
|
||||||
return_value=json.dumps(
|
return_value={"name": "Awesome repository"},
|
||||||
{"name": "Awesome repository", "url": "http://example2.com/docs"}
|
|
||||||
),
|
|
||||||
), patch("pathlib.Path.exists", return_value=True):
|
), patch("pathlib.Path.exists", return_value=True):
|
||||||
await store_manager.update_repositories(current + ["http://example.com"])
|
await store_manager.update_repositories(current + ["http://example.com"])
|
||||||
assert store_manager.get_from_url("http://example.com").validate()
|
assert store_manager.get_from_url("http://example.com").validate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user