From faddcafcf5cf3b5252c68661d54cc29cc6116931 Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Tue, 2 Apr 2024 17:20:40 +0200 Subject: [PATCH 1/3] Only include "discussion" key if include_discussion=True --- osmapi/OsmApi.py | 4 +-- osmapi/dom.py | 5 ++-- tests/changeset_test.py | 30 +++++++++++++++---- .../test_ChangesetGetWithoutDiscussion.xml | 7 +++++ 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 tests/fixtures/test_ChangesetGetWithoutDiscussion.xml diff --git a/osmapi/OsmApi.py b/osmapi/OsmApi.py index 809d5f5..2f48948 100644 --- a/osmapi/OsmApi.py +++ b/osmapi/OsmApi.py @@ -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={}): """ diff --git a/osmapi/dom.py b/osmapi/dom.py index 47816ff..5a50544 100644 --- a/osmapi/dom.py +++ b/osmapi/dom.py @@ -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 diff --git a/tests/changeset_test.py b/tests/changeset_test.py index 2d2469a..60f7262 100644 --- a/tests/changeset_test.py +++ b/tests/changeset_test.py @@ -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", @@ -516,7 +515,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", @@ -578,6 +576,31 @@ 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), + "comments_count": 3, + "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") @@ -588,7 +611,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", @@ -618,7 +640,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", @@ -659,7 +680,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", diff --git a/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml b/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml new file mode 100644 index 0000000..20b9f0e --- /dev/null +++ b/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml @@ -0,0 +1,7 @@ + + + + + + + From ba6af13083338596c69bce1fa7a0bc7e07ec058f Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Tue, 2 Apr 2024 17:23:02 +0200 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3d79b7..82b500c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 2bfc20653c30aad23d063a304053218cde7e98d8 Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Tue, 2 Apr 2024 17:29:27 +0200 Subject: [PATCH 3/3] Remove comment_count for test without discussion --- tests/changeset_test.py | 1 - tests/fixtures/test_ChangesetGetWithoutDiscussion.xml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/changeset_test.py b/tests/changeset_test.py index 60f7262..f7d098f 100644 --- a/tests/changeset_test.py +++ b/tests/changeset_test.py @@ -586,7 +586,6 @@ def test_ChangesetGetWithoutDiscussion(api, add_response): "id": 52924, "closed_at": datetime.datetime(2015, 1, 1, 14, 54, 2), "created_at": datetime.datetime(2015, 1, 1, 14, 54, 1), - "comments_count": 3, "max_lat": "58.3369242", "max_lon": "25.8829107", "min_lat": "58.336813", diff --git a/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml b/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml index 20b9f0e..1df9751 100644 --- a/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml +++ b/tests/fixtures/test_ChangesetGetWithoutDiscussion.xml @@ -1,6 +1,6 @@ - +