|
86 | 86 | """
|
87 | 87 |
|
88 | 88 |
|
| 89 | +def global_retry_transient_errors(value: bool) -> str: |
| 90 | + return u"""[global] |
| 91 | +default = one |
| 92 | +retry_transient_errors={} |
| 93 | +
|
| 94 | +[one] |
| 95 | +url = http://one.url |
| 96 | +private_token = ABCDEF""".format( |
| 97 | + value |
| 98 | + ) |
| 99 | + |
| 100 | + |
| 101 | +def global_and_gitlab_retry_transient_errors( |
| 102 | + global_value: bool, gitlab_value: bool |
| 103 | +) -> str: |
| 104 | + return u"""[global] |
| 105 | + default = one |
| 106 | + retry_transient_errors={global_value} |
| 107 | +
|
| 108 | + [one] |
| 109 | + url = http://one.url |
| 110 | + private_token = ABCDEF |
| 111 | + retry_transient_errors={gitlab_value}""".format( |
| 112 | + global_value=global_value, gitlab_value=gitlab_value |
| 113 | + ) |
| 114 | + |
| 115 | + |
89 | 116 | @mock.patch.dict(os.environ, {"PYTHON_GITLAB_CFG": "/some/path"})
|
90 | 117 | def test_env_config_present():
|
91 | 118 | assert ["/some/path"] == config._env_config()
|
@@ -245,3 +272,48 @@ def test_config_user_agent(m_open, path_exists, config_string, expected_agent):
|
245 | 272 |
|
246 | 273 | cp = config.GitlabConfigParser()
|
247 | 274 | assert cp.user_agent == expected_agent
|
| 275 | + |
| 276 | + |
| 277 | +@mock.patch("os.path.exists") |
| 278 | +@mock.patch("builtins.open") |
| 279 | +@pytest.mark.parametrize( |
| 280 | + "config_string,expected", |
| 281 | + [ |
| 282 | + pytest.param(valid_config, False, id="default_value"), |
| 283 | + pytest.param( |
| 284 | + global_retry_transient_errors(True), "True", id="global_config_true" |
| 285 | + ), |
| 286 | + pytest.param( |
| 287 | + global_retry_transient_errors(False), "False", id="global_config_false" |
| 288 | + ), |
| 289 | + pytest.param( |
| 290 | + global_and_gitlab_retry_transient_errors(False, True), |
| 291 | + "True", |
| 292 | + id="gitlab_overrides_global_true", |
| 293 | + ), |
| 294 | + pytest.param( |
| 295 | + global_and_gitlab_retry_transient_errors(True, False), |
| 296 | + "False", |
| 297 | + id="gitlab_overrides_global_false", |
| 298 | + ), |
| 299 | + pytest.param( |
| 300 | + global_and_gitlab_retry_transient_errors(True, True), |
| 301 | + "True", |
| 302 | + id="gitlab_equals_global_true", |
| 303 | + ), |
| 304 | + pytest.param( |
| 305 | + global_and_gitlab_retry_transient_errors(False, False), |
| 306 | + "False", |
| 307 | + id="gitlab_equals_global_false", |
| 308 | + ), |
| 309 | + ], |
| 310 | +) |
| 311 | +def test_config_retry_transient_errors_when_global_config_is_set( |
| 312 | + m_open, path_exists, config_string, expected |
| 313 | +): |
| 314 | + fd = io.StringIO(config_string) |
| 315 | + fd.close = mock.Mock(return_value=None) |
| 316 | + m_open.return_value = fd |
| 317 | + |
| 318 | + cp = config.GitlabConfigParser() |
| 319 | + assert cp.retry_transient_errors == expected |
0 commit comments