Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1ef7018

Browse filesBrowse files
nejchJohnVillalovos
authored andcommitted
fix(config): raise error when gitlab id provided but no config section found
1 parent ac46c1c commit 1ef7018
Copy full SHA for 1ef7018

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Open diff view settings
Collapse file

‎gitlab/config.py‎

Copy file name to clipboardExpand all lines: gitlab/config.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ def _parse_config(self) -> None:
137137
_config = configparser.ConfigParser()
138138
_config.read(self._files)
139139

140+
if self.gitlab_id and not _config.has_section(self.gitlab_id):
141+
raise GitlabDataError(
142+
f"A gitlab id was provided ({self.gitlab_id}) "
143+
"but no config section found"
144+
)
145+
140146
if self.gitlab_id is None:
141147
try:
142148
self.gitlab_id = _config.get("global", "default")
Collapse file

‎tests/unit/test_gitlab.py‎

Copy file name to clipboardExpand all lines: tests/unit/test_gitlab.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import responses
2626

2727
import gitlab
28-
from gitlab.config import GitlabConfigMissingError
28+
from gitlab.config import GitlabConfigMissingError, GitlabDataError
2929
from tests.unit import helpers
3030

3131
localhost = "http://localhost"
@@ -305,6 +305,11 @@ def test_gitlab_from_config_without_files_raises():
305305
gitlab.Gitlab.from_config("non-existing")
306306

307307

308+
def test_gitlab_from_config_with_wrong_gitlab_id_raises(default_config):
309+
with pytest.raises(GitlabDataError, match="non-existing"):
310+
gitlab.Gitlab.from_config("non-existing", [default_config])
311+
312+
308313
def test_gitlab_subclass_from_config(default_config):
309314
class MyGitlab(gitlab.Gitlab):
310315
pass

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.