|
21 | 21 | import pytest
|
22 | 22 | from httmock import HTTMock, response, urlmatch, with_httmock # noqa
|
23 | 23 |
|
24 |
| -from gitlab import Gitlab, GitlabList, USER_AGENT |
| 24 | +from gitlab import DEFAULT_URL, Gitlab, GitlabList, USER_AGENT |
25 | 25 | from gitlab.v4.objects import CurrentUser
|
26 | 26 |
|
| 27 | +localhost = "http://localhost" |
27 | 28 | username = "username"
|
28 | 29 | user_id = 1
|
| 30 | +token = "abc123" |
29 | 31 |
|
30 | 32 |
|
31 | 33 | @urlmatch(scheme="http", netloc="localhost", path="/api/v4/user", method="get")
|
@@ -127,6 +129,47 @@ def test_gitlab_token_auth(gl, callback=None):
|
127 | 129 | assert isinstance(gl.user, CurrentUser)
|
128 | 130 |
|
129 | 131 |
|
| 132 | +def test_gitlab_default_url(): |
| 133 | + gl = Gitlab() |
| 134 | + assert gl.url == DEFAULT_URL |
| 135 | + |
| 136 | + |
| 137 | +@pytest.mark.parametrize( |
| 138 | + "args, kwargs, expected_url, expected_private_token, expected_oauth_token", |
| 139 | + [ |
| 140 | + ([], {}, DEFAULT_URL, None, None), |
| 141 | + ([None, token], {}, DEFAULT_URL, token, None), |
| 142 | + ([localhost], {}, localhost, None, None), |
| 143 | + ([localhost, token], {}, localhost, token, None), |
| 144 | + ([localhost, None, token], {}, localhost, None, token), |
| 145 | + ([], {"private_token": token}, DEFAULT_URL, token, None), |
| 146 | + ([], {"oauth_token": token}, DEFAULT_URL, None, token), |
| 147 | + ([], {"url": localhost}, localhost, None, None), |
| 148 | + ([], {"url": localhost, "private_token": token}, localhost, token, None), |
| 149 | + ([], {"url": localhost, "oauth_token": token}, localhost, None, token), |
| 150 | + ], |
| 151 | + ids=[ |
| 152 | + "no_args", |
| 153 | + "args_private_token", |
| 154 | + "args_url", |
| 155 | + "args_url_private_token", |
| 156 | + "args_url_oauth_token", |
| 157 | + "kwargs_private_token", |
| 158 | + "kwargs_oauth_token", |
| 159 | + "kwargs_url", |
| 160 | + "kwargs_url_private_token", |
| 161 | + "kwargs_url_oauth_token", |
| 162 | + ], |
| 163 | +) |
| 164 | +def test_gitlab_args_kwargs( |
| 165 | + args, kwargs, expected_url, expected_private_token, expected_oauth_token |
| 166 | +): |
| 167 | + gl = Gitlab(*args, **kwargs) |
| 168 | + assert gl.url == expected_url |
| 169 | + assert gl.private_token == expected_private_token |
| 170 | + assert gl.oauth_token == expected_oauth_token |
| 171 | + |
| 172 | + |
130 | 173 | def test_gitlab_from_config(default_config):
|
131 | 174 | config_path = default_config
|
132 | 175 | Gitlab.from_config("one", [config_path])
|
|
0 commit comments