pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python-gitlab/python-gitlab/commit/c5a37e7e37a62372c250dfc8c0799e847eecbc30

link crossorigen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-10539fe0effdbc74.css" /> test(api,cli): add tests for custom user agent · python-gitlab/python-gitlab@c5a37e7 · GitHub
Skip to content

Commit c5a37e7

Browse files
committed
test(api,cli): add tests for custom user agent
1 parent 4bb201b commit c5a37e7

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

gitlab/tests/test_config.py

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

24-
from gitlab import config
24+
from gitlab import config, USER_AGENT
2525
import pytest
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
assert 2 == cp.timeout
180193
assert True == 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+
def test_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+
assert cp.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
import pickle
2020

21+
import pytest
2122
from httmock import HTTMock, response, urlmatch, with_httmock # noqa
2223

23-
from gitlab import Gitlab, GitlabList
24+
from gitlab import Gitlab, GitlabList, USER_AGENT
2425
from gitlab.v4.objects import CurrentUser
2526

2627

@@ -139,3 +140,15 @@ class MyGitlab(Gitlab):
139140
config_path = default_config
140141
gl = MyGitlab.from_config("one", [config_path])
141142
assert isinstance(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+
def test_gitlab_user_agent(kwargs, expected_agent):
153+
gl = Gitlab("http://localhost", **kwargs)
154+
assert gl.headers["User-Agent"] == expected_agent

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy