|
21 | 21 | import mock |
22 | 22 | import io |
23 | 23 |
|
24 | | -from gitlab import config |
| 24 | +from gitlab import config, USER_AGENT |
25 | 25 | import pytest |
26 | 26 |
|
27 | 27 |
|
| 28 | +custom_user_agent = "my-package/1.0.0" |
| 29 | + |
28 | 30 | valid_config = u"""[global] |
29 | 31 | default = one |
30 | 32 | ssl_verify = true |
|
51 | 53 | oauth_token = STUV |
52 | 54 | """ |
53 | 55 |
|
| 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 | + |
54 | 67 | no_default_config = u"""[global] |
55 | 68 | [there] |
56 | 69 | url = http://there.url |
@@ -178,3 +191,21 @@ def test_valid_data(m_open, path_exists): |
178 | 191 | assert "STUV" == cp.oauth_token |
179 | 192 | assert 2 == cp.timeout |
180 | 193 | 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 |
0 commit comments