forked from zerebubuth/openstreetmap-license-change
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_way.rb
157 lines (145 loc) · 7.75 KB
/
test_way.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
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './util.rb'
require 'test/unit'
class TestWay < Test::Unit::TestCase
def setup
@db = DB.new(:changesets => {
1 => Changeset[User[true]],
2 => Changeset[User[true]],
3 => Changeset[User[false]]
})
end
# --------------------------------------------------------------------------
# Way tests
# --------------------------------------------------------------------------
# way created by decliner, with no other edits, needs to be deleted
# and redacted hidden.
def test_way_simple
history = [OSM::Way[[1,2,3], :id => 1, :changeset => 3, :version => 1]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Delete[OSM::Way, 1],
Redact[OSM::Way, 1, 1, :hidden]
], actions)
end
# way created by decliner, but nodes subsequently replaced by agreer.
# Under the v0 principle, we can keep the nodes, but not the tags
def test_way_nodes_replaced
history = [OSM::Way[[1,2,3], :id=>1, :changeset=>3, :version=>1, "highway"=>"primary"], # created by decliner
OSM::Way[[4,6 ], :id=>1, :changeset=>1, :version=>2, "highway"=>"primary"]] # nodes replaced by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[[4,6], :id=>1, :changeset=>-1, :version=>2]],
Redact[OSM::Way, 1, 1, :hidden],
Redact[OSM::Way, 1, 2, :visible] # this version has the tainted highway tag in it
], actions)
end
# way created by decliner, but nodes subsequently replaced by agreer.
# Under the v0 principle, we can keep the nodes
def test_way_nodes_replaced_no_tag
history = [OSM::Way[[1,2,3], :id=>1, :changeset=>3, :version=>1], # created by decliner
OSM::Way[[4,6 ], :id=>1, :changeset=>1, :version=>2]] # nodes replaced by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Way, 1, 1, :hidden]
], actions)
end
# way created by agreer, but nodes removed by decliner, then subsequent edit by agreer
def test_way_nodes_removed
history = [OSM::Way[[1,2,3,4,5], :id=>1, :changeset=>1, :version=>1, "highway"=>"trunk"], # created by agreer
OSM::Way[[1,2, 4,5], :id=>1, :changeset=>3, :version=>2, "highway"=>"trunk"], # node removed by decliner
OSM::Way[[1,2, 4,5], :id=>1, :changeset=>2, :version=>3, "highway"=>"primary"]] # tag change by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[[1,2,3,4,5], :id=>1, :changeset=>-1, :version=>3, "highway"=>"primary"]],
Redact[OSM::Way, 1, 2, :hidden],
Redact[OSM::Way, 1, 3, :visible] # needs to be redacted, as node 3 are still missing in this version
], actions)
end
# as above, but adding nodes
def test_way_nodes_added
history = [OSM::Way[[ 1,2,3], :id=>1, :changeset=>1, :version=>1, "highway"=>"trunk"], # created by agreer
OSM::Way[[4,5,1,2,3], :id=>1, :changeset=>3, :version=>2, "highway"=>"trunk"], # nodes added by decliner
OSM::Way[[4,5,1,2,3], :id=>1, :changeset=>2, :version=>3, "highway"=>"primary"]] # tag change by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[[1,2,3], :id=>1, :changeset=>-1, :version=>3, "highway"=>"primary"]],
Redact[OSM::Way, 1, 2, :hidden],
Redact[OSM::Way, 1, 3, :visible] # needs to be redacted, as nodes [4,5] are still in this version
], actions)
end
# if an acceptor creates a way, a decliner adds some nodes but doesn't
# change the tags in a subsequent edit, then we just need to roll back
# the nodes changes.
def test_way_decliner_adds_nodes
# test multiple versions of this - it shouldn't matter where in the
# way the decliner has added the nodes.
init_nodes = [1,2,3]
edit_nodes = [[4,5,6,1,2,3],
[4,1,5,2,6,3],
[1,4,2,5,3,6],
[1,2,4,5,6,3],
[1,2,3,4,5,6]]
edit_nodes.each do |next_nodes|
history = [OSM::Way[init_nodes, :id => 1, :changeset => 1, :version => 1, "highway" => "trunk"],
OSM::Way[next_nodes, :id => 1, :changeset => 3, :version => 2, "highway" => "trunk"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[init_nodes, :id => 1, :changeset => -1, :version => 2, "highway" => "trunk"]],
Redact[OSM::Way, 1, 2, :hidden]
], actions)
end
end
# by the "version zero" proposal, a way at version zero has an empty
# list of nodes, so even if the way was created by a decliner, the
# addition of nodes to it by an acceptor is salvagable. note, however
# that the tags are not.
def test_way_decliner_creates_acceptor_adds
history = [OSM::Way[[1,2,3], :id => 1, :changeset => 3, :version => 1, "highway" => "trunk"],
OSM::Way[[1,2,4,3,5,6], :id => 1, :changeset => 1, :version => 2, "highway" => "trunk", "ref" => "666"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[[4,5,6], :id => 1, :changeset => -1, :version => 2, "ref" => "666"]],
Redact[OSM::Way, 1, 1, :hidden],
Redact[OSM::Way, 1, 2, :visible]
], actions)
end
# a variant of the above, in which the way is created by an acceptor,
# but all of the nodes are replaced in the second version by a decliner.
# however, tags created in the first, acceptor, version are clean.
def test_way_decliner_sandwich_replace
history = [OSM::Way[[7,8,9], :id => 1, :changeset => 1, :version => 1, "highway" => "trunk"],
OSM::Way[[1,2,3], :id => 1, :changeset => 3, :version => 2, "highway" => "trunk"],
OSM::Way[[1,2,4,3,5,6], :id => 1, :changeset => 1, :version => 3, "highway" => "trunk", "ref" => "666"]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[[4,5,6], :id => 1, :changeset => -1, :version => 3, "highway" => "trunk", "ref" => "666"]],
Redact[OSM::Way, 1, 2, :hidden],
Redact[OSM::Way, 1, 3, :visible]
], actions)
end
# test what happens when way nodes are deleted and added.
#
# upon careful consideration, we reckoned that deletions of way nodes should stay
# deleted as the most likely case for losing a node from a way is that it was
# also deleted, so adding it back would probably serve no purpose. with that in
# mind, node replacements should be treated as a deletion followed by an addition
# and, if the addition is by a decliner, should be removed from the final version.
#
def test_way_nodes_replaced_and_added
history = [OSM::Way[[1,2,3 ], :id=>1, :changeset=>1, :version=>1, "highway"=>"trunk"], # created by agreer
OSM::Way[[1,4,3 ], :id=>1, :changeset=>3, :version=>2, "highway"=>"trunk"], # node removed by decliner
OSM::Way[[1,4,3,5,6], :id=>1, :changeset=>2, :version=>3, "highway"=>"primary"]] # tag change and node addition by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Way[[1,3,5,6], :id=>1, :changeset=>-1, :version=>3, "highway"=>"primary"]],
Redact[OSM::Way, 1, 2, :hidden],
Redact[OSM::Way, 1, 3, :visible] # needs to be redacted - node 4 still in this version
], actions)
end
# ** FIXME: add some more way tests here, and some relation ones too.
end