forked from zerebubuth/openstreetmap-license-change
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tags.rb
183 lines (154 loc) · 6.46 KB
/
test_tags.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
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './util.rb'
require 'test/unit'
class TestTags < Test::Unit::TestCase
def setup
@db = DB.new(:changesets => {
1 => Changeset[User[true]],
2 => Changeset[User[true]],
3 => Changeset[User[false]]
})
end
# --------------------------------------------------------------------------
# Tests concerned with the keeping and removing of tags.
# --------------------------------------------------------------------------
# This tests the following scenario:
# * agreer creates object
# * decliner adds a name tag
# * agreer makes a trivial change to that tag
# * therefore the decliner retains "ownership" and the tag must be
# removed.
def test_trivial_name_change_by_agreer
trivialchanges = {
"Oxford St" => "Oxford Street",
"Johnann Wolfgang von Goethe Allee" => "Johann-Wolfgang-von-Goethe-Allee",
"Mulberry Hiway" => "Mulberry Highway",
"old fen way" => "Old Fen Way"
}
trivialchanges.each do | old, new |
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
history = [OSM::Node[[0,0], :id => 1, :changeset => 1, :version => 1],
OSM::Node[[0,0], :id => 1, :changeset => 3, :version => 2,
"name" => old],
OSM::Node[[0,0], :id => 1, :changeset => 2, :version => 3,
"name" => new]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Node[[0,0], :id => 1, :changeset => -1, :version => 3]],
Redact[OSM::Node, 1, 2, :hidden],
Redact[OSM::Node, 1, 3, :visible],
], actions)
end
end
# This is the reverse of trivial_name_change_by_agreer:
# * agreer creates object
# * agreer adds a name tag
# * decliner makes a trivial change to that tag
# * therefore the agreer retains "ownership" and the tag can be retained.
# (the assumption here is that the trvial change is not deserving
# of copyright or any other protection - that it could be done by
# an automated process)
def test_trivial_name_change_by_decliner
trivial_changes = {
"Oxford St" => "Oxford Street",
"Johnann Wolfgang von Goethe Allee" => "Johann-Wolfgang-von-Goethe-Allee",
"Mulberry Hiway" => "Mulberry Highway",
"old fen way" => "Old Fen Way"
}
trivial_changes.each do |old, new|
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
expect_redaction([], # expect no redactions here...
[[true, {}],
[true, {"name" => old}],
[false, {"name" => new}]
])
end
end
# Scenario:
# * agreer creates object
# * agreer adds a tag
# * decliner makes a trivial change to the key, keeping the value the same
# as before, the trivial change is not deserving of protection, so the
# change will be kept.
def test_trivial_key_change_by_decliner
trivial_changes = {
"nmae" => "name",
"addr:hosenumber" => "addr:housenumber",
"addr_housenumber" => "addr:housenumber",
"addr:housenummer" => "addr:housenumber"
}
trivial_changes.each do |old, new|
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
expect_redaction([],
[[true, {}],
[true, {old => "some value here"}],
[false, {new => "some value here"}]
])
end
end
# This tests the following scenario:
# * agreer creates object
# * decliner adds a name tag
# * agreer makes a significant change to that tag
# * therefore the decliner's change must be rolled back.
def test_significant_name_change_by_decliner
significant_changes = {
"Oxford St" => "Bedford St",
"Johnann Wolfgang von Goethe Allee" => "Johann-Sebastian-Bach-Allee",
"Mulberry Hiway" => "Blueberry Valley Drive"
}
significant_changes.each do |old, new|
# check that the method considers them actually significant first...
assert_equal(true, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered significant.")
expect_redaction([[2, :hidden]],
[[true, {}],
[false, {"name" => old}],
[true, {"name" => new}]
])
end
end
# This tests the following scenario:
# * agreer creates object
# * agreer adds a name tag
# * decliner makes a significant change to that tag
# * therefore the tag must be rolled back to before the significant change
def test_significant_name_change_by_agreer
significantchanges = {
"Oxford St" => "Bedford St",
"Johnann Wolfgang von Goethe Allee" => "Johann-Sebastian-Bach-Allee",
"Mulberry Hiway" => "Blueberry Valley Drive",
}
significantchanges.each do | old, new |
assert_equal(true, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered significant.")
history = [OSM::Node[[0,0], :id => 1, :changeset => 1, :version => 1],
OSM::Node[[0,0], :id => 1, :changeset => 2, :version => 2,
"name" => old],
OSM::Node[[0,0], :id => 1, :changeset => 3, :version => 3,
"name" => new]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
# decliner's version hidden but no change to object
assert_equal([Edit[OSM::Node[[0,0], :id => 1, :changeset => -1, :version => 3, "name" => old]],
Redact[OSM::Node, 1, 3, :hidden]
], actions)
end
end
private
def expect_redaction(redacts, tags)
history = Array.new
tags.each_with_index do |e, version|
agreer_edit, t = e
hash = { :id => 1, :changeset => (agreer_edit ? 1 : 3), :version => (version + 1) }
hash.merge!(t)
history << OSM::Node[[0, 0], hash]
end
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal(redacts.map {|v,h| Redact[OSM::Node, 1, v, h]}, actions,
"Note: with tag pattern #{tags}")
end
end