Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(client): addhttp_patch method#2471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intomainfromjlvillal/http_patch
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsdocs/api-levels.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@ The available methods are:
* ``http_get()``
* ``http_post()``
* ``http_put()``
* ``http_patch()``
* ``http_delete()``
* ``http_list()`` (a wrapper around ``http_get`` handling pagination, including with lazy generators)
* ``http_head()`` (only returns the header dictionary)
Expand Down
48 changes: 48 additions & 0 deletionsgitlab/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1094,6 +1094,54 @@ def http_put(
error_message="Failed to parse the server message"
) from e

def http_patch(
self,
path: str,
*,
query_data: Optional[Dict[str, Any]] = None,
post_data: Optional[Union[Dict[str, Any], bytes]] = None,
raw: bool = False,
**kwargs: Any,
) -> Union[Dict[str, Any], requests.Response]:
"""Make a PATCH request to the Gitlab server.

Args:
path: Path or full URL to query ('/projects' or
'http://whatever/v4/api/projecs')
query_data: Data to send as query parameters
post_data: Data to send in the body (will be converted to
json by default)
raw: If True, do not convert post_data to json
**kwargs: Extra options to send to the server (e.g. sudo)

Returns:
The parsed json returned by the server.

Raises:
GitlabHttpError: When the return code is not 2xx
GitlabParsingError: If the json data could not be parsed
"""
query_data = query_data or {}
post_data = post_data or {}

result = self.http_request(
"patch",
path,
query_data=query_data,
post_data=post_data,
raw=raw,
**kwargs,
)
try:
json_result = result.json()
if TYPE_CHECKING:
assert isinstance(json_result, dict)
return json_result
except Exception as e:
raise gitlab.exceptions.GitlabParsingError(
error_message="Failed to parse the server message"
) from e

def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
"""Make a DELETE request to the Gitlab server.

Expand Down
1 change: 1 addition & 0 deletionspyproject.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ disable = [
"too-many-instance-attributes",
"too-many-lines",
"too-many-locals",
"too-many-public-methods",
"too-many-statements",
"unsubscriptable-object",
]
Expand Down
50 changes: 50 additions & 0 deletionstests/unit/test_gitlab_http_methods.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -809,6 +809,56 @@ def test_put_request_invalid_data(gl):
assert responses.assert_call_count(url, 1) is True


@responses.activate
def test_patch_request(gl):
url = "http://localhost/api/v4/projects"
responses.add(
method=responses.PATCH,
url=url,
json={"name": "project1"},
status=200,
match=helpers.MATCH_EMPTY_QUERY_PARAMS,
)

result = gl.http_patch("/projects")
assert isinstance(result, dict)
assert result["name"] == "project1"
assert responses.assert_call_count(url, 1) is True


@responses.activate
def test_patch_request_404(gl):
url = "http://localhost/api/v4/not_there"
responses.add(
method=responses.PATCH,
url=url,
json=[],
status=404,
match=helpers.MATCH_EMPTY_QUERY_PARAMS,
)

with pytest.raises(GitlabHttpError):
gl.http_patch("/not_there")
assert responses.assert_call_count(url, 1) is True


@responses.activate
def test_patch_request_invalid_data(gl):
url = "http://localhost/api/v4/projects"
responses.add(
method=responses.PATCH,
url=url,
body='["name": "project1"]',
content_type="application/json",
status=200,
match=helpers.MATCH_EMPTY_QUERY_PARAMS,
)

with pytest.raises(GitlabParsingError):
gl.http_patch("/projects")
assert responses.assert_call_count(url, 1) is True


@responses.activate
def test_delete_request(gl):
url = "http://localhost/api/v4/projects"
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp