Skip to content

Commit

Permalink
fix: The PATCH method should be used to update a team (#44)
Browse files Browse the repository at this point in the history
* fix: The PATCH method should be used to update a team

* fix: Annotations of Client methods should contain MoiraApiError instead of HTTPError
  • Loading branch information
SharUpOff authored Feb 5, 2025
1 parent 587aa56 commit 8cf4699
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.3.2

The PATCH method should be used to update a team

# 4.3.1

Fix package issues
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.1
4.3.2
30 changes: 26 additions & 4 deletions moira_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get(self, path='', **kwargs):
:param kwargs: additional parameters for request
:return: dict response
:raises: HTTPError
:raises: MoiraApiError
:raises: InvalidJSONError
"""
r = requests.get(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
Expand All @@ -90,7 +90,7 @@ def delete(self, path='', **kwargs):
:param kwargs: additional parameters for request
:return: dict response
:raises: HTTPError
:raises: MoiraApiError
:raises: InvalidJSONError
"""
r = requests.delete(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
Expand All @@ -112,7 +112,7 @@ def put(self, path='', **kwargs):
:param kwargs: additional parameters for request
:return: dict response
:raises: HTTPError
:raises: MoiraApiError
:raises: InvalidJSONError
"""
r = requests.put(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
Expand All @@ -127,14 +127,36 @@ def put(self, path='', **kwargs):
except ValueError:
raise InvalidJSONError(r.content)

def patch(self, path='', **kwargs):
"""
:param path: str api path
:param kwargs: additional parameters for request
:return: dict response
:raises: MoiraApiError
:raises: InvalidJSONError
"""
r = requests.patch(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)

try:
r.raise_for_status()
except requests.exceptions.HTTPError as err:
raise MoiraApiError(r.content)

try:
return r.json()
except ValueError:
raise InvalidJSONError(r.content)

def post(self, path='', **kwargs):
"""
:param path: str api path
:param kwargs: additional parameters for request
:return: dict response
:raises: HTTPError
:raises: MoiraApiError
:raises: InvalidJSONError
"""
r = requests.post(self._path_join(path), headers=self.headers, auth=self.auth, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion moira_client/models/team/_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update(self, team_id: str, team: TeamModel) -> SaveTeamResponse:
"description": team.description,
}

response = self._client.put(self._full_path(team_id), json=payload)
response = self._client.patch(self._full_path(team_id), json=payload)

return SaveTeamResponse(**response)

Expand Down
2 changes: 1 addition & 1 deletion tests/models/team/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_get(self):
assert response.description == self._response_data["description"]

def test_update(self):
with patch.object(self._client, "put", return_value=self._single_response_data) as request:
with patch.object(self._client, "patch", return_value=self._single_response_data) as request:
response = self._manager.update(self._team.id, self._team)

assert len(request.mock_calls) == 1
Expand Down

0 comments on commit 8cf4699

Please sign in to comment.