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

Commitc5a37e7

Browse files
committed
test(api,cli): add tests for custom user agent
1 parent4bb201b commitc5a37e7

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

‎gitlab/tests/test_config.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
importmock
2222
importio
2323

24-
fromgitlabimportconfig
24+
fromgitlabimportconfig,USER_AGENT
2525
importpytest
2626

2727

28+
custom_user_agent="my-package/1.0.0"
29+
2830
valid_config=u"""[global]
2931
default = one
3032
ssl_verify = true
@@ -51,6 +53,17 @@
5153
oauth_token = STUV
5254
"""
5355

56+
custom_user_agent_config="""[global]
57+
default = one
58+
user_agent = {}
59+
60+
[one]
61+
url = http://one.url
62+
private_token = ABCDEF
63+
""".format(
64+
custom_user_agent
65+
)
66+
5467
no_default_config=u"""[global]
5568
[there]
5669
url = http://there.url
@@ -178,3 +191,21 @@ def test_valid_data(m_open, path_exists):
178191
assert"STUV"==cp.oauth_token
179192
assert2==cp.timeout
180193
assertTrue==cp.ssl_verify
194+
195+
196+
@mock.patch("os.path.exists")
197+
@mock.patch("builtins.open")
198+
@pytest.mark.parametrize(
199+
"config_string,expected_agent",
200+
[
201+
(valid_config,USER_AGENT),
202+
(custom_user_agent_config,custom_user_agent),
203+
],
204+
)
205+
deftest_config_user_agent(m_open,path_exists,config_string,expected_agent):
206+
fd=io.StringIO(config_string)
207+
fd.close=mock.Mock(return_value=None)
208+
m_open.return_value=fd
209+
210+
cp=config.GitlabConfigParser()
211+
assertcp.user_agent==expected_agent

‎gitlab/tests/test_gitlab.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
importpickle
2020

21+
importpytest
2122
fromhttmockimportHTTMock,response,urlmatch,with_httmock# noqa
2223

23-
fromgitlabimportGitlab,GitlabList
24+
fromgitlabimportGitlab,GitlabList,USER_AGENT
2425
fromgitlab.v4.objectsimportCurrentUser
2526

2627

@@ -139,3 +140,15 @@ class MyGitlab(Gitlab):
139140
config_path=default_config
140141
gl=MyGitlab.from_config("one", [config_path])
141142
assertisinstance(gl,MyGitlab)
143+
144+
145+
@pytest.mark.parametrize(
146+
"kwargs,expected_agent",
147+
[
148+
({},USER_AGENT),
149+
({"user_agent":"my-package/1.0.0"},"my-package/1.0.0"),
150+
],
151+
)
152+
deftest_gitlab_user_agent(kwargs,expected_agent):
153+
gl=Gitlab("http://localhost",**kwargs)
154+
assertgl.headers["User-Agent"]==expected_agent

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp