File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ You can also use configuration files to create ``gitlab.Gitlab`` objects:
62
62
63
63
gl = gitlab.Gitlab.from_config(' somewhere' , [' /tmp/gl.cfg' ])
64
64
65
+ With custom session
66
+
67
+ .. code-block :: python
68
+
69
+ gl = gitlab.Gitlab.from_config(' somewhere' , [' /tmp/gl.cfg' ], session = custom_session)
70
+
71
+
65
72
See the :ref: `cli_configuration ` section for more information about
66
73
configuration files.
67
74
Original file line number Diff line number Diff line change @@ -232,14 +232,20 @@ def api_version(self) -> str:
232
232
233
233
@classmethod
234
234
def from_config (
235
- cls , gitlab_id : Optional [str ] = None , config_files : Optional [List [str ]] = None
235
+ cls ,
236
+ gitlab_id : Optional [str ] = None ,
237
+ config_files : Optional [List [str ]] = None ,
238
+ ** kwargs : Any ,
236
239
) -> "Gitlab" :
237
240
"""Create a Gitlab connection from configuration files.
238
241
239
242
Args:
240
243
gitlab_id: ID of the configuration section.
241
244
config_files list[str]: List of paths to configuration files.
242
245
246
+ kwargs:
247
+ session requests.Session: Custom requests Session
248
+
243
249
Returns:
244
250
A Gitlab connection.
245
251
@@ -264,6 +270,7 @@ def from_config(
264
270
order_by = config .order_by ,
265
271
user_agent = config .user_agent ,
266
272
retry_transient_errors = config .retry_transient_errors ,
273
+ ** kwargs ,
267
274
)
268
275
269
276
@classmethod
Original file line number Diff line number Diff line change 1
1
import pytest
2
+ import requests
2
3
3
4
import gitlab
4
5
@@ -23,6 +24,24 @@ def test_auth_from_config(gl, temp_dir):
23
24
assert isinstance (test_gitlab .user , gitlab .v4 .objects .CurrentUser )
24
25
25
26
27
+ def test_no_custom_session (gl , temp_dir ):
28
+ """Test no custom session"""
29
+ custom_session = requests .Session ()
30
+ test_gitlab = gitlab .Gitlab .from_config (
31
+ config_files = [temp_dir / "python-gitlab.cfg" ]
32
+ )
33
+ assert test_gitlab .session != custom_session
34
+
35
+
36
+ def test_custom_session (gl , temp_dir ):
37
+ """Test custom session"""
38
+ custom_session = requests .Session ()
39
+ test_gitlab = gitlab .Gitlab .from_config (
40
+ config_files = [temp_dir / "python-gitlab.cfg" ], session = custom_session
41
+ )
42
+ assert test_gitlab .session == custom_session
43
+
44
+
26
45
def test_broadcast_messages (gl , get_all_kwargs ):
27
46
msg = gl .broadcastmessages .create ({"message" : "this is the message" })
28
47
msg .color = "#444444"
You can’t perform that action at this time.
0 commit comments