forked from zerebubuth/openstreetmap-license-change
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_relation.rb
executable file
·208 lines (189 loc) · 11.6 KB
/
test_relation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env ruby
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './util.rb'
require 'minitest/unit'
class TestRelation < MiniTest::Unit::TestCase
def setup
@db = DB.new(:changesets => {
1 => Changeset[User[true]],
2 => Changeset[User[true]],
3 => Changeset[User[false]]
})
end
def test_relation_simple
history = [OSM::Relation[
[ [OSM::Way,1,""] , [OSM::Way,2,""] ],
:id => 1, :changeset => 3, :version => 1,
"type" => "route" ]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Delete[OSM::Relation, 1],
Redact[OSM::Relation, 1, 1, :hidden]
], actions)
end
def test_relation_simple_keep
history = [OSM::Relation[
[ [OSM::Way,1,""] , [OSM::Way,2,""] ],
:id => 1, :changeset => 1, :version => 1,
"type" => "route" ]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([], actions)
end
# relation created by decliner, then members added by agreer.
# Under the v0 principle, we can keep the new members, but not the v1 members or the tags
def test_relation_members_added
history = [OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2] ], :id => 1, :changeset => 3, :version => 1, "type" => "route" ],
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,4], [OSM::Way,2] ], :id => 1, :changeset => 2, :version => 2, "type" => "route" ],
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,4], [OSM::Way,2], [OSM::Way,3] ], :id => 1, :changeset => 1, :version => 3, "type" => "route" ]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Relation[[ [OSM::Way,4], [OSM::Way,3] ], :id => 1, :changeset => -1, :version => 3, "type" => "route"]],
Redact[OSM::Relation, 1, 1, :hidden],
Redact[OSM::Relation, 1, 2, :visible],
Redact[OSM::Relation, 1, 3, :visible]
], actions)
end
# relation members added by agreer, then role changed by decliner
def test_relation_role_changed
history = [OSM::Relation[[ [OSM::Way,1,"outer"] , [OSM::Way,2,"" ] ], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,"outer"] , [OSM::Way,2,"inner"] ], :id=>1, :changeset=>3, :version=>2, "type" => "multipolygon"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Relation[[ [OSM::Way,1,"outer"] , [OSM::Way,2,""] ], :id=>1, :changeset=>-1, :version=>2, "type" => "multipolygon"]],
Redact[OSM::Relation,1,2,:hidden]
], actions)
end
# relation members added by agreer, then role changed by decliner, and changed back by agreer. Intermediate edit should be redacted but no edits made.
def test_relation_role_edited_reverted
history = [OSM::Relation[[ [OSM::Way,1,"outer"] , [OSM::Way,2,"inner"] ], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,"outer"] , [OSM::Way,2,"aaaaa"] ], :id=>1, :changeset=>3, :version=>2, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,"outer"] , [OSM::Way,2,"inner"] ], :id=>1, :changeset=>1, :version=>3, "type" => "multipolygon"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Relation,1,2,:hidden]], actions)
end
# relation member deleted by decliner. by the "deletions are OK" rule, nothing needs to happen
def test_relation_member_deleted_by_decliner
history = [OSM::Relation[[ [OSM::Way,1,""] , [OSM::Way,2,""] ], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,""] ], :id=>1, :changeset=>3, :version=>2, "type" => "multipolygon"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([], actions)
end
# relation member deleted by decliner then re-added by agreer. by the "deletions are OK" rule
# there is no need to do anything to the element.
def test_relation_member_deleted_by_decliner_readded_by_agreer
history = [OSM::Relation[[ [OSM::Way,1,""] , [OSM::Way,2,""] ], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,""] ], :id=>1, :changeset=>3, :version=>2, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,""] , [OSM::Way,2,""] ], :id=>1, :changeset=>1, :version=>3, "type" => "multipolygon"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([], actions)
end
# relation attributes changed by decliner, then marked odbl=clean. Redact the original edit but make no edit to the final result.
def test_relation_attributes_marked_clean
history = [OSM::Relation[[ [OSM::Way,1,""]], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,""]], :id=>1, :changeset=>3, :version=>2, "type" => "unipolygon"],
OSM::Relation[[ [OSM::Way,1,""]], :id=>1, :changeset=>1, :version=>3, "type" => "unipolygon", "odbl" => "clean"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Relation,1,2,:hidden]], actions)
end
# member role changed by decliner, then marked odbl=clean. Redact the original edit but make no edit to the final result.
def test_member_role_marked_clean
history = [OSM::Relation[[ [OSM::Way,1,""]], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,"aaa"]], :id=>1, :changeset=>3, :version=>2, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,"aaa"]], :id=>1, :changeset=>1, :version=>3, "type" => "multipolygon", "odbl" => "clean"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Relation,1,2,:hidden]], actions)
end
# member role changed on way that subsequently gets deleted. Redact the change but make no edits.
def test_relation_attribute_changed_then_deleted
history = [OSM::Relation[[ [OSM::Way,1,""], [OSM::Way,2,""]], :id=>1, :changeset=>1, :version=>1, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,""], [OSM::Way,2,"aaa"]], :id=>1, :changeset=>3, :version=>2, "type" => "multipolygon"],
OSM::Relation[[ [OSM::Way,1,""]], :id=>1, :changeset=>1, :version=>3, "type" => "multipolygon"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Relation,1,2,:hidden]], actions)
end
# relation created by agreer, then order changed by decliner
#
# this is tricky for the same reason as the way-node ordering stuff above.
# the change of order can equally be interpreted as a deletion and
# addition, which trigger a completely different set of rules.
#
def test_relation_order_changed
history = [OSM::Relation[[ [OSM::Way,1] , [OSM::Way,4], [OSM::Way,2], [OSM::Way,3] ], :id => 1, :changeset => 1, :version => 1, "type" => "route" ],
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2], [OSM::Way,3], [OSM::Way,4] ], :id => 1, :changeset => 3, :version => 2, "type" => "route" ]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Relation[[ [OSM::Way,1], [OSM::Way,4], [OSM::Way,2], [OSM::Way,3] ], :id=>1, :changeset=>-1, :version=>2, "type" => "route"]],
Redact[OSM::Relation,1,2,:hidden]
], actions)
end
# relation created by agreer, then order changed by decliner, then extra members added by agreer
# (we can't preserve order in this case. Difficult to know what to do - fall back to the last
# good order, with new members appended? Or try and insert at the same index, even if it doesn't
# make any sense without the previous order?)
#
# this is tricky for the same reason as the way-node ordering stuff above.
# the change of order can equally be interpreted as a deletion and
# addition, which trigger a completely different set of rules.
#
def test_relation_order_changed_then_member_appended
history = [OSM::Relation[[ [OSM::Way,1] , [OSM::Way,4], [OSM::Way,2], [OSM::Way,3] ], :id => 1, :changeset => 1, :version => 1, "type" => "route" ],
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2], [OSM::Way,3], [OSM::Way,4] ], :id => 1, :changeset => 3, :version => 2, "type" => "route" ],
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2], [OSM::Way,3], [OSM::Way,4], [OSM::Way,5] ], :id => 1, :changeset => 2, :version => 3, "type" => "route" ]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Relation[[ [OSM::Way,1], [OSM::Way,4], [OSM::Way,2], [OSM::Way,3], [OSM::Way,5] ], :id=>1, :changeset=>-1, :version=>3, "type" => "route"]],
Redact[OSM::Relation,1,2,:hidden],
Redact[OSM::Relation,1,3,:visible]
], actions)
end
# simplified version of test_automatic_relation78000
# member added by agreer in redacted changeset that is later removed by another agreer
def test_relation_members_added_then_removed
history = [OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2] ], :id => 1, :changeset => 3, :version => 1, "type" => "route" ], #decliner
OSM::Relation[[ [OSM::Way,2], [OSM::Way,3] , [OSM::Way,4] ], :id => 1, :changeset => 2, :version => 2, "type" => "route" ], #agreer
OSM::Relation[[ [OSM::Way,4] ], :id => 1, :changeset => 1, :version => 3, "type" => "route" ]] #agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Relation, 1, 1, :hidden],
Redact[OSM::Relation, 1, 2, :visible]
], actions)
end
# member added as the first member by a decliner, that means that the member added in
# the third version have to be inserted as first and not as seccond member
def test_relation_members_added_by_decliner
history = [OSM::Relation[[ [OSM::Way,3] ], :id => 1, :changeset => 1, :version => 1 ], #agreer
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,3] ], :id => 1, :changeset => 3, :version => 2 ], #decliner
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2] , [OSM::Way,3] ], :id => 1, :changeset => 2, :version => 3 ]] #agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Relation[[ [OSM::Way,2], [OSM::Way,3] ], :id => 1, :changeset => -1, :version => 3]],
Redact[OSM::Relation, 1, 2, :hidden],
Redact[OSM::Relation, 1, 3, :visible]
], actions)
end
def test_relation_members_added_then_moved
history = [OSM::Relation[[ [OSM::Way,2] , [OSM::Way,3] ], :id => 1, :changeset => 1, :version => 1 ], #agreer
OSM::Relation[[ [OSM::Way,1] , [OSM::Way,2] , [OSM::Way,3] ], :id => 1, :changeset => 3, :version => 2 ], #decliner
OSM::Relation[[ [OSM::Way,3] , [OSM::Way,1] , [OSM::Way,2] ], :id => 1, :changeset => 2, :version => 3 ]] #agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Relation[[ [OSM::Way,3] , [OSM::Way,2] ], :id => 1, :changeset => -1, :version => 3]],
Redact[OSM::Relation, 1, 2, :hidden],
Redact[OSM::Relation, 1, 3, :visible]
], actions)
end
end
if __FILE__ == $0
MiniTest::Unit.new.run(ARGV)
end