From 055b62e835ae02e52ae34da3dbfbf0e692e23e7e Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Fri, 23 Feb 2024 14:13:00 -0500 Subject: [PATCH] Fix error when a changeset has an empty host value --- osmcha/changeset.py | 5 ++++- tests/test_mod.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/osmcha/changeset.py b/osmcha/changeset.py index 7f2dde0..8c84356 100644 --- a/osmcha/changeset.py +++ b/osmcha/changeset.py @@ -420,5 +420,8 @@ def get_dict(self): ch_dict.pop(key) for field in FIELDS_TO_REMOVE: - ch_dict.pop(field) + try: + ch_dict.pop(field) + except KeyError: + pass return ch_dict diff --git a/tests/test_mod.py b/tests/test_mod.py index d9d114a..52766a3 100644 --- a/tests/test_mod.py +++ b/tests/test_mod.py @@ -377,7 +377,6 @@ def test_analyse_verify_editor_id_osm(): assert ch.suspicion_reasons == [] - def test_verify_editor_id_is_known_instance(): """Test if iD is not a powerfull_editor and if 'Unknown iD instance' is added to suspicion_reasons. @@ -904,6 +903,27 @@ def test_changeset_with_warning_tag_invalid_format(): assert not changeset.is_suspect +def get_dict_doesnt_fail_with_empty_host_value(): + ch_dict = { + 'created_by': 'iD', + 'created_at': '2019-04-25T18:08:46Z', + 'host': '', + 'comment': 'add pois', + 'id': '1', + 'user': 'JustTest', + 'uid': '123123', + 'bbox': Polygon([ + (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), + (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), + (-71.0646843, 44.2371354) + ]) + } + changeset = Analyse(ch_dict) + changeset.full_analysis() + processed_dict = changeset.get_dict() + assert 'host' not in processed_dict.keys() + + def test_enabled_warnings(): warnings = Warnings() assert warnings.get_non_exact_match_warnings() == [