From 3f6aeb1918069bb1c8b6796f97632183c3a6049b Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 4 May 2025 04:27:10 +0300 Subject: [PATCH] Move api changeset upload bbox tests --- .../api/changesets/uploads_controller_test.rb | 110 +++++++++++++++ .../api/changesets_controller_test.rb | 129 ------------------ 2 files changed, 110 insertions(+), 129 deletions(-) diff --git a/test/controllers/api/changesets/uploads_controller_test.rb b/test/controllers/api/changesets/uploads_controller_test.rb index 807dec421..11aa03acd 100644 --- a/test/controllers/api/changesets/uploads_controller_test.rb +++ b/test/controllers/api/changesets/uploads_controller_test.rb @@ -1098,6 +1098,116 @@ module Api assert_not node.visible end + # ------------------------------------- + # Test bounding boxes. + # ------------------------------------- + + def test_upload_bbox_of_widely_spaced_nodes + user = create(:user) + + # create an old changeset to ensure we have the maximum rate limit + create(:changeset, :user => user, :created_at => Time.now.utc - 28.days) + + changeset = create(:changeset, :user => user) + + # upload some widely-spaced nodes, spiralling positive and negative + diff = <<~CHANGESET + + + + + + + + + + + + + + + + + + + + + + + CHANGESET + + auth_header = bearer_authorization_header user + + post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header + + assert_response :success + + # check that the changeset bbox is within bounds + changeset.reload + assert_operator changeset.min_lon, :>=, -180 * GeoRecord::SCALE, "Minimum longitude (#{changeset.min_lon / GeoRecord::SCALE}) should be >= -180 to be valid." + assert_operator changeset.max_lon, :<=, 180 * GeoRecord::SCALE, "Maximum longitude (#{changeset.max_lon / GeoRecord::SCALE}) should be <= 180 to be valid." + assert_operator changeset.min_lat, :>=, -90 * GeoRecord::SCALE, "Minimum latitude (#{changeset.min_lat / GeoRecord::SCALE}) should be >= -90 to be valid." + assert_operator changeset.max_lat, :<=, 90 * GeoRecord::SCALE, "Maximum latitude (#{changeset.max_lat / GeoRecord::SCALE}) should be <= 90 to be valid." + end + + def test_upload_bbox_of_moved_node + changeset = create(:changeset) + node = create(:node, :lat => 1.0, :lon => 2.0) + + diff = <<~CHANGESET + + + + + + CHANGESET + + auth_header = bearer_authorization_header changeset.user + + post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header + + assert_response :success + + # check the bbox + changeset.reload + assert_equal 1.0 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 1.0 degrees" + assert_equal 2.0 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 2.0 degrees" + assert_equal 1.1 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 1.1 degrees" + assert_equal 2.1 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 2.1 degrees" + end + + def test_upload_bbox_of_extended_way + way = create(:way) + initial_node = create(:node, :lat => 1.1, :lon => 2.1) + create(:way_node, :way => way, :node => initial_node) + added_node = create(:node, :lat => 1.3, :lon => 2.3) + changeset = create(:changeset) + + diff = <<~CHANGESET + + + + + + + + + CHANGESET + + auth_header = bearer_authorization_header changeset.user + + post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header + + assert_response :success + + # check the bbox + changeset.reload + assert_equal 1.1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 1.1 degrees" + assert_equal 2.1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 2.1 degrees" + assert_equal 1.3 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 1.3 degrees" + assert_equal 2.3 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 2.3 degrees" + end + # ------------------------------------- # Test upload rate/size limits. # ------------------------------------- diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index fe85ee277..c5fa1eccf 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -658,135 +658,6 @@ module Api end end - def test_upload_large_changeset - user = create(:user) - auth_header = bearer_authorization_header user - - # create an old changeset to ensure we have the maximum rate limit - create(:changeset, :user => user, :created_at => Time.now.utc - 28.days) - - # create a changeset - post api_changesets_path, :params => "", :headers => auth_header - assert_response :success, "Should be able to create a changeset: #{@response.body}" - changeset_id = @response.body.to_i - - # upload some widely-spaced nodes, spiralling positive and negative - diff = <<~CHANGESET - - - - - - - - - - - - - - - - - - - - - - - CHANGESET - - # upload it, which used to cause an error like "PGError: ERROR: - # integer out of range" (bug #2152). but shouldn't any more. - post api_changeset_upload_path(changeset_id), :params => diff, :headers => auth_header - assert_response :success, - "can't upload a spatially-large diff to changeset: #{@response.body}" - - # check that the changeset bbox is within bounds - cs = Changeset.find(changeset_id) - assert_operator cs.min_lon, :>=, -180 * GeoRecord::SCALE, "Minimum longitude (#{cs.min_lon / GeoRecord::SCALE}) should be >= -180 to be valid." - assert_operator cs.max_lon, :<=, 180 * GeoRecord::SCALE, "Maximum longitude (#{cs.max_lon / GeoRecord::SCALE}) should be <= 180 to be valid." - assert_operator cs.min_lat, :>=, -90 * GeoRecord::SCALE, "Minimum latitude (#{cs.min_lat / GeoRecord::SCALE}) should be >= -90 to be valid." - assert_operator cs.max_lat, :<=, 90 * GeoRecord::SCALE, "Maximum latitude (#{cs.max_lat / GeoRecord::SCALE}) should be <= 90 to be valid." - end - - ## - # test what happens if a diff is uploaded containing only a node - # move. - def test_upload_node_move - auth_header = bearer_authorization_header - - xml = "" \ - "" \ - "" - post api_changesets_path, :params => xml, :headers => auth_header - assert_response :success - changeset_id = @response.body.to_i - - old_node = create(:node, :lat => 1, :lon => 1) - - diff = XML::Document.new - diff.root = XML::Node.new "osmChange" - modify = XML::Node.new "modify" - xml_old_node = xml_node_for_node(old_node) - xml_old_node["lat"] = 2.0.to_s - xml_old_node["lon"] = 2.0.to_s - xml_old_node["changeset"] = changeset_id.to_s - modify << xml_old_node - diff.root << modify - - # upload it - post api_changeset_upload_path(changeset_id), :params => diff.to_s, :headers => auth_header - assert_response :success, - "diff should have uploaded OK" - - # check the bbox - changeset = Changeset.find(changeset_id) - assert_equal 1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 1 degree" - assert_equal 2 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 2 degrees" - assert_equal 1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 1 degree" - assert_equal 2 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 2 degrees" - end - - ## - # test what happens if a diff is uploaded adding a node to a way. - def test_upload_way_extend - auth_header = bearer_authorization_header - - xml = "" \ - "" \ - "" - post api_changesets_path, :params => xml, :headers => auth_header - assert_response :success - changeset_id = @response.body.to_i - - old_way = create(:way) - create(:way_node, :way => old_way, :node => create(:node, :lat => 0.1, :lon => 0.1)) - - diff = XML::Document.new - diff.root = XML::Node.new "osmChange" - modify = XML::Node.new "modify" - xml_old_way = xml_node_for_way(old_way) - nd_ref = XML::Node.new "nd" - nd_ref["ref"] = create(:node, :lat => 0.3, :lon => 0.3).id.to_s - xml_old_way << nd_ref - xml_old_way["changeset"] = changeset_id.to_s - modify << xml_old_way - diff.root << modify - - # upload it - post api_changeset_upload_path(changeset_id), :params => diff.to_s, :headers => auth_header - assert_response :success, - "diff should have uploaded OK" - - # check the bbox - changeset = Changeset.find(changeset_id) - assert_equal 0.1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 0.1 degree" - assert_equal 0.3 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 0.3 degrees" - assert_equal 0.1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 0.1 degree" - assert_equal 0.3 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 0.3 degrees" - end - ## # when we make some simple changes we get the same changes back from the # diff download. -- 2.39.5