-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_odbl_tag.rb
executable file
·147 lines (131 loc) · 7.12 KB
/
test_odbl_tag.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
#!/usr/bin/env ruby
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './util.rb'
require 'minitest/unit'
class TestOdblTag < MiniTest::Unit::TestCase
def setup
@db = DB.new(:changesets => {
1 => Changeset[User[true]],
2 => Changeset[User[true]],
3 => Changeset[User[false]]
})
end
# --------------------------------------------------------------------------
# Tests concerning odbl=clean tag
# --------------------------------------------------------------------------
# odbl=clean overrides previous object history, but old versions still need to be redacted
def test_node_odbl_clean
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "odbl" => "clean"]] # odbl=clean added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# as above, but with differently-cased odbl=clean tag
def test_node_odbl_clean_case_insensitive
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "ODbL" => "Clean"]] # odbl=clean added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# Some people like to use "yes" instead of "clean"
def test_node_odbl_clean_case_insensitive_yes
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "oDbL" => "yEs"]] # odbl=clean added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# Some people like to use "true" instead of "clean"
def test_node_odbl_clean_case_insensitive_true
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "oDbL" => "TrUe"]] # odbl=clean added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# Some people like to use "1" instead of "clean"
def test_node_odbl_clean_case_insensitive_one
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "oDbL" => "1"]] # odbl=clean added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# Some people like to use "clear" instead of "clean"
def test_node_odbl_clean_case_insensitive_clear
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "odbl" => "clear"]] # odbl=clean added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# Cater for the typo obdl=clean
def test_node_obdl_clean
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "obdl" => "clean"]] # obdl=clean (typo) added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# Cater for the typo obdl=clean
def test_node_obdl_clean_typo
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "oodbl" => "clean"]] # obdl=clean (typo) added by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
], actions)
end
# What happenes when the odbl=clean is removed
def test_node_odbl_clean_removed
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "odbl" => "clean"], # odbl=clean added by agreer
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 4, "foo" => "bar"]] # tag removed by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Node[[0, 0], :id => 1, :version => 4, :visible => true, :changeset => -1]],
Redact[OSM::Node, 1, 2, :hidden],
Redact[OSM::Node, 1, 3, :visible],
Redact[OSM::Node, 1, 4, :visible]
], actions)
end
# What if someone was adding and removing the odbl=clean tag
def test_node_odbl_clean_removed
history = [OSM::Node[[0,0], :id=>1, :changeset => 1, :version => 1], # created by agreer
OSM::Node[[0,0], :id=>1, :changeset => 3, :version => 2, "foo" => "bar"], # edited by decliner
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 3, "foo" => "bar", "odbl" => "clean"], # odbl=clean added by agreer
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 4, "foo" => "bar"], # odbl tag removed by agreer
OSM::Node[[0,0], :id=>1, :changeset => 2, :version => 5, "odbl" => "clean"]] # object cleaned and odbl tag reintroduced by agreer
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Redact[OSM::Node, 1, 2, :hidden],
Redact[OSM::Node, 1, 3, :visible],
Redact[OSM::Node, 1, 4, :visible]
], actions)
end
end
if __FILE__ == $0
MiniTest::Unit.new.run(ARGV)
end