Remove do_redact_element methods from api old element redaction tests
This commit is contained in:
parent
98a365c827
commit
c134cabab2
3 changed files with 37 additions and 76 deletions
|
@ -197,11 +197,7 @@ module Api
|
|||
# test the redaction of an old version of a node, while not being
|
||||
# authorised.
|
||||
def test_redact_node_unauthorised
|
||||
node = create(:node, :with_history, :version => 4)
|
||||
node_v3 = node.old_nodes.find_by(:version => 3)
|
||||
|
||||
do_redact_node(node_v3,
|
||||
create(:redaction))
|
||||
do_redact_redactable_node
|
||||
assert_response :unauthorized, "should need to be authenticated to redact."
|
||||
end
|
||||
|
||||
|
@ -209,14 +205,7 @@ module Api
|
|||
# test the redaction of an old version of a node, while being
|
||||
# authorised as a normal user.
|
||||
def test_redact_node_normal_user
|
||||
auth_header = bearer_authorization_header
|
||||
|
||||
node = create(:node, :with_history, :version => 4)
|
||||
node_v3 = node.old_nodes.find_by(:version => 3)
|
||||
|
||||
do_redact_node(node_v3,
|
||||
create(:redaction),
|
||||
auth_header)
|
||||
do_redact_redactable_node bearer_authorization_header
|
||||
assert_response :forbidden, "should need to be moderator to redact."
|
||||
end
|
||||
|
||||
|
@ -224,14 +213,12 @@ module Api
|
|||
# test that, even as moderator, the current version of a node
|
||||
# can't be redacted.
|
||||
def test_redact_node_current_version
|
||||
node = create(:node, :with_history, :version => 4)
|
||||
redaction = create(:redaction)
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
|
||||
node = create(:node, :with_history, :version => 4)
|
||||
node_v4 = node.old_nodes.find_by(:version => 4)
|
||||
post node_version_redact_path(node, 4), :params => { :redaction => redaction.id }, :headers => auth_header
|
||||
|
||||
do_redact_node(node_v4,
|
||||
create(:redaction),
|
||||
auth_header)
|
||||
assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
|
||||
end
|
||||
|
||||
|
@ -265,12 +252,15 @@ module Api
|
|||
def test_redact_node_moderator
|
||||
node = create(:node, :with_history, :version => 4)
|
||||
node_v3 = node.old_nodes.find_by(:version => 3)
|
||||
redaction = create(:redaction)
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
|
||||
do_redact_node(node_v3, create(:redaction), auth_header)
|
||||
post node_version_redact_path(*node_v3.id), :params => { :redaction => redaction.id }, :headers => auth_header
|
||||
|
||||
assert_response :success, "should be OK to redact old version as moderator."
|
||||
assert_predicate node_v3.reload, :redacted?
|
||||
node_v3.reload
|
||||
assert_predicate node_v3, :redacted?
|
||||
assert_equal redaction, node_v3.redaction
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -342,16 +332,9 @@ module Api
|
|||
|
||||
def do_redact_redactable_node(headers = {})
|
||||
node = create(:node, :with_history, :version => 4)
|
||||
node_v3 = node.old_nodes.find_by(:version => 3)
|
||||
do_redact_node(node_v3, create(:redaction), headers)
|
||||
end
|
||||
redaction = create(:redaction)
|
||||
|
||||
def do_redact_node(node, redaction, headers = {})
|
||||
get api_node_version_path(node.node_id, node.version), :headers => headers
|
||||
assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}."
|
||||
|
||||
# now redact it
|
||||
post node_version_redact_path(node.node_id, node.version), :params => { :redaction => redaction.id }, :headers => headers
|
||||
post node_version_redact_path(node, 3), :params => { :redaction => redaction.id }, :headers => headers
|
||||
end
|
||||
|
||||
def check_not_found_id_version(id, version)
|
||||
|
|
|
@ -188,10 +188,7 @@ module Api
|
|||
# test the redaction of an old version of a relation, while not being
|
||||
# authorised.
|
||||
def test_redact_relation_unauthorised
|
||||
relation = create(:relation, :with_history, :version => 4)
|
||||
relation_v3 = relation.old_relations.find_by(:version => 3)
|
||||
|
||||
do_redact_relation(relation_v3, create(:redaction))
|
||||
do_redact_redactable_relation
|
||||
assert_response :unauthorized, "should need to be authenticated to redact."
|
||||
end
|
||||
|
||||
|
@ -199,12 +196,7 @@ module Api
|
|||
# test the redaction of an old version of a relation, while being
|
||||
# authorised as a normal user.
|
||||
def test_redact_relation_normal_user
|
||||
relation = create(:relation, :with_history, :version => 4)
|
||||
relation_v3 = relation.old_relations.find_by(:version => 3)
|
||||
|
||||
auth_header = bearer_authorization_header
|
||||
|
||||
do_redact_relation(relation_v3, create(:redaction), auth_header)
|
||||
do_redact_redactable_relation bearer_authorization_header
|
||||
assert_response :forbidden, "should need to be moderator to redact."
|
||||
end
|
||||
|
||||
|
@ -213,11 +205,11 @@ module Api
|
|||
# can't be redacted.
|
||||
def test_redact_relation_current_version
|
||||
relation = create(:relation, :with_history, :version => 4)
|
||||
relation_latest = relation.old_relations.last
|
||||
|
||||
redaction = create(:redaction)
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
|
||||
do_redact_relation(relation_latest, create(:redaction), auth_header)
|
||||
post relation_version_redact_path(relation, 4), :params => { :redaction => redaction.id }, :headers => auth_header
|
||||
|
||||
assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
|
||||
end
|
||||
|
||||
|
@ -251,12 +243,15 @@ module Api
|
|||
def test_redact_relation_moderator
|
||||
relation = create(:relation, :with_history, :version => 4)
|
||||
relation_v3 = relation.old_relations.find_by(:version => 3)
|
||||
redaction = create(:redaction)
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
|
||||
do_redact_relation(relation_v3, create(:redaction), auth_header)
|
||||
post relation_version_redact_path(*relation_v3.id), :params => { :redaction => redaction.id }, :headers => auth_header
|
||||
|
||||
assert_response :success, "should be OK to redact old version as moderator."
|
||||
assert_predicate relation_v3.reload, :redacted?
|
||||
relation_v3.reload
|
||||
assert_predicate relation_v3, :redacted?
|
||||
assert_equal redaction, relation_v3.redaction
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -326,16 +321,9 @@ module Api
|
|||
|
||||
def do_redact_redactable_relation(headers = {})
|
||||
relation = create(:relation, :with_history, :version => 4)
|
||||
relation_v3 = relation.old_relations.find_by(:version => 3)
|
||||
do_redact_relation(relation_v3, create(:redaction), headers)
|
||||
end
|
||||
redaction = create(:redaction)
|
||||
|
||||
def do_redact_relation(relation, redaction, headers = {})
|
||||
get api_relation_version_path(relation.relation_id, relation.version)
|
||||
assert_response :success, "should be able to get version #{relation.version} of relation #{relation.relation_id}."
|
||||
|
||||
# now redact it
|
||||
post relation_version_redact_path(relation.relation_id, relation.version), :params => { :redaction => redaction.id }, :headers => headers
|
||||
post relation_version_redact_path(relation, 3), :params => { :redaction => redaction.id }, :headers => headers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -199,10 +199,7 @@ module Api
|
|||
# test the redaction of an old version of a way, while not being
|
||||
# authorised.
|
||||
def test_redact_way_unauthorised
|
||||
way = create(:way, :with_history, :version => 4)
|
||||
way_v3 = way.old_ways.find_by(:version => 3)
|
||||
|
||||
do_redact_way(way_v3, create(:redaction))
|
||||
do_redact_redactable_way
|
||||
assert_response :unauthorized, "should need to be authenticated to redact."
|
||||
end
|
||||
|
||||
|
@ -210,11 +207,7 @@ module Api
|
|||
# test the redaction of an old version of a way, while being
|
||||
# authorised as a normal user.
|
||||
def test_redact_way_normal_user
|
||||
auth_header = bearer_authorization_header
|
||||
way = create(:way, :with_history, :version => 4)
|
||||
way_v3 = way.old_ways.find_by(:version => 3)
|
||||
|
||||
do_redact_way(way_v3, create(:redaction), auth_header)
|
||||
do_redact_redactable_way bearer_authorization_header
|
||||
assert_response :forbidden, "should need to be moderator to redact."
|
||||
end
|
||||
|
||||
|
@ -222,11 +215,12 @@ module Api
|
|||
# test that, even as moderator, the current version of a way
|
||||
# can't be redacted.
|
||||
def test_redact_way_current_version
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
way = create(:way, :with_history, :version => 4)
|
||||
way_latest = way.old_ways.last
|
||||
redaction = create(:redaction)
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
|
||||
post way_version_redact_path(way, 4), :params => { :redaction => redaction.id }, :headers => auth_header
|
||||
|
||||
do_redact_way(way_latest, create(:redaction), auth_header)
|
||||
assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
|
||||
end
|
||||
|
||||
|
@ -260,12 +254,15 @@ module Api
|
|||
def test_redact_way_moderator
|
||||
way = create(:way, :with_history, :version => 4)
|
||||
way_v3 = way.old_ways.find_by(:version => 3)
|
||||
redaction = create(:redaction)
|
||||
auth_header = bearer_authorization_header create(:moderator_user)
|
||||
|
||||
do_redact_way(way_v3, create(:redaction), auth_header)
|
||||
post way_version_redact_path(*way_v3.id), :params => { :redaction => redaction.id }, :headers => auth_header
|
||||
|
||||
assert_response :success, "should be OK to redact old version as moderator."
|
||||
assert_predicate way_v3.reload, :redacted?
|
||||
way_v3.reload
|
||||
assert_predicate way_v3, :redacted?
|
||||
assert_equal redaction, way_v3.redaction
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -358,16 +355,9 @@ module Api
|
|||
|
||||
def do_redact_redactable_way(headers = {})
|
||||
way = create(:way, :with_history, :version => 4)
|
||||
way_v3 = way.old_ways.find_by(:version => 3)
|
||||
do_redact_way(way_v3, create(:redaction), headers)
|
||||
end
|
||||
redaction = create(:redaction)
|
||||
|
||||
def do_redact_way(way, redaction, headers = {})
|
||||
get api_way_version_path(way.way_id, way.version)
|
||||
assert_response :success, "should be able to get version #{way.version} of way #{way.way_id}."
|
||||
|
||||
# now redact it
|
||||
post way_version_redact_path(way.way_id, way.version), :params => { :redaction => redaction.id }, :headers => headers
|
||||
post way_version_redact_path(way.id, 2), :params => { :redaction => redaction.id }, :headers => headers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue