def test_changeset_with_warning_tag_disconnected_way(): ch_dict = { 'created_by': 'iD', 'created_at': '2019-04-25T18:08:46Z', 'host': 'https://www.openstreetmap.org/edit', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'warnings:disconnected_way': '4', 'warnings:generic_name': '4', 'warnings:impossible_oneway': '4', 'warnings:incompatible_source': '4', 'warnings:outdated_tags': '9', '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() assert 'Disconnected way' in changeset.suspicion_reasons assert 'Generic name' in changeset.suspicion_reasons assert 'Impossible oneway' in changeset.suspicion_reasons assert 'suspect_word' in changeset.suspicion_reasons assert 'Outdated tags' in changeset.suspicion_reasons assert changeset.is_suspect
def test_changeset_with_warning_tag_almost_junction(): ch_dict = { 'created_by': 'iD', 'created_at': '2019-04-25T18:08:46Z', 'host': 'https://www.openstreetmap.org/edit', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'warnings:almost_junction': '1', 'warnings:missing_role': '1', 'warnings:missing_tag': '1', 'warnings:private_data': '1', 'warnings:tag_suggests_area': '1', 'warnings:unsquare_way': '1', '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() assert 'Almost junction' in changeset.suspicion_reasons assert 'Missing role' in changeset.suspicion_reasons assert 'Missing tag' in changeset.suspicion_reasons assert 'Private information' in changeset.suspicion_reasons assert 'Line tagged as area' in changeset.suspicion_reasons assert 'Unsquare corners' in changeset.suspicion_reasons assert changeset.is_suspect
def test_verify_id_editor_amazon_is_known_instance(): """Test if iD is not a powerfull_editor and if 'Unknown iD instance' is added to suspicion_reasons. """ ch_dict = { 'created_by': 'iD 2.17.3', 'host': 'https://ideditor.amazon.com/', 'created_at': '2020-09-25T18:08:46Z', 'comment': 'add pois', 'comments_count': '4', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False assert 'Unknown iD instance' not in ch.suspicion_reasons assert ch.is_suspect is False
def test_changeset_by_mapper_who_does_not_exist(): changeset_meta_data = '''<osm version="0.6" generator="CGImap 0.5.8 (15904 thorn-02.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/"><changeset id="44469157" created_at="2016-12-17T12:37:41Z" closed_at="2016-12-17T12:37:43Z" open="false" user="******" uid="1087876" min_lat="12.9316906" min_lon="77.5555034" max_lat="12.9316906" max_lon="77.5555034" comments_count="0"><tag k="comment" v="Added a hotel"/><tag k="locale" v="en-US"/><tag k="host" v="http://www.openstreetmap.org/id"/><tag k="imagery_used" v="Bing aerial imagery"/><tag k="created_by" v="iD 2.0.1"/></changeset></osm>''' changeset_data = '''<osmChange version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/"><create><node id="4558466455" changeset="44469157" timestamp="2016-12-17T12:37:43Z" version="1" visible="true" user="******" uid="1087876" lat="12.9316906" lon="77.5555034"><tag k="fast_food" v="regional"/><tag k="food" v="veg"/><tag k="name" v="Sankethi's"/><tag k="operator" v="Sankethi Ventures"/><tag k="smoking" v="no"/><tag k="tourism" v="hotel"/></node></create></osmChange>''' # Mock changeset meta data request. responses.add(responses.GET, 'http://www.openstreetmap.org/api/0.6/changeset/44469157', body=changeset_meta_data, status=200) # Mock changeset data request. responses.add( responses.GET, 'http://www.openstreetmap.org/api/0.6/changeset/44469157/download', body=changeset_data, status=200) # Mock download user details request. responses.add( responses.GET, 'https://osm-comments-api.mapbox.com/api/v1/users/name/bkowshik', json={"error": "not found"}, status=404 # To denote that the user does not exist. ) changeset = Analyse(44469157) changeset.full_analysis() assert 'New mapper' in changeset.suspicion_reasons assert changeset.is_suspect
def test_redacted_changeset(): """Redacted changesets have no metadata so those cases need to be threated to avoid a ZeroDivisionError in the Analyse.count() method. """ ch = Analyse(34495147) ch.full_analysis() assert ch.is_suspect is False
def test_analyse_verify_editor_Potlatch2(): """Test if Potlatch 2 is not a powerfull_editor.""" ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'comments_count': '0', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False
def test_changeset_with_warning_tag_close_nodes(): ch_dict = { 'created_by': 'iD', 'created_at': '2019-04-25T18:08:46Z', 'host': 'https://www.openstreetmap.org/edit', 'comment': 'add pois', 'comments_count': '13', 'id': '1', 'user': '******', 'uid': '123123', 'warnings:close_nodes:detached': '1', '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() assert 'Very close points' in changeset.suspicion_reasons assert changeset.is_suspect
def test_analyse_verify_editor_rapid_test(): """Test if RapiD test is not a powerfull_editor and a trusted instance.""" ch_dict = { 'created_by': 'RapiD 0.9.0', 'host': 'https://mapwith.ai/rapidtest', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False assert ch.suspicion_reasons == []
def test_analyse_verify_editor_josm(): """Test if JOSM is a powerfull_editor.""" ch_dict = { 'created_by': 'JOSM/1.5 (8339 en)', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'comments_count': '3', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor
def test_analyse_user_details(): ch = Analyse(31450443) ch.full_analysis() assert ch.user_details assert ch.user_details['contributor_uid'] == 2578646 assert ch.user_details['contributor_name'] == 'Tobsen Laufi' assert ch.user_details['contributor_blocks'] == 0 assert ch.user_details['contributor_since'] == datetime(2015, 01, 15) assert ch.user_details['contributor_traces'] == 0 assert ch.user_details['nodes_c'] == 0 assert ch.user_details['nodes_m'] == 0 assert ch.user_details['nodes_d'] == 975 assert ch.user_details['ways_c'] == 0 assert ch.user_details['ways_m'] == 0 assert ch.user_details['ways_d'] == 43 assert ch.user_details['relations_c'] == 0 assert ch.user_details['relations_m'] == 0 assert ch.user_details['relations_d'] == 1 assert ch.user_details['changesets_no'] == 1 assert ch.user_details['changesets_changes'] == 1019 assert ch.user_details['changesets_f_tstamp'] == datetime(2015, 05, 25, 16, 30, 43) assert ch.user_details['changesets_l_tstamp'] == datetime(2015, 05, 25, 16, 30, 43) assert ch.user_details['changesets_mapping_days'] == '2015=1'
def test_analyse_label_suspicious(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'comment': 'Put data from Google', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.label_suspicious('some reason') assert 'some reason' in ch.suspicion_reasons assert ch.is_suspect
def test_changeset_with_review_requested(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'review_requested': 'yes', '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() assert 'Review requested' in changeset.suspicion_reasons assert changeset.is_suspect
def test_changeset_with_warning_tag_invalid_format(): ch_dict = { 'created_by': 'iD', 'created_at': '2019-04-25T18:08:46Z', 'host': 'https://www.openstreetmap.org/edit', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'warnings:invalid_format': '0', '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() assert changeset.suspicion_reasons == [] assert not changeset.is_suspect
def create_changeset(changeset_id): """Analyse and create the changeset in the database.""" ch = Analyse(changeset_id) ch.full_analysis() # remove suspicion_reasons ch_dict = ch.get_dict() ch_dict.pop('suspicion_reasons') # remove bbox field if it is not a valid geometry if ch.bbox == 'GEOMETRYCOLLECTION EMPTY': ch_dict.pop('bbox') # save changeset changeset, created = Changeset.objects.update_or_create(id=ch_dict['id'], defaults=ch_dict) if ch.suspicion_reasons: for reason in ch.suspicion_reasons: reason, created = SuspicionReasons.objects.get_or_create( name=reason) reason.changesets.add(changeset) print('{c[id]} created'.format(c=ch_dict)) return changeset
def test_analyse_verify_editor_id_improveosm(): """Test if iD is not a powerfull_editor and if https://strava.github.io/iD/ is a trusted instance. """ ch_dict = { 'created_by': 'iD 1.7.3', 'host': 'https://strava.github.io/iD/', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False assert ch.suspicion_reasons == []
def test_analyse_verify_editor_id_unknown_instance(): """Test if iD is not a powerfull_editor and if 'Unknown iD instance' is added to suspicion_reasons. """ ch_dict = { 'created_by': 'iD 1.7.3', 'host': 'http://anotherhost.com', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False assert 'Unknown iD instance' in ch.suspicion_reasons assert ch.is_suspect
def test_analyse_count(): ch = Analyse(32663070) ch.full_analysis() assert ch.create == 8 assert ch.modify == 3 assert ch.delete == 2 assert ch.is_suspect is False assert len(ch.suspicion_reasons) == 0
def test_new_user_custom_create_value(): """Created: 1900. Modified: 16. Deleted: 320 / JOSM""" ch = Analyse(10013029, create_threshold=2000) ch.full_analysis() assert ch.is_suspect is True assert 'possible import' not in ch.suspicion_reasons assert 'New mapper' in ch.suspicion_reasons assert len(ch.suspicion_reasons) == 1
def cli(id): """Analyse an OpenStreetMap changeset.""" ch = Analyse(id) ch.full_analysis() click.echo( 'Created: %s. Modified: %s. Deleted: %s' % (ch.create, ch.modify, ch.delete) ) if ch.is_suspect: click.echo('The changeset %s is suspect!' % id) else: click.echo('The changeset %s is not suspect!' % id)
def test_analyse_verify_words(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'comment': 'Put data from Google', 'id': '1', 'user': '******', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_words() assert ch.is_suspect assert 'suspect_word' in ch.suspicion_reasons ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'source': 'Waze', 'id': '1', 'user': '******', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_words() assert ch.is_suspect assert 'suspect_word' in ch.suspicion_reasons ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'imagery_used': 'Custom (http://{switch:a,b,c}.tiles.googlemaps.com/{zoom}/{x}/{y}.png)', 'source': 'Bing', 'id': '1', 'user': '******', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_words() assert ch.is_suspect assert 'suspect_word' in ch.suspicion_reasons
def cli(id): """Analyse an OpenStreetMap changeset.""" ch = Analyse(id) ch.full_analysis() click.echo( 'Created: %s. Modified: %s. Deleted: %s' % (ch.create, ch.modify, ch.delete) ) if ch.is_suspect: click.echo('The changeset {} is suspect! Reasons: {}'.format( id, ', '.join(ch.suspicion_reasons) )) else: click.echo('The changeset %s is not suspect!' % id)
def test_verify_hotosm_id_is_known_instance(): """Test if iD is not a powerfull_editor and if 'Unknown iD instance' is added to suspicion_reasons. """ ch1 = { 'created_by': 'iD 1.7.3', 'host': 'https://tasks.teachosm.org/projects/23/map/', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'comments_count': '0', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch2 = { 'created_by': 'iD 1.7.3', 'host': 'https://tasks.hotosm.org/projects/23/map/', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'comments_count': '1', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch1) ch.verify_editor() assert ch.powerfull_editor is False assert 'Unknown iD instance' not in ch.suspicion_reasons assert ch.is_suspect is False ch_2 = Analyse(ch2) ch_2.verify_editor() assert ch_2.powerfull_editor is False assert 'Unknown iD instance' not in ch_2.suspicion_reasons assert ch_2.is_suspect is False
def test_analyse_init(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'comment': 'Put data from Google', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) assert ch.id == 1 assert ch.editor == 'Potlatch 2' assert ch.comment == 'Put data from Google' assert ch.user == 'JustTest' assert ch.uid == '123123' assert ch.date == datetime(2015, 4, 25, 18, 8, 46)
def test_analyse_verify_editor_Potlatch2(): """Test if Potlatch 2 is not a powerfull_editor.""" ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False
def test_analyse_verify_editor_merkaartor(): """Test if Merkaartor is a powerfull_editor.""" ch_dict = { 'created_by': 'Merkaartor 0.18 (de)', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor
def test_analyse_verify_editor_josm(): """Test if JOSM is a powerfull_editor.""" ch_dict = { 'created_by': 'JOSM/1.5 (8339 en)', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor
def test_custom_percentage(): """C/M/D = 481 620 80 / JOSM""" ch = Analyse(45082154) ch.full_analysis() assert ch.is_suspect is False assert len(ch.suspicion_reasons) == 0 ch = Analyse(45082154, percentage=0.5) ch.full_analysis() assert ch.is_suspect assert 'mass modification' in ch.suspicion_reasons
def test_custom_top_threshold(): """C/M/D = 1072 124 282 / made with iD""" ch = Analyse(45862717) ch.full_analysis() assert ch.is_suspect assert 'possible import' in ch.suspicion_reasons ch = Analyse(45862717, top_threshold=1100) ch.full_analysis() assert ch.is_suspect is False assert len(ch.suspicion_reasons) == 0
def test_changeset_with_review_requested(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'review_requested': 'yes', '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() assert 'Review requested' in changeset.suspicion_reasons assert changeset.is_suspect
def test_analyse_label_suspicious(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'comment': 'Put data from Google', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.label_suspicious('some reason') assert 'some reason' in ch.suspicion_reasons assert ch.is_suspect
def test_save_user_details(self): analyze = Analyse(31450443) # A random changeset analyze.full_analysis() # Removing these values from the object analyze_dict = analyze.__dict__.copy() for key in analyze.__dict__: if analyze.__dict__.get(key) == '': analyze_dict.pop(key) analyze_dict.pop('suspicion_reasons') analyze_dict.pop('user_details') changeset = Changeset.objects.create(**analyze_dict) changeset.save() self.assertIsNone(changeset.user_detail) changeset.save_user_details(analyze) self.assertIsNotNone(changeset.user_detail) self.assertEqual(changeset.user_detail.contributor_name, 'Tobsen Laufi') self.assertEqual(changeset.user_detail.contributor_blocks, 0) self.assertEqual(changeset.user_detail.contributor_since, datetime(2015, 01, 15)) self.assertEqual(changeset.user_detail.contributor_traces, 0) self.assertEqual(changeset.user_detail.nodes_c, 0) self.assertEqual(changeset.user_detail.nodes_m, 0) self.assertEqual(changeset.user_detail.nodes_d, 975) self.assertEqual(changeset.user_detail.ways_c, 0) self.assertEqual(changeset.user_detail.ways_m, 0) self.assertEqual(changeset.user_detail.ways_d, 43) self.assertEqual(changeset.user_detail.relations_c, 0) self.assertEqual(changeset.user_detail.relations_m, 0) self.assertEqual(changeset.user_detail.relations_d, 1) self.assertEqual(changeset.user_detail.changesets_no, 1) self.assertEqual(changeset.user_detail.changesets_changes, 1019) self.assertEqual(changeset.user_detail.changesets_f_tstamp, datetime(2015, 05, 25, 16, 30, 43)) self.assertEqual(changeset.user_detail.changesets_l_tstamp, datetime(2015, 05, 25, 16, 30, 43)) self.assertEqual(changeset.user_detail.changesets_mapping_days, '2015=1')
def test_analyse_verify_editor_id_strava(): """Test if iD is not a powerfull_editor and if https://strava.github.io/iD/ is a trusted instance. """ ch_dict = { 'created_by': 'iD 1.7.3', 'host': 'https://strava.github.io/iD/', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False assert ch.suspicion_reasons == []
def create_changeset(changeset_id): """Analyse and create the changeset in the database.""" ch = Analyse(changeset_id) ch.full_analysis() # remove suspicion_reasons and empty values from dict ch_dict = ch.__dict__.copy() for key in ch.__dict__: if ch.__dict__.get(key) == "": ch_dict.pop(key) ch_dict.pop("suspicion_reasons") # save changeset changeset = Changeset(**ch_dict) changeset.save() if ch.suspicion_reasons: for reason in ch.suspicion_reasons: reason, created = SuspicionReasons.objects.get_or_create(name=reason) reason.changesets.add(changeset) print("{c[id]} created".format(c=ch_dict))
def create_changeset(changeset_id): """Analyse and create the changeset in the database.""" ch = Analyse(changeset_id) ch.full_analysis() # remove suspicion_reasons and empty values from dict ch_dict = ch.__dict__.copy() for key in ch.__dict__: if ch.__dict__.get(key) == '': ch_dict.pop(key) ch_dict['score'] = ch_dict['changeset_score'] ch_dict.pop('suspicion_reasons') # ch_dict.pop('user_details') ch_dict.pop('user_score') ch_dict.pop('changeset_score') ch_dict.pop('user_score_details') ch_dict.pop('changeset_score_details') # save changeset changeset, created = Changeset.objects.update_or_create(id=ch_dict['id'], defaults=ch_dict) if ch.suspicion_reasons: for reason in ch.suspicion_reasons: reason, created = SuspicionReasons.objects.get_or_create(name=reason) reason.changesets.add(changeset) SuspicionScore.objects.filter(changeset=changeset).delete() for detail in ch.changeset_score_details: s = SuspicionScore(changeset=changeset) s.score = detail['score'] s.reason = detail['reason'] s.save() # if ch.user_details: # changeset.save_user_details(ch) print('{c[id]} created'.format(c=ch_dict))
def create_changeset(changeset_id): """Analyse and create the changeset in the database.""" ch = Analyse(changeset_id) ch.full_analysis() # remove suspicion_reasons and empty values from dict ch_dict = ch.__dict__.copy() for key in ch.__dict__: if ch.__dict__.get(key) == '': ch_dict.pop(key) ch_dict.pop('suspicion_reasons') # save changeset changeset = Changeset(**ch_dict) changeset.save() if ch.suspicion_reasons: for reason in ch.suspicion_reasons: reason, created = SuspicionReasons.objects.get_or_create( name=reason) reason.changesets.add(changeset) print('{c[id]} created'.format(c=ch_dict))
def test_analyse_verify_editor_id_unknown_instance(): """Test if iD is not a powerfull_editor and if 'Unknown iD instance' is added to suspicion_reasons. """ ch_dict = { 'created_by': 'iD 1.7.3', 'host': 'http://anotherhost.com', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False assert 'Unknown iD instance' in ch.suspicion_reasons assert ch.is_suspect
def test_changeset_by_old_mapper_with_special_character_username(): changeset = Analyse(46141825) changeset.full_analysis() assert 'New mapper' not in changeset.suspicion_reasons assert not changeset.is_suspect
def test_changeset_by_old_mapper_with_unicode_username(): changeset = Analyse(46790192) changeset.full_analysis() assert 'New mapper' not in changeset.suspicion_reasons assert not changeset.is_suspect
def test_changeset_with_6_mapping_days(): changeset = Analyse(13523366) changeset.full_analysis() assert 'New mapper' not in changeset.suspicion_reasons assert not changeset.is_suspect
def test_analyse_mass_deletion(): ch = Analyse(31450443) ch.full_analysis() assert ch.is_suspect assert 'mass deletion' in ch.suspicion_reasons
def test_changeset_by_new_mapper(): changeset = Analyse(46756461) changeset.full_analysis() assert 'New mapper' in changeset.suspicion_reasons assert changeset.is_suspect
def test_analyse_verify_editor(): ch_dict = { 'created_by': 'JOSM/1.5 (8339 en)', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor ch_dict = { 'created_by': 'Merkaartor 0.18 (de)', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor ch_dict = { 'created_by': 'Level0 v1.1', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor ch_dict = { 'created_by': 'QGIS plugin', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor ch_dict = { 'created_by': 'iD 1.7.3', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'comment': 'add pois', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([ (-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354) ]) } ch = Analyse(ch_dict) ch.verify_editor() assert ch.powerfull_editor is False
def test_analyse_mass_modification(): ch = Analyse(19863853) ch.full_analysis() assert ch.is_suspect assert 'mass modification' in ch.suspicion_reasons
def test_changeset_without_tags(): ch = Analyse(46755934) ch.full_analysis() assert ch.powerfull_editor assert ch.is_suspect assert 'Software editor was not declared' in ch.suspicion_reasons
def test_get_dict(): """Test if get_dict function return only the fields that osmcha-django needs to save in the database. """ # An iD changeset ch = Analyse(46286980) ch.full_analysis() assert 'id' in ch.get_dict().keys() assert 'user' in ch.get_dict().keys() assert 'uid' in ch.get_dict().keys() assert 'editor' in ch.get_dict().keys() assert 'bbox' in ch.get_dict().keys() assert 'date' in ch.get_dict().keys() assert 'comment' in ch.get_dict().keys() assert 'source' in ch.get_dict().keys() assert 'imagery_used' in ch.get_dict().keys() assert 'is_suspect' in ch.get_dict().keys() assert 'powerfull_editor' in ch.get_dict().keys() assert 'suspicion_reasons' in ch.get_dict().keys() assert 'create' in ch.get_dict().keys() assert 'modify' in ch.get_dict().keys() assert 'delete' in ch.get_dict().keys() assert len(ch.get_dict().keys()) == 15 # A JOSM changeset ch = Analyse(46315321) ch.full_analysis() assert 'id' in ch.get_dict().keys() assert 'user' in ch.get_dict().keys() assert 'uid' in ch.get_dict().keys() assert 'editor' in ch.get_dict().keys() assert 'bbox' in ch.get_dict().keys() assert 'date' in ch.get_dict().keys() assert 'comment' in ch.get_dict().keys() assert 'source' in ch.get_dict().keys() assert 'imagery_used' in ch.get_dict().keys() assert 'is_suspect' in ch.get_dict().keys() assert 'powerfull_editor' in ch.get_dict().keys() assert 'suspicion_reasons' in ch.get_dict().keys() assert 'create' in ch.get_dict().keys() assert 'modify' in ch.get_dict().keys() assert 'delete' in ch.get_dict().keys() assert len(ch.get_dict().keys()) == 15
def test_changeset_by_new_mapper(): changeset = Analyse(36700893) changeset.full_analysis() print(changeset.suspicion_reasons) assert 'New mapper' in changeset.suspicion_reasons assert changeset.is_suspect
def test_changeset_without_coords(): """Changeset deleted a relation, so it has not a bbox.""" ch = Analyse(33624206) assert ch.bbox == 'GEOMETRYCOLLECTION EMPTY'
def test_analyse_import(): ch = Analyse(10013029) ch.full_analysis() assert ch.is_suspect assert 'possible import' in ch.suspicion_reasons
def test_changeset_by_user_with_more_than_one_block(): changeset = Analyse(34879408) changeset.full_analysis() assert 'User has multiple blocks' in changeset.suspicion_reasons assert changeset.is_suspect
def test_analyse_verify_words(): ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'comment': 'Put data from Google', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_words() assert ch.is_suspect assert 'suspect_word' in ch.suspicion_reasons ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'source': 'Waze', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_words() assert ch.is_suspect assert 'suspect_word' in ch.suspicion_reasons ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'imagery_used': 'Custom (http://{switch:a,b,c}.tiles.googlemaps.com/{zoom}/{x}/{y}.png)', 'source': 'Bing', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_words() assert ch.is_suspect assert 'suspect_word' in ch.suspicion_reasons ch_dict = { 'created_by': 'Potlatch 2', 'created_at': '2015-04-25T18:08:46Z', 'build': '2.3-650-gad99430', 'version': '2.3', 'comment': 'Somewhere in Brazil', 'id': '1', 'user': '******', 'uid': '123123', 'bbox': Polygon([(-71.0646843, 44.2371354), (-71.0048652, 44.2371354), (-71.0048652, 44.2430624), (-71.0646843, 44.2430624), (-71.0646843, 44.2371354)]) } ch = Analyse(ch_dict) ch.verify_words() assert not ch.is_suspect