diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-01-31 17:58:20 +0100 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2021-01-31 18:15:12 +0100 |
commit | c5a37e7e37a62372c250dfc8c0799e847eecbc30 (patch) | |
tree | 0c006b3e087a86b75d810cb2983d0c0acb6f0edd /gitlab/tests/test_config.py | |
parent | 4bb201b92ef0dcc14a7a9c83e5600ba5b118fc33 (diff) | |
download | gitlab-c5a37e7e37a62372c250dfc8c0799e847eecbc30.tar.gz |
test(api,cli): add tests for custom user agent
Diffstat (limited to 'gitlab/tests/test_config.py')
-rw-r--r-- | gitlab/tests/test_config.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/gitlab/tests/test_config.py b/gitlab/tests/test_config.py index 7fb03e0..7a9e239 100644 --- a/gitlab/tests/test_config.py +++ b/gitlab/tests/test_config.py @@ -21,10 +21,12 @@ import unittest import mock import io -from gitlab import config +from gitlab import config, USER_AGENT import pytest +custom_user_agent = "my-package/1.0.0" + valid_config = u"""[global] default = one ssl_verify = true @@ -51,6 +53,17 @@ url = https://four.url oauth_token = STUV """ +custom_user_agent_config = """[global] +default = one +user_agent = {} + +[one] +url = http://one.url +private_token = ABCDEF +""".format( + custom_user_agent +) + no_default_config = u"""[global] [there] url = http://there.url @@ -178,3 +191,21 @@ def test_valid_data(m_open, path_exists): assert "STUV" == cp.oauth_token assert 2 == cp.timeout assert True == cp.ssl_verify + + +@mock.patch("os.path.exists") +@mock.patch("builtins.open") +@pytest.mark.parametrize( + "config_string,expected_agent", + [ + (valid_config, USER_AGENT), + (custom_user_agent_config, custom_user_agent), + ], +) +def test_config_user_agent(m_open, path_exists, config_string, expected_agent): + fd = io.StringIO(config_string) + fd.close = mock.Mock(return_value=None) + m_open.return_value = fd + + cp = config.GitlabConfigParser() + assert cp.user_agent == expected_agent |