diff options
| author | John L. Villalovos <john@sodarock.com> | 2022-01-05 21:17:05 -0800 |
|---|---|---|
| committer | John L. Villalovos <john@sodarock.com> | 2022-01-05 21:17:05 -0800 |
| commit | ee136356c83b3cbf12d51729c1f401e924e2d6e2 (patch) | |
| tree | 4c65222143e8dfb171d562092d716f13f196c2bf | |
| parent | a349793307e3a975bb51f864b48e5e9825f70182 (diff) | |
| download | gitlab-ee136356c83b3cbf12d51729c1f401e924e2d6e2.tar.gz | |
chore: require keyword-only arguments for client.http_request()
Require keyword-only arguments for client.http_request()
Also change the name of the variable 'verb' to 'method' to match the
call to requests.request()
| -rw-r--r-- | gitlab/client.py | 25 | ||||
| -rw-r--r-- | tests/unit/test_gitlab_http_methods.py | 20 |
2 files changed, 26 insertions, 19 deletions
diff --git a/gitlab/client.py b/gitlab/client.py index b791c8f..b2369b6 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -549,7 +549,7 @@ class Gitlab(object): def _check_redirects(self, result: requests.Response) -> None: # Check the requests history to detect 301/302 redirections. - # If the initial verb is POST or PUT, the redirected request will use a + # If the initial method is POST or PUT, the redirected request will use a # GET request, leading to unwanted behaviour. # If we detect a redirection with a POST or a PUT request, we # raise an exception with a useful error message. @@ -606,7 +606,8 @@ class Gitlab(object): def http_request( self, - verb: str, + *, + method: str, path: str, query_data: Optional[Dict[str, Any]] = None, post_data: Optional[Union[Dict[str, Any], bytes]] = None, @@ -621,7 +622,7 @@ class Gitlab(object): """Make an HTTP request to the Gitlab server. Args: - verb: The HTTP method to call ('get', 'post', 'put', 'delete') + method: The HTTP method to call ('get', 'post', 'put', 'delete') path: Path or full URL to query ('/projects' or 'http://whatever/v4/api/projecs') query_data: Data to send as query parameters @@ -678,7 +679,7 @@ class Gitlab(object): cur_retries = 0 while True: result = self.session.request( - method=verb, + method=method, url=url, json=json, data=data, @@ -759,7 +760,7 @@ class Gitlab(object): """ query_data = query_data or {} result = self.http_request( - "get", path, query_data=query_data, streamed=streamed, **kwargs + method="get", path=path, query_data=query_data, streamed=streamed, **kwargs ) if ( @@ -856,8 +857,8 @@ class Gitlab(object): post_data = post_data or {} result = self.http_request( - "post", - path, + method="post", + path=path, query_data=query_data, post_data=post_data, files=files, @@ -904,8 +905,8 @@ class Gitlab(object): post_data = post_data or {} result = self.http_request( - "put", - path, + method="put", + path=path, query_data=query_data, post_data=post_data, files=files, @@ -933,7 +934,7 @@ class Gitlab(object): Raises: GitlabHttpError: When the return code is not 2xx """ - return self.http_request("delete", path, **kwargs) + return self.http_request(method="delete", path=path, **kwargs) @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError) def search( @@ -987,7 +988,9 @@ class GitlabList(object): self, url: str, query_data: Optional[Dict[str, Any]] = None, **kwargs: Any ) -> None: query_data = query_data or {} - result = self._gl.http_request("get", url, query_data=query_data, **kwargs) + result = self._gl.http_request( + method="get", path=url, query_data=query_data, **kwargs + ) try: links = result.links if links: diff --git a/tests/unit/test_gitlab_http_methods.py b/tests/unit/test_gitlab_http_methods.py index ba57c31..2706579 100644 --- a/tests/unit/test_gitlab_http_methods.py +++ b/tests/unit/test_gitlab_http_methods.py @@ -22,7 +22,7 @@ def test_http_request(gl): return response(200, content, headers, None, 5, request) with HTTMock(resp_cont): - http_r = gl.http_request("get", "/projects") + http_r = gl.http_request(method="get", path="/projects") http_r.json() assert http_r.status_code == 200 @@ -35,7 +35,7 @@ def test_http_request_404(gl): with HTTMock(resp_cont): with pytest.raises(GitlabHttpError): - gl.http_request("get", "/not_there") + gl.http_request(method="get", path="/not_there") @pytest.mark.parametrize("status_code", [500, 502, 503, 504]) @@ -50,7 +50,7 @@ def test_http_request_with_only_failures(gl, status_code): with HTTMock(resp_cont): with pytest.raises(GitlabHttpError): - gl.http_request("get", "/projects") + gl.http_request(method="get", path="/projects") assert call_count == 1 @@ -74,7 +74,9 @@ def test_http_request_with_retry_on_method_for_transient_failures(gl): ) with HTTMock(resp_cont): - http_r = gl.http_request("get", "/projects", retry_transient_errors=True) + http_r = gl.http_request( + method="get", path="/projects", retry_transient_errors=True + ) assert http_r.status_code == 200 assert call_count == calls_before_success @@ -99,7 +101,7 @@ def test_http_request_with_retry_on_class_for_transient_failures(gl_retry): ) with HTTMock(resp_cont): - http_r = gl_retry.http_request("get", "/projects") + http_r = gl_retry.http_request(method="get", path="/projects") assert http_r.status_code == 200 assert call_count == calls_before_success @@ -118,7 +120,9 @@ def test_http_request_with_retry_on_class_and_method_for_transient_failures(gl_r with HTTMock(resp_cont): with pytest.raises(GitlabHttpError): - gl_retry.http_request("get", "/projects", retry_transient_errors=False) + gl_retry.http_request( + method="get", path="/projects", retry_transient_errors=False + ) assert call_count == 1 @@ -181,7 +185,7 @@ def test_http_request_302_get_does_not_raise(gl): return resp_obj with HTTMock(resp_cont): - gl.http_request(verb=method, path=api_path) + gl.http_request(method=method, path=api_path) def test_http_request_302_put_raises_redirect_error(gl): @@ -203,7 +207,7 @@ def test_http_request_302_put_raises_redirect_error(gl): with HTTMock(resp_cont): with pytest.raises(RedirectError) as exc: - gl.http_request(verb=method, path=api_path) + gl.http_request(method=method, path=api_path) error_message = exc.value.error_message assert "Moved Temporarily" in error_message assert "http://localhost/api/v4/user/status" in error_message |
