diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-07-22 22:31:24 +0200 |
---|---|---|
committer | John Villalovos <john@sodarock.com> | 2022-07-22 14:28:11 -0700 |
commit | ac46c1cb291c03ad14bc76f5f16c9f98f2a5a82d (patch) | |
tree | 090dd85936621a01138f8ad177c23dd77568394b | |
parent | 789ef81585942dd6b935ffe58630025a19436a46 (diff) | |
download | gitlab-ac46c1cb291c03ad14bc76f5f16c9f98f2a5a82d.tar.gz |
fix(config): raise error when gitlab id provided but no config file found
-rw-r--r-- | gitlab/config.py | 5 | ||||
-rw-r--r-- | tests/unit/test_gitlab.py | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/gitlab/config.py b/gitlab/config.py index 2e98b59..2fe058a 100644 --- a/gitlab/config.py +++ b/gitlab/config.py @@ -128,6 +128,11 @@ class GitlabConfigParser: if self._files: self._parse_config() + if self.gitlab_id and not self._files: + raise GitlabConfigMissingError( + f"A gitlab id was provided ({self.gitlab_id}) but no config file found" + ) + def _parse_config(self) -> None: _config = configparser.ConfigParser() _config.read(self._files) diff --git a/tests/unit/test_gitlab.py b/tests/unit/test_gitlab.py index 4189174..7b6b438 100644 --- a/tests/unit/test_gitlab.py +++ b/tests/unit/test_gitlab.py @@ -25,6 +25,7 @@ import pytest import responses import gitlab +from gitlab.config import GitlabConfigMissingError from tests.unit import helpers localhost = "http://localhost" @@ -299,6 +300,11 @@ def test_gitlab_from_config(default_config): gitlab.Gitlab.from_config("one", [config_path]) +def test_gitlab_from_config_without_files_raises(): + with pytest.raises(GitlabConfigMissingError, match="non-existing"): + gitlab.Gitlab.from_config("non-existing") + + def test_gitlab_subclass_from_config(default_config): class MyGitlab(gitlab.Gitlab): pass |