diff options
author | Omar Mochtar <iomarmochtar@gmail.com> | 2022-08-03 22:09:17 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 17:09:17 +0200 |
commit | e2ea8b89a7b0aebdb1eb3b99196d7c0034076df8 (patch) | |
tree | e16b745e0d1502424e089ede402889a9f5f2d7fa /tests/unit/test_gitlab.py | |
parent | 1136b17f4e5f36c66c3a67292e508b43ded9ca3e (diff) | |
download | gitlab-e2ea8b89a7b0aebdb1eb3b99196d7c0034076df8.tar.gz |
fix: optionally keep user-provided base URL for pagination (#2149)
Diffstat (limited to 'tests/unit/test_gitlab.py')
-rw-r--r-- | tests/unit/test_gitlab.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/unit/test_gitlab.py b/tests/unit/test_gitlab.py index 203f123..900a652 100644 --- a/tests/unit/test_gitlab.py +++ b/tests/unit/test_gitlab.py @@ -353,3 +353,58 @@ def test_gitlab_plain_const_does_not_warn(recwarn): assert not recwarn assert no_access == 0 + + +@responses.activate +@pytest.mark.parametrize( + "kwargs,link_header,expected_next_url,show_warning", + [ + ( + {}, + "<http://localhost/api/v4/tests?per_page=1&page=2>;" ' rel="next"', + "http://localhost/api/v4/tests?per_page=1&page=2", + False, + ), + ( + {}, + "<http://orig_host/api/v4/tests?per_page=1&page=2>;" ' rel="next"', + "http://orig_host/api/v4/tests?per_page=1&page=2", + True, + ), + ( + {"keep_base_url": True}, + "<http://orig_host/api/v4/tests?per_page=1&page=2>;" ' rel="next"', + "http://localhost/api/v4/tests?per_page=1&page=2", + False, + ), + ], + ids=["url-match-does-not-warn", "url-mismatch-warns", "url-mismatch-keeps-url"], +) +def test_gitlab_keep_base_url(kwargs, link_header, expected_next_url, show_warning): + responses.add( + **{ + "method": responses.GET, + "url": "http://localhost/api/v4/tests", + "json": [{"a": "b"}], + "headers": { + "X-Page": "1", + "X-Next-Page": "2", + "X-Per-Page": "1", + "X-Total-Pages": "2", + "X-Total": "2", + "Link": (link_header), + }, + "content_type": "application/json", + "status": 200, + "match": helpers.MATCH_EMPTY_QUERY_PARAMS, + } + ) + + gl = gitlab.Gitlab(url="http://localhost", **kwargs) + if show_warning: + with pytest.warns(UserWarning) as warn_record: + obj = gl.http_list("/tests", iterator=True) + assert len(warn_record) == 1 + else: + obj = gl.http_list("/tests", iterator=True) + assert obj._next_url == expected_next_url |