diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a917cb..15d6e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.0] +### Added +- Exception for `410` status code in notes endpoint. + ## [2.1.1] ### Fixed - Percent-encoding was not applied on texts entered by the user. [#22](https://github.com/docentYT/osm_easy_api/issues/22) diff --git a/src/osm_easy_api/__init__.py b/src/osm_easy_api/__init__.py index af2f273..e4d5418 100644 --- a/src/osm_easy_api/__init__.py +++ b/src/osm_easy_api/__init__.py @@ -1,4 +1,4 @@ -VERSION = "2.1.1" +VERSION = "2.2.0" from .data_classes import * from .diff import Diff, Frequency diff --git a/src/osm_easy_api/api/endpoints/changeset_discussion.py b/src/osm_easy_api/api/endpoints/changeset_discussion.py index c549e42..21a97c2 100644 --- a/src/osm_easy_api/api/endpoints/changeset_discussion.py +++ b/src/osm_easy_api/api/endpoints/changeset_discussion.py @@ -19,6 +19,7 @@ def comment(self, changeset_id: int, text: str) -> None: Raises: exceptions.ChangesetNotClosed: Changeset must be closed to add comment. + exceptions.TooManyRequests: Request has been blocked due to rate limiting. """ response = self.outer._request(self.outer._RequestMethods.POST, self.outer._url.changeset_discussion["comment"].format(id=changeset_id, text=urllib.parse.quote(text)), self.outer._Requirement.YES, auto_status_code_handling=False) diff --git a/src/osm_easy_api/api/endpoints/notes.py b/src/osm_easy_api/api/endpoints/notes.py index b9305cf..e64d93d 100644 --- a/src/osm_easy_api/api/endpoints/notes.py +++ b/src/osm_easy_api/api/endpoints/notes.py @@ -73,6 +73,7 @@ def get(self, id: int) -> Note: Raises: exceptions.IdNotFoundError: Note with given id cannot be found. + exceptions.ElementDeleted: Note with given id has been hidden by a moderator. Returns: Note: Note object. @@ -85,6 +86,8 @@ def get(self, id: int) -> Note: match status_code: case 200: pass case 404: raise exceptions.IdNotFoundError() + case 410: raise exceptions.ElementDeleted() + case _: assert False, f"Unexpected response status code {status_code}. Please report it on github." # pragma: no cover return self._xml_to_notes_list(generator)[0] @@ -148,6 +151,7 @@ def comment(self, id: int, text: str) -> Note: Raises: exceptions.IdNotFoundError: Cannot find note with given id. exceptions.NoteAlreadyClosed: Note is closed. + exceptions.ElementDeleted: Note with given id has been hidden by a moderator. Returns: Note: Note object of commented note @@ -161,6 +165,7 @@ def comment(self, id: int, text: str) -> Note: case 200: pass case 404: raise exceptions.IdNotFoundError() case 409: raise exceptions.NoteAlreadyClosed() + case 410: raise exceptions.ElementDeleted() case _: assert False, f"Unexpected response status code {status_code}. Please report it on github." # pragma: no cover return self._xml_to_notes_list(generator)[0] @@ -175,6 +180,7 @@ def close(self, id: int, text: str | None = None) -> Note: Raises: exceptions.IdNotFoundError: Cannot find note with given id. exceptions.NoteAlreadyClosed: Note already closed. + exceptions.ElementDeleted: Note with given id has been hidden by a moderator. Returns: Note: Note object of closed note. @@ -191,6 +197,7 @@ def close(self, id: int, text: str | None = None) -> Note: case 200: pass case 404: raise exceptions.IdNotFoundError() case 409: raise exceptions.NoteAlreadyClosed() + case 410: raise exceptions.ElementDeleted() case _: assert False, f"Unexpected response status code {status_code}. Please report it on github." # pragma: no cover return self._xml_to_notes_list(generator)[0] @@ -205,6 +212,7 @@ def reopen(self, id: int, text: str | None = None) -> Note: Raises: exceptions.IdNotFoundError: Cannot find note with given id. exceptions.NoteAlreadyClosed: Note already closed. + exceptions.ElementDeleted: Note with given id has been hidden by a moderator. Returns: Note: Note object of closed note. @@ -236,7 +244,7 @@ def hide(self, id: int, text: str | None = None) -> None: Raises: exceptions.NotAModerator: User does not have a moderator role. exceptions.IdNotFoundError: Cannot find note with given id. - exceptions.ElementDeleted: Note already deleted. + exceptions.ElementDeleted: Note with given id has been hidden by a moderator. """ url = self.outer._url.note["hide"].format(id=id, text=text) param = f"?text={text}" if text else "" diff --git a/tests/api/test_api_notes.py b/tests/api/test_api_notes.py index fbdea52..0792e10 100644 --- a/tests/api/test_api_notes.py +++ b/tests/api/test_api_notes.py @@ -46,6 +46,27 @@ def test_get(self): assert note.comments[0].user, "User not exist" self.assertEqual(note.comments[0].user.id, 18179) + def get(): + return api.notes.get(37970) + + responses.add(**{ + "method": responses.GET, + "url": "https://test.pl/api/0.6/notes/37970", + "body": body, + "status": 404 + }) + + self.assertRaises(ApiExceptions.IdNotFoundError, get) + + responses.add(**{ + "method": responses.GET, + "url": "https://test.pl/api/0.6/notes/37970", + "body": body, + "status": 410 + }) + + self.assertRaises(ApiExceptions.ElementDeleted, get) + @responses.activate def test_get_bbox(self): body = """ @@ -204,4 +225,13 @@ def comment(): "body": body, "status": 409 }) - self.assertRaises(ApiExceptions.NoteAlreadyClosed, comment) \ No newline at end of file + + self.assertRaises(ApiExceptions.NoteAlreadyClosed, comment) + + responses.add(**{ + "method": responses.POST, + "url": "https://test.pl/api/0.6/notes/37970/comment?text=abc", + "body": body, + "status": 410 + }) + self.assertRaises(ApiExceptions.ElementDeleted, comment) \ No newline at end of file