From e9c123459facc28e8a3f0872a1e06d7123254785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 9 Apr 2021 16:49:41 +0200 Subject: [PATCH] Break loop when we have the correct file (#2796) * Break loop when we have the correct file * Fix tests --- supervisor/store/repository.py | 7 ++++--- tests/store/test_custom_repository.py | 11 +++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/supervisor/store/repository.py b/supervisor/store/repository.py index a0f5424f8..c5e474baf 100644 --- a/supervisor/store/repository.py +++ b/supervisor/store/repository.py @@ -82,8 +82,8 @@ class Repository(CoreSysAttributes): # If exists? for filetype in FILE_SUFFIX_CONFIGURATION: repository_file = Path(self.git.path / f"repository{filetype}") - if not repository_file.exists(): - continue + if repository_file.exists(): + break if not repository_file.exists(): return False @@ -91,7 +91,8 @@ class Repository(CoreSysAttributes): # If valid? try: 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 True diff --git a/tests/store/test_custom_repository.py b/tests/store/test_custom_repository.py index 32d39b1c5..e276f6531 100644 --- a/tests/store/test_custom_repository.py +++ b/tests/store/test_custom_repository.py @@ -13,9 +13,10 @@ async def test_add_valid_repository(coresys, store_manager): """Test add custom repository.""" current = coresys.config.addons_repositories with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "pathlib.Path.read_text", - return_value=json.dumps({"name": "Awesome repository"}), + "supervisor.utils.common.read_yaml_file", + return_value={"name": "Awesome repository"}, ), patch("pathlib.Path.exists", return_value=True): + await store_manager.update_repositories(current + ["http://example.com"]) assert store_manager.get_from_url("http://example.com").validate() 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.""" current = coresys.config.addons_repositories with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "pathlib.Path.read_text", - return_value=json.dumps( - {"name": "Awesome repository", "url": "http://example2.com/docs"} - ), + "supervisor.utils.common.read_yaml_file", + return_value={"name": "Awesome repository"}, ), patch("pathlib.Path.exists", return_value=True): await store_manager.update_repositories(current + ["http://example.com"]) assert store_manager.get_from_url("http://example.com").validate()