Skip to content

Commit

Permalink
Merge pull request #25 from docentYT/development
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
docentYT authored Feb 23, 2024
2 parents 223cfe2 + 5f82b12 commit b617b30
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/osm_easy_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "2.1.1"
VERSION = "2.2.0"

from .data_classes import *
from .diff import Diff, Frequency
Expand Down
1 change: 1 addition & 0 deletions src/osm_easy_api/api/endpoints/changeset_discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 9 additions & 1 deletion src/osm_easy_api/api/endpoints/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]

Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand Down Expand Up @@ -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 ""
Expand Down
32 changes: 31 additions & 1 deletion tests/api/test_api_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """<osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
Expand Down Expand Up @@ -204,4 +225,13 @@ def comment():
"body": body,
"status": 409
})
self.assertRaises(ApiExceptions.NoteAlreadyClosed, comment)

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)

0 comments on commit b617b30

Please sign in to comment.