Merge remote-tracking branch 'openstreetmap/pull/1367'

This commit is contained in:
Tom Hughes 2016-12-18 16:29:33 +00:00
commit 970e1a99d7
36 changed files with 366 additions and 735 deletions

View file

@ -531,7 +531,10 @@ class AmfControllerTest < ActionController::TestCase
def test_findrelations_by_tags
visible_relation = current_relations(:visible_relation)
create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
used_relation = current_relations(:used_relation)
create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes")
create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation")
amf_content "findrelations", "/1", ["yes"]
post :amf_read

View file

@ -53,6 +53,7 @@ class ApiControllerTest < ActionController::TestCase
def test_map
node = current_nodes(:used_node_1)
tag = create(:node_tag, :node => node)
# Need to split the min/max lat/lon out into their own variables here
# so that we can test they are returned later.
minlon = node.lon - 0.1
@ -70,7 +71,7 @@ class ApiControllerTest < ActionController::TestCase
assert_select "bounds[minlon='#{minlon}'][minlat='#{minlat}'][maxlon='#{maxlon}'][maxlat='#{maxlat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
assert_select "tag[k='test'][v='yes']"
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
assert_select "way", :count => 2
assert_select "way[id='1']", :count => 1
@ -84,6 +85,7 @@ class ApiControllerTest < ActionController::TestCase
# the same as the node we are looking at
def test_map_inclusive
node = current_nodes(:used_node_1)
tag = create(:node_tag, :node => node)
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
get :map, :bbox => bbox
assert_response :success, "The map call should have succeeded"
@ -91,7 +93,7 @@ class ApiControllerTest < ActionController::TestCase
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
assert_select "tag[k='test'][v='yes']"
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
assert_select "way", :count => 2
assert_select "way[id='1']", :count => 1

View file

@ -1388,7 +1388,10 @@ EOF
end
def test_changeset_download
tag = create(:old_node_tag, :old_node => nodes(:used_node_2))
get :download, :id => changesets(:normal_user_first_change).id
assert_response :success
assert_template nil
# print @response.body
@ -1396,7 +1399,7 @@ EOF
assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do
assert_select "create", :count => 5
assert_select "create>node[id='#{nodes(:used_node_2).node_id}'][visible='#{nodes(:used_node_2).visible?}'][version='#{nodes(:used_node_2).version}']" do
assert_select "tag[k='#{node_tags(:t3).k}'][v='#{node_tags(:t3).v}']"
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
assert_select "create>node[id='#{nodes(:visible_node).node_id}']"
end

View file

@ -437,13 +437,14 @@ class NodeControllerTest < ActionController::TestCase
##
# test adding tags to a node
def test_duplicate_tags
existing = create(:node_tag, :node => current_nodes(:public_visible_node))
# setup auth
basic_authorization(users(:public_user).email, "test")
# add an identical tag to the node
tag_xml = XML::Node.new("tag")
tag_xml["k"] = current_node_tags(:public_v_t1).k
tag_xml["v"] = current_node_tags(:public_v_t1).v
tag_xml["k"] = existing.k
tag_xml["v"] = existing.v
# add the tag into the existing xml
node_xml = current_nodes(:public_visible_node).to_xml
@ -454,7 +455,7 @@ class NodeControllerTest < ActionController::TestCase
put :update, :id => current_nodes(:public_visible_node).id
assert_response :bad_request,
"adding duplicate tags to a node should fail with 'bad request'"
assert_equal "Element node/#{current_nodes(:public_visible_node).id} has duplicate tags with key #{current_node_tags(:t1).k}", @response.body
assert_equal "Element node/#{current_nodes(:public_visible_node).id} has duplicate tags with key #{existing.k}", @response.body
end
# test whether string injection is possible

View file

@ -86,10 +86,14 @@ class OldNodeControllerTest < ActionController::TestCase
basic_authorization(users(:public_user).email, "test")
# setup a simple XML node
create_list(:node_tag, 2, :node => current_nodes(:node_with_versions))
xml_doc = current_nodes(:node_with_versions).to_xml
xml_node = xml_doc.find("//osm/node").first
nodeid = current_nodes(:node_with_versions).id
# Ensure that the current tags are propagated to the history too
propagate_tags(current_nodes(:node_with_versions), nodes(:node_with_versions_v4))
# keep a hash of the versions => string, as we'll need something
# to test against later
versions = {}
@ -161,6 +165,17 @@ class OldNodeControllerTest < ActionController::TestCase
# Test that getting the current version is identical to picking
# that version with the version URI call.
def test_current_version
create(:node_tag, :node => current_nodes(:visible_node))
create(:node_tag, :node => current_nodes(:used_node_1))
create(:node_tag, :node => current_nodes(:used_node_2))
create(:node_tag, :node => current_nodes(:node_used_by_relationship))
create(:node_tag, :node => current_nodes(:node_with_versions))
propagate_tags(current_nodes(:visible_node), nodes(:visible_node))
propagate_tags(current_nodes(:used_node_1), nodes(:used_node_1))
propagate_tags(current_nodes(:used_node_2), nodes(:used_node_2))
propagate_tags(current_nodes(:node_used_by_relationship), nodes(:node_used_by_relationship))
propagate_tags(current_nodes(:node_with_versions), nodes(:node_with_versions_v4))
check_current_version(current_nodes(:visible_node))
check_current_version(current_nodes(:used_node_1))
check_current_version(current_nodes(:used_node_2))
@ -377,4 +392,10 @@ class OldNodeControllerTest < ActionController::TestCase
def precision(f)
(f * GeoRecord::SCALE).round.to_f / GeoRecord::SCALE
end
def propagate_tags(node, old_node)
node.tags.each do |k, v|
create(:old_node_tag, :old_node => old_node, :k => k, :v => v)
end
end
end

View file

@ -46,6 +46,13 @@ class OldWayControllerTest < ActionController::TestCase
##
# check that we can retrieve versions of a way
def test_version
create(:way_tag, :way => current_ways(:visible_way))
create(:way_tag, :way => current_ways(:used_way))
create(:way_tag, :way => current_ways(:way_with_versions))
propagate_tags(current_ways(:visible_way), ways(:visible_way))
propagate_tags(current_ways(:used_way), ways(:used_way))
propagate_tags(current_ways(:way_with_versions), ways(:way_with_versions_v4))
check_current_version(current_ways(:visible_way).id)
check_current_version(current_ways(:used_way).id)
check_current_version(current_ways(:way_with_versions).id)
@ -276,4 +283,10 @@ class OldWayControllerTest < ActionController::TestCase
# now redact it
post :redact, :id => way.way_id, :version => way.version, :redaction => redaction.id
end
def propagate_tags(way, old_way)
way.tags.each do |k, v|
create(:old_way_tag, :old_way => old_way, :k => k, :v => v)
end
end
end

View file

@ -337,6 +337,7 @@ class RelationControllerTest < ActionController::TestCase
def test_update_relation_tags
basic_authorization "test@example.com", "test"
rel_id = current_relations(:multi_tag_relation).id
create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
cs_id = changesets(:public_user_first_change).id
with_relation(rel_id) do |rel|
@ -366,6 +367,7 @@ class RelationControllerTest < ActionController::TestCase
def test_update_relation_tags_via_upload
basic_authorization users(:public_user).email, "test"
rel_id = current_relations(:multi_tag_relation).id
create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
cs_id = changesets(:public_user_first_change).id
with_relation(rel_id) do |rel|

View file

@ -43,6 +43,11 @@ class SearchControllerTest < ActionController::TestCase
##
# test searching ways
def test_search_ways
[:visible_way, :invisible_way, :used_way].each do |way|
create(:way_tag, :way => current_ways(way), :k => "test", :v => "yes")
end
create(:way_tag, :way => current_ways(:used_way), :k => "name", :v => "Test Way")
get :search_ways, :type => "test"
assert_response :service_unavailable
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
@ -59,6 +64,11 @@ class SearchControllerTest < ActionController::TestCase
##
# test searching relations
def test_search_relations
[:visible_relation, :invisible_relation, :used_relation].each do |relation|
create(:relation_tag, :relation => current_relations(relation), :k => "test", :v => "yes")
end
create(:relation_tag, :relation => current_relations(:used_relation), :k => "name", :v => "Test Relation")
get :search_relations, :type => "test"
assert_response :service_unavailable
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]

View file

@ -538,10 +538,12 @@ class WayControllerTest < ActionController::TestCase
# setup auth
basic_authorization(users(:normal_user).email, "test")
existing = create(:way_tag, :way => current_ways(:visible_way))
# add an identical tag to the way
tag_xml = XML::Node.new("tag")
tag_xml["k"] = current_way_tags(:t1).k
tag_xml["v"] = current_way_tags(:t1).v
tag_xml["k"] = existing.k
tag_xml["v"] = existing.v
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
@ -559,8 +561,8 @@ class WayControllerTest < ActionController::TestCase
# add an identical tag to the way
tag_xml = XML::Node.new("tag")
tag_xml["k"] = current_way_tags(:t1).k
tag_xml["v"] = current_way_tags(:t1).v
tag_xml["k"] = existing.k
tag_xml["v"] = existing.v
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
@ -571,7 +573,7 @@ class WayControllerTest < ActionController::TestCase
put :update, :id => current_ways(:visible_way).id
assert_response :bad_request,
"adding a duplicate tag to a way should fail with 'bad request'"
assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{current_way_tags(:t1).k}", @response.body
assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{existing.k}", @response.body
end
##