Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

feat: allow passing kwargs to Gitlab class when instantiating withfrom_config#2392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intopython-gitlab:mainfromlmilbaum:custom_session
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletionsdocs/api-usage-advanced.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,15 @@ on your own, such as for nested API responses and ``Union`` return types. For ex
ifTYPE_CHECKING:
assertisinstance(license["plan"],str)
Custom session (Bring your own Session)
---------------------------------------

You can use configuration files and a custom session to create
``gitlab.Gitlab`` objects:

..code-block::python
gl= gitlab.Gitlab.from_config('somewhere', ['/tmp/gl.cfg'],session=custom_session)
9 changes: 8 additions & 1 deletiongitlab/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -232,14 +232,20 @@ def api_version(self) -> str:

@classmethod
def from_config(
cls, gitlab_id: Optional[str] = None, config_files: Optional[List[str]] = None
cls,
gitlab_id: Optional[str] = None,
config_files: Optional[List[str]] = None,
**kwargs: Any,
) -> "Gitlab":
"""Create a Gitlab connection from configuration files.

Args:
gitlab_id: ID of the configuration section.
config_files list[str]: List of paths to configuration files.

kwargs:
session requests.Session: Custom requests Session

Returns:
A Gitlab connection.

Expand All@@ -264,6 +270,7 @@ def from_config(
order_by=config.order_by,
user_agent=config.user_agent,
retry_transient_errors=config.retry_transient_errors,
**kwargs,
)

@classmethod
Expand Down
19 changes: 19 additions & 0 deletionstests/functional/api/test_gitlab.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import pytest
import requests

import gitlab

Expand All@@ -23,6 +24,24 @@ def test_auth_from_config(gl, temp_dir):
assert isinstance(test_gitlab.user, gitlab.v4.objects.CurrentUser)


def test_no_custom_session(gl, temp_dir):
"""Test no custom session"""
custom_session = requests.Session()
test_gitlab = gitlab.Gitlab.from_config(
config_files=[temp_dir / "python-gitlab.cfg"]
)
assert test_gitlab.session != custom_session


def test_custom_session(gl, temp_dir):
"""Test custom session"""
custom_session = requests.Session()
test_gitlab = gitlab.Gitlab.from_config(
config_files=[temp_dir / "python-gitlab.cfg"], session=custom_session
)
assert test_gitlab.session == custom_session


def test_broadcast_messages(gl, get_all_kwargs):
msg = gl.broadcastmessages.create({"message": "this is the message"})
msg.color = "#444444"
Expand Down
23 changes: 23 additions & 0 deletionstests/unit/test_gitlab.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
from http.client import HTTPConnection

import pytest
import requests
import responses

import gitlab
Expand DownExpand Up@@ -412,3 +413,25 @@ def test_gitlab_keep_base_url(kwargs, link_header, expected_next_url, show_warni
else:
obj = gl.http_list("/tests", iterator=True)
assert obj._next_url == expected_next_url


def test_no_custom_session(default_config):
"""Test no custom session"""

config_path = default_config
custom_session = requests.Session()
test_gitlab = gitlab.Gitlab.from_config("one", [config_path])

assert test_gitlab.session != custom_session


def test_custom_session(default_config):
"""Test custom session"""

config_path = default_config
custom_session = requests.Session()
test_gitlab = gitlab.Gitlab.from_config(
"one", [config_path], session=custom_session
)

assert test_gitlab.session == custom_session

[8]ページ先頭

©2009-2025 Movatter.jp