Skip to content

Commit

Permalink
Merge pull request #164 from metaodi/omit-discussion-key
Browse files Browse the repository at this point in the history
Omit discussion key
  • Loading branch information
metaodi authored Jun 17, 2024
2 parents 1c873a5 + 2bfc206 commit fcbb1fb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project follows [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Only include `discussion` key in result of `ChangesetGet` if `include_discussion=True` (see issue #163, thanks [Mateusz Konieczny](https://github.com/matkoniecz))

## [4.1.0] - 2024-03-19
### Added
Expand Down
4 changes: 2 additions & 2 deletions osmapi/OsmApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,10 +1218,10 @@ def ChangesetGet(self, ChangesetId, include_discussion=False):
"""
path = f"/api/0.6/changeset/{ChangesetId}"
if include_discussion:
path += "?include_discussion=true"
path = f"{path}?include_discussion=true"
data = self._session._get(path)
changeset = dom.OsmResponseToDom(data, tag="changeset", single=True)
return dom.DomParseChangeset(changeset)
return dom.DomParseChangeset(changeset, include_discussion=include_discussion)

def ChangesetUpdate(self, ChangesetTags={}):
"""
Expand Down
5 changes: 3 additions & 2 deletions osmapi/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ def DomParseRelation(DomElement):
return result


def DomParseChangeset(DomElement):
def DomParseChangeset(DomElement, include_discussion=False):
"""
Returns ChangesetData for the changeset.
"""
result = _DomGetAttributes(DomElement)
result["tag"] = _DomGetTag(DomElement)
result["discussion"] = _DomGetDiscussion(DomElement)
if include_discussion:
result["discussion"] = _DomGetDiscussion(DomElement)

return result

Expand Down
29 changes: 24 additions & 5 deletions tests/changeset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_ChangesetGet(api, add_response):
"id": 123,
"closed_at": datetime.datetime(2009, 9, 7, 22, 57, 37),
"created_at": datetime.datetime(2009, 9, 7, 21, 57, 36),
"discussion": [],
"max_lat": "52.4710193",
"max_lon": "-1.4831815",
"min_lat": "45.9667901",
Expand Down Expand Up @@ -536,7 +535,6 @@ def test_ChangesetsGet(api, add_response):
"closed_at": datetime.datetime(2014, 4, 29, 20, 25, 1),
"created_at": datetime.datetime(2014, 4, 29, 20, 25, 1),
"id": 41417,
"discussion": [],
"max_lat": "58.8997467",
"max_lon": "22.7364427",
"min_lat": "58.8501594",
Expand Down Expand Up @@ -598,6 +596,30 @@ def test_ChangesetGetWithComment(api, add_response):
}


def test_ChangesetGetWithoutDiscussion(api, add_response):
resp = add_response(GET, "/changeset/52924")

result = api.ChangesetGet(52924, include_discussion=False)

assert resp.calls[0].request.params == {}
assert result == {
"id": 52924,
"closed_at": datetime.datetime(2015, 1, 1, 14, 54, 2),
"created_at": datetime.datetime(2015, 1, 1, 14, 54, 1),
"max_lat": "58.3369242",
"max_lon": "25.8829107",
"min_lat": "58.336813",
"min_lon": "25.8823273",
"open": False,
"user": "metaodi",
"uid": 1841,
"tag": {
"comment": "My test",
"created_by": "osmapi/0.4.1",
},
}


def test_ChangesetComment(auth_api, add_response):
resp = add_response(POST, "/changeset/123/comment")

Expand All @@ -608,7 +630,6 @@ def test_ChangesetComment(auth_api, add_response):
"id": 123,
"closed_at": datetime.datetime(2009, 9, 7, 22, 57, 37),
"created_at": datetime.datetime(2009, 9, 7, 21, 57, 36),
"discussion": [],
"max_lat": "52.4710193",
"max_lon": "-1.4831815",
"min_lat": "45.9667901",
Expand Down Expand Up @@ -638,7 +659,6 @@ def test_ChangesetSubscribe(auth_api, add_response):
"id": 123,
"closed_at": datetime.datetime(2009, 9, 7, 22, 57, 37),
"created_at": datetime.datetime(2009, 9, 7, 21, 57, 36),
"discussion": [],
"max_lat": "52.4710193",
"max_lon": "-1.4831815",
"min_lat": "45.9667901",
Expand Down Expand Up @@ -679,7 +699,6 @@ def test_ChangesetUnsubscribe(auth_api, add_response):
"id": 123,
"closed_at": datetime.datetime(2009, 9, 7, 22, 57, 37),
"created_at": datetime.datetime(2009, 9, 7, 21, 57, 36),
"discussion": [],
"max_lat": "52.4710193",
"max_lon": "-1.4831815",
"min_lat": "45.9667901",
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/test_ChangesetGetWithoutDiscussion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/">
<changeset id="52924" user="metaodi" uid="1841" created_at="2015-01-01T14:54:01Z" closed_at="2015-01-01T14:54:02Z" open="false" min_lat="58.336813" min_lon="25.8823273" max_lat="58.3369242" max_lon="25.8829107">
<tag k="created_by" v="osmapi/0.4.1"/>
<tag k="comment" v="My test"/>
</changeset>
</osm>

0 comments on commit fcbb1fb

Please sign in to comment.