| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,7 @@ The available methods are: | |||
| 60 | 60 | * ``http_get()`` | |
| 61 | 61 | * ``http_post()`` | |
| 62 | 62 | * ``http_put()`` | |
| 63 | + * ``http_patch()`` | ||
| 63 | 64 | * ``http_delete()`` | |
| 64 | 65 | * ``http_list()`` (a wrapper around ``http_get`` handling pagination, including with lazy generators) | |
| 65 | 66 | * ``http_head()`` (only returns the header dictionary) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1094,6 +1094,54 @@ def http_put( | |||
| 1094 | 1094 | error_message="Failed to parse the server message" | |
| 1095 | 1095 | ) from e | |
| 1096 | 1096 | ||
| 1097 | + def http_patch( | ||
| 1098 | + self, | ||
| 1099 | + path: str, | ||
| 1100 | + *, | ||
| 1101 | + query_data: Optional[Dict[str, Any]] = None, | ||
| 1102 | + post_data: Optional[Union[Dict[str, Any], bytes]] = None, | ||
| 1103 | + raw: bool = False, | ||
| 1104 | + **kwargs: Any, | ||
| 1105 | + ) -> Union[Dict[str, Any], requests.Response]: | ||
| 1106 | + """Make a PATCH request to the Gitlab server. | ||
| 1107 | + | ||
| 1108 | + Args: | ||
| 1109 | + path: Path or full URL to query ('/projects' or | ||
| 1110 | + 'http://whatever/v4/api/projecs') | ||
| 1111 | + query_data: Data to send as query parameters | ||
| 1112 | + post_data: Data to send in the body (will be converted to | ||
| 1113 | + json by default) | ||
| 1114 | + raw: If True, do not convert post_data to json | ||
| 1115 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 1116 | + | ||
| 1117 | + Returns: | ||
| 1118 | + The parsed json returned by the server. | ||
| 1119 | + | ||
| 1120 | + Raises: | ||
| 1121 | + GitlabHttpError: When the return code is not 2xx | ||
| 1122 | + GitlabParsingError: If the json data could not be parsed | ||
| 1123 | + """ | ||
| 1124 | + query_data = query_data or {} | ||
| 1125 | + post_data = post_data or {} | ||
| 1126 | + | ||
| 1127 | + result = self.http_request( | ||
| 1128 | + "patch", | ||
| 1129 | + path, | ||
| 1130 | + query_data=query_data, | ||
| 1131 | + post_data=post_data, | ||
| 1132 | + raw=raw, | ||
| 1133 | + **kwargs, | ||
| 1134 | + ) | ||
| 1135 | + try: | ||
| 1136 | + json_result = result.json() | ||
| 1137 | + if TYPE_CHECKING: | ||
| 1138 | + assert isinstance(json_result, dict) | ||
| 1139 | + return json_result | ||
| 1140 | + except Exception as e: | ||
| 1141 | + raise gitlab.exceptions.GitlabParsingError( | ||
| 1142 | + error_message="Failed to parse the server message" | ||
| 1143 | + ) from e | ||
| 1144 | + | ||
| 1097 | 1145 | def http_delete(self, path: str, **kwargs: Any) -> requests.Response: | |
| 1098 | 1146 | """Make a DELETE request to the Gitlab server. | |
| 1099 | 1147 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,7 @@ disable = [ | |||
| 58 | 58 | "too-many-instance-attributes", | |
| 59 | 59 | "too-many-lines", | |
| 60 | 60 | "too-many-locals", | |
| 61 | + "too-many-public-methods", | ||
| 61 | 62 | "too-many-statements", | |
| 62 | 63 | "unsubscriptable-object", | |
| 63 | 64 | ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -809,6 +809,56 @@ def test_put_request_invalid_data(gl): | |||
| 809 | 809 | assert responses.assert_call_count(url, 1) is True | |
| 810 | 810 | ||
| 811 | 811 | ||
| 812 | + @responses.activate | ||
| 813 | + def test_patch_request(gl): | ||
| 814 | + url = "http://localhost/api/v4/projects" | ||
| 815 | + responses.add( | ||
| 816 | + method=responses.PATCH, | ||
| 817 | + url=url, | ||
| 818 | + json={"name": "project1"}, | ||
| 819 | + status=200, | ||
| 820 | + match=helpers.MATCH_EMPTY_QUERY_PARAMS, | ||
| 821 | + ) | ||
| 822 | + | ||
| 823 | + result = gl.http_patch("/projects") | ||
| 824 | + assert isinstance(result, dict) | ||
| 825 | + assert result["name"] == "project1" | ||
| 826 | + assert responses.assert_call_count(url, 1) is True | ||
| 827 | + | ||
| 828 | + | ||
| 829 | + @responses.activate | ||
| 830 | + def test_patch_request_404(gl): | ||
| 831 | + url = "http://localhost/api/v4/not_there" | ||
| 832 | + responses.add( | ||
| 833 | + method=responses.PATCH, | ||
| 834 | + url=url, | ||
| 835 | + json=[], | ||
| 836 | + status=404, | ||
| 837 | + match=helpers.MATCH_EMPTY_QUERY_PARAMS, | ||
| 838 | + ) | ||
| 839 | + | ||
| 840 | + with pytest.raises(GitlabHttpError): | ||
| 841 | + gl.http_patch("/not_there") | ||
| 842 | + assert responses.assert_call_count(url, 1) is True | ||
| 843 | + | ||
| 844 | + | ||
| 845 | + @responses.activate | ||
| 846 | + def test_patch_request_invalid_data(gl): | ||
| 847 | + url = "http://localhost/api/v4/projects" | ||
| 848 | + responses.add( | ||
| 849 | + method=responses.PATCH, | ||
| 850 | + url=url, | ||
| 851 | + body='["name": "project1"]', | ||
| 852 | + content_type="application/json", | ||
| 853 | + status=200, | ||
| 854 | + match=helpers.MATCH_EMPTY_QUERY_PARAMS, | ||
| 855 | + ) | ||
| 856 | + | ||
| 857 | + with pytest.raises(GitlabParsingError): | ||
| 858 | + gl.http_patch("/projects") | ||
| 859 | + assert responses.assert_call_count(url, 1) is True | ||
| 860 | + | ||
| 861 | + | ||
| 812 | 862 | @responses.activate | |
| 813 | 863 | def test_delete_request(gl): | |
| 814 | 864 | url = "http://localhost/api/v4/projects" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments