]> git.openstreetmap.org Git - rails.git/commitdiff
fixing some of the relation tests. Some adjustments to the fixtures.
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Wed, 22 Apr 2009 00:42:23 +0000 (00:42 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Wed, 22 Apr 2009 00:42:23 +0000 (00:42 +0000)
test/fixtures/current_relation_members.yml
test/fixtures/current_relations.yml
test/fixtures/relation_members.yml
test/fixtures/relations.yml
test/functional/relation_controller_test.rb
test/unit/relation_member_test.rb
test/unit/relation_test.rb

index f055371151e96483e074c98da66ab51094334742..f6418983ac51cc9acba22f538b14f6422418c0ef 100644 (file)
@@ -27,3 +27,9 @@ t5:
   member_role: "some"
   member_type: "Node"
   member_id: 5
+  
+public_used:
+  id: 4
+  member_role: "used by other relation"
+  member_type: "Relation"
+  member_id: 5
index 7df9c6bd76a57b10c77f57a6c6d6808f71d5ce35..da034395699c51b5f0b8be71b6c739443c28d0a3 100644 (file)
@@ -7,7 +7,7 @@ visible_relation:
 
 invisible_relation:
   id: 2
-  changeset_id: 1
+  changeset_id: 3
   timestamp: 2007-01-01 00:00:00
   visible: false
   version: 1
@@ -25,3 +25,10 @@ multi_tag_relation:
   timestamp: 2009-04-21 09:50:57
   visible: true
   version: 1
+  
+public_used_relation:
+  id: 5
+  changeset_id: 2
+  timestamp: 2009-04-22 00:30:33
+  visible: true
+  version: 1
index 5a19bf3f26615034389af5b14223abc928153699..b37e5beae7cb46bd8890de546cc59ee56522c7b4 100644 (file)
@@ -22,3 +22,17 @@ t4:
   member_type: "Node"
   member_id: 5
   version: 1
+
+t5:
+  id: 2
+  member_role: "some"
+  member_type: "Node"
+  member_id: 5
+  version: 1
+  
+public_used:
+  id: 4
+  member_role: "used by other relation"
+  member_type: "Relation"
+  member_id: 5
+  version: 1
index 7df9c6bd76a57b10c77f57a6c6d6808f71d5ce35..5583527827f634b9b2932affffa27bd240784538 100644 (file)
@@ -7,7 +7,7 @@ visible_relation:
 
 invisible_relation:
   id: 2
-  changeset_id: 1
+  changeset_id: 3
   timestamp: 2007-01-01 00:00:00
   visible: false
   version: 1
@@ -25,3 +25,10 @@ multi_tag_relation:
   timestamp: 2009-04-21 09:50:57
   visible: true
   version: 1
+  
+public_used_relation:
+  id: 5
+  changeset_id: 2
+  timestamp: 2009-04-22 00:30:03
+  visible: true
+  version: 1
index 9ecac826cb441af6398be1f8fb8840480c1cdde2..4baf810fe3c7a62291372fb806d54d8e9bf9785f 100644 (file)
@@ -319,9 +319,59 @@ class RelationControllerTest < ActionController::TestCase
     # first try to delete relation without auth
     delete :delete, :id => current_relations(:visible_relation).id
     assert_response :unauthorized
+    
+    ## First try with the private user, to make sure that you get a forbidden
+    basic_authorization(users(:normal_user).email, "test")
+    
+    # this shouldn't work, as we should need the payload...
+    delete :delete, :id => current_relations(:visible_relation).id
+    assert_response :forbidden
+
+    # try to delete without specifying a changeset
+    content "<osm><relation id='#{current_relations(:visible_relation).id}'/></osm>"
+    delete :delete, :id => current_relations(:visible_relation).id
+    assert_response :forbidden
+
+    # try to delete with an invalid (closed) changeset
+    content update_changeset(current_relations(:visible_relation).to_xml,
+                             changesets(:normal_user_closed_change).id)
+    delete :delete, :id => current_relations(:visible_relation).id
+    assert_response :forbidden
+
+    # try to delete with an invalid (non-existent) changeset
+    content update_changeset(current_relations(:visible_relation).to_xml,0)
+    delete :delete, :id => current_relations(:visible_relation).id
+    assert_response :forbidden
+
+    # this won't work because the relation is in-use by another relation
+    content(relations(:used_relation).to_xml)
+    delete :delete, :id => current_relations(:used_relation).id
+    assert_response :forbidden
+
+    # this should work when we provide the appropriate payload...
+    content(relations(:visible_relation).to_xml)
+    delete :delete, :id => current_relations(:visible_relation).id
+    assert_response :forbidden
+
+    # this won't work since the relation is already deleted
+    content(relations(:invisible_relation).to_xml)
+    delete :delete, :id => current_relations(:invisible_relation).id
+    assert_response :forbidden
 
-    # now set auth
-    basic_authorization("test@openstreetmap.org", "test");  
+    # this works now because the relation which was using this one 
+    # has been deleted.
+    content(relations(:used_relation).to_xml)
+    delete :delete, :id => current_relations(:used_relation).id
+    assert_response :forbidden
+
+    # this won't work since the relation never existed
+    delete :delete, :id => 0
+    assert_response :forbidden
+
+    
+
+    # now set auth for the private user
+    basic_authorization(users(:public_user).email, "test");  
 
     # this shouldn't work, as we should need the payload...
     delete :delete, :id => current_relations(:visible_relation).id
@@ -344,15 +394,27 @@ class RelationControllerTest < ActionController::TestCase
     delete :delete, :id => current_relations(:visible_relation).id
     assert_response :conflict
 
-    # this won't work because the relation is in-use by another relation
+    # this won't work because the relation is in a changeset owned by someone else
     content(relations(:used_relation).to_xml)
     delete :delete, :id => current_relations(:used_relation).id
+    assert_response :conflict, 
+    "shouldn't be able to delete a relation in a changeset owned by someone else (#{@response.body})"
+
+    # this won't work because the relation in the payload is different to that passed
+    content(relations(:public_used_relation).to_xml)
+    delete :delete, :id => current_relations(:used_relation).id
+    assert_not_equal relations(:public_used_relation).id, current_relations(:used_relation).id
+    assert_response :bad_request, "shouldn't be able to delete a relation when payload is different to the url"
+    
+    # this won't work because the relation is in-use by another relation
+    content(relations(:public_used_relation).to_xml)
+    delete :delete, :id => current_relations(:public_used_relation).id
     assert_response :precondition_failed, 
        "shouldn't be able to delete a relation used in a relation (#{@response.body})"
 
     # this should work when we provide the appropriate payload...
-    content(relations(:visible_relation).to_xml)
-    delete :delete, :id => current_relations(:visible_relation).id
+    content(relations(:multi_tag_relation).to_xml)
+    delete :delete, :id => current_relations(:multi_tag_relation).id
     assert_response :success
 
     # valid delete should return the new version number, which should
@@ -367,8 +429,8 @@ class RelationControllerTest < ActionController::TestCase
 
     # this works now because the relation which was using this one 
     # has been deleted.
-    content(relations(:used_relation).to_xml)
-    delete :delete, :id => current_relations(:used_relation).id
+    content(relations(:public_used_relation).to_xml)
+    delete :delete, :id => current_relations(:public_used_relation).id
     assert_response :success, 
        "should be able to delete a relation used in an old relation (#{@response.body})"
 
@@ -450,11 +512,11 @@ class RelationControllerTest < ActionController::TestCase
   ##
   # check that relations are ordered
   def test_relation_member_ordering
-    basic_authorization("test@openstreetmap.org", "test");  
-
+    basic_authorization(users(:public_user).email, "test")
+    
     doc_str = <<OSM
 <osm>
- <relation changeset='1'>
+ <relation changeset='4'>
   <member ref='1' type='node' role='first'/>
   <member ref='3' type='node' role='second'/>
   <member ref='1' type='way' role='third'/>
@@ -499,11 +561,32 @@ OSM
   ## 
   # check that relations can contain duplicate members
   def test_relation_member_duplicates
-    basic_authorization("test@openstreetmap.org", "test");  
+    ## First try with the private user
+    basic_authorization(users(:normal_user).email, "test");  
 
     doc_str = <<OSM
 <osm>
- <relation changeset='1'>
+ <relation changeset='4'>
+  <member ref='1' type='node' role='forward'/>
+  <member ref='3' type='node' role='forward'/>
+  <member ref='1' type='node' role='forward'/>
+  <member ref='3' type='node' role='forward'/>
+ </relation>
+</osm>
+OSM
+    doc = XML::Parser.string(doc_str).parse
+
+    content doc
+    put :create
+    assert_response :forbidden
+
+
+    ## Now try with the public user
+    basic_authorization(users(:public_user).email, "test");  
+
+    doc_str = <<OSM
+<osm>
+ <relation changeset='4'>
   <member ref='1' type='node' role='forward'/>
   <member ref='3' type='node' role='forward'/>
   <member ref='1' type='node' role='forward'/>
@@ -551,8 +634,21 @@ OSM
   # create a changeset and yield to the caller to set it up, then assert
   # that the changeset bounding box is +bbox+.
   def check_changeset_modify(bbox)
-    basic_authorization("test@openstreetmap.org", "test");  
+    ## First test with the private user to check that you get a forbidden
+    basic_authorization(users(:normal_user).email, "test");  
 
+    # create a new changeset for this operation, so we are assured
+    # that the bounding box will be newly-generated.
+    changeset_id = with_controller(ChangesetController.new) do
+      content "<osm><changeset/></osm>"
+      put :create
+      assert_response :forbidden, "shouldn't be able to create changeset for modify test, as should get forbidden"
+    end
+
+    
+    ## Now do the whole thing with the public user
+    basic_authorization(users(:public_user).email, "test")
+    
     # create a new changeset for this operation, so we are assured
     # that the bounding box will be newly-generated.
     changeset_id = with_controller(ChangesetController.new) do
index f0590ef71a7e10d45c5d5db29e549f6bb2af03a0..93fa551800b2dc0277ce82656ac9f9cce88f3b96 100644 (file)
@@ -4,7 +4,7 @@ class RelationMemberTest < Test::Unit::TestCase
   api_fixtures
   
   def test_relation_member_count
-    assert_equal 5, RelationMember.count
+    assert_equal 6, RelationMember.count
   end
   
 end
index b72a9835a35505e63a515bf4de728da1ae9bcf6f..5d46a6e599dc0c79eb3ea6c15033c13635bd3d1f 100644 (file)
@@ -4,7 +4,7 @@ class RelationTest < Test::Unit::TestCase
   api_fixtures
   
   def test_relation_count
-    assert_equal 4, Relation.count
+    assert_equal 5, Relation.count
   end
   
 end