##// END OF EJS Templates
scm: mercurial: add test of binary file should be force download in functional test (#6256)....
Toshi MARUYAMA -
r5082:9000cdbf2fba
parent child
Show More
@@ -1,366 +1,373
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30 PRJ_ID = 3
31 31
32 32 ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
33 33
34 34 def setup
35 35 @controller = RepositoriesController.new
36 36 @request = ActionController::TestRequest.new
37 37 @response = ActionController::TestResponse.new
38 38 User.current = nil
39 39 @repository = Repository::Mercurial.create(
40 40 :project => Project.find(PRJ_ID),
41 41 :url => REPOSITORY_PATH,
42 42 :path_encoding => 'ISO-8859-1'
43 43 )
44 44 assert @repository
45 45 @diff_c_support = true
46 46 @char_1 = CHAR_1_HEX.dup
47 47 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
48 48 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
49 49 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
50 50 if @char_1.respond_to?(:force_encoding)
51 51 @char_1.force_encoding('UTF-8')
52 52 @tag_char_1.force_encoding('UTF-8')
53 53 @branch_char_0.force_encoding('UTF-8')
54 54 @branch_char_1.force_encoding('UTF-8')
55 55 end
56 56 end
57 57
58 58 if ruby19_non_utf8_pass
59 59 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
60 60 "and Encoding.default_external is not UTF-8. " +
61 61 "Current value is '#{Encoding.default_external.to_s}'"
62 62 def test_fake; assert true end
63 63 elsif File.directory?(REPOSITORY_PATH)
64 64 def test_show_root
65 65 @repository.fetch_changesets
66 66 @repository.reload
67 67 get :show, :id => PRJ_ID
68 68 assert_response :success
69 69 assert_template 'show'
70 70 assert_not_nil assigns(:entries)
71 71 assert_equal 4, assigns(:entries).size
72 72 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
73 73 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
74 74 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
75 75 assert_not_nil assigns(:changesets)
76 76 assigns(:changesets).size > 0
77 77 end
78 78
79 79 def test_show_directory
80 80 @repository.fetch_changesets
81 81 @repository.reload
82 82 get :show, :id => PRJ_ID, :path => ['images']
83 83 assert_response :success
84 84 assert_template 'show'
85 85 assert_not_nil assigns(:entries)
86 86 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
87 87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
88 88 assert_not_nil entry
89 89 assert_equal 'file', entry.kind
90 90 assert_equal 'images/edit.png', entry.path
91 91 assert_not_nil assigns(:changesets)
92 92 assigns(:changesets).size > 0
93 93 end
94 94
95 95 def test_show_at_given_revision
96 96 @repository.fetch_changesets
97 97 @repository.reload
98 98 [0, '0', '0885933ad4f6'].each do |r1|
99 99 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
100 100 assert_response :success
101 101 assert_template 'show'
102 102 assert_not_nil assigns(:entries)
103 103 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
104 104 assert_not_nil assigns(:changesets)
105 105 assigns(:changesets).size > 0
106 106 end
107 107 end
108 108
109 109 def test_show_directory_sql_escape_percent
110 110 @repository.fetch_changesets
111 111 @repository.reload
112 112 [13, '13', '3a330eb32958'].each do |r1|
113 113 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'], :rev => r1
114 114 assert_response :success
115 115 assert_template 'show'
116 116
117 117 assert_not_nil assigns(:entries)
118 118 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
119 119 changesets = assigns(:changesets)
120 120 assert_not_nil changesets
121 121 assigns(:changesets).size > 0
122 122 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
123 123 end
124 124 end
125 125
126 126 def test_show_directory_latin_1
127 127 @repository.fetch_changesets
128 128 @repository.reload
129 129 [21, '21', 'adf805632193'].each do |r1|
130 130 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
131 131 assert_response :success
132 132 assert_template 'show'
133 133
134 134 assert_not_nil assigns(:entries)
135 135 assert_equal ["make-latin-1-file.rb",
136 136 "test-#{@char_1}-1.txt",
137 137 "test-#{@char_1}-2.txt",
138 138 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
139 139 changesets = assigns(:changesets)
140 140 assert_not_nil changesets
141 141 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
142 142 end
143 143 end
144 144
145 145 def test_show_branch
146 146 @repository.fetch_changesets
147 147 @repository.reload
148 148 [
149 149 'default',
150 150 @branch_char_1,
151 151 'branch (1)[2]&,%.-3_4',
152 152 @branch_char_0,
153 153 'test_branch.latin-1',
154 154 'test-branch-00',
155 155 ].each do |bra|
156 156 get :show, :id => PRJ_ID, :rev => bra
157 157 assert_response :success
158 158 assert_template 'show'
159 159 assert_not_nil assigns(:entries)
160 160 assert assigns(:entries).size > 0
161 161 assert_not_nil assigns(:changesets)
162 162 assigns(:changesets).size > 0
163 163 end
164 164 end
165 165
166 166 def test_show_tag
167 167 @repository.fetch_changesets
168 168 @repository.reload
169 169 [
170 170 @tag_char_1,
171 171 'tag_test.00',
172 172 'tag-init-revision'
173 173 ].each do |tag|
174 174 get :show, :id => PRJ_ID, :rev => tag
175 175 assert_response :success
176 176 assert_template 'show'
177 177 assert_not_nil assigns(:entries)
178 178 assert assigns(:entries).size > 0
179 179 assert_not_nil assigns(:changesets)
180 180 assigns(:changesets).size > 0
181 181 end
182 182 end
183 183
184 184 def test_changes
185 185 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
186 186 assert_response :success
187 187 assert_template 'changes'
188 188 assert_tag :tag => 'h2', :content => 'edit.png'
189 189 end
190 190
191 191 def test_entry_show
192 192 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
193 193 assert_response :success
194 194 assert_template 'entry'
195 195 # Line 10
196 196 assert_tag :tag => 'th',
197 197 :content => '10',
198 198 :attributes => { :class => 'line-num' },
199 199 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
200 200 end
201 201
202 202 def test_entry_show_latin_1
203 203 [21, '21', 'adf805632193'].each do |r1|
204 204 get :entry, :id => PRJ_ID, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
205 205 assert_response :success
206 206 assert_template 'entry'
207 207 assert_tag :tag => 'th',
208 208 :content => '1',
209 209 :attributes => { :class => 'line-num' },
210 210 :sibling => { :tag => 'td',
211 211 :content => /Mercurial is a distributed version control system/ }
212 212 end
213 213 end
214 214
215 215 def test_entry_download
216 216 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
217 217 assert_response :success
218 218 # File content
219 219 assert @response.body.include?('WITHOUT ANY WARRANTY')
220 220 end
221 221
222 def test_entry_binary_force_download
223 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
224 assert_response :success
225 # TODO: 'image/png'
226 assert_equal 'application/octet-stream', @response.content_type
227 end
228
222 229 def test_directory_entry
223 230 get :entry, :id => PRJ_ID, :path => ['sources']
224 231 assert_response :success
225 232 assert_template 'show'
226 233 assert_not_nil assigns(:entry)
227 234 assert_equal 'sources', assigns(:entry).name
228 235 end
229 236
230 237 def test_diff
231 238 @repository.fetch_changesets
232 239 @repository.reload
233 240 [4, '4', 'def6d2f1254a'].each do |r1|
234 241 # Full diff of changeset 4
235 242 get :diff, :id => PRJ_ID, :rev => r1
236 243 assert_response :success
237 244 assert_template 'diff'
238 245 if @diff_c_support
239 246 # Line 22 removed
240 247 assert_tag :tag => 'th',
241 248 :content => '22',
242 249 :sibling => { :tag => 'td',
243 250 :attributes => { :class => /diff_out/ },
244 251 :content => /def remove/ }
245 252 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
246 253 end
247 254 end
248 255 end
249 256
250 257 def test_diff_two_revs
251 258 @repository.fetch_changesets
252 259 @repository.reload
253 260 [2, '400bb8672109', '400', 400].each do |r1|
254 261 [4, 'def6d2f1254a'].each do |r2|
255 262 get :diff, :id => PRJ_ID, :rev => r1,
256 263 :rev_to => r2
257 264 assert_response :success
258 265 assert_template 'diff'
259 266
260 267 diff = assigns(:diff)
261 268 assert_not_nil diff
262 269 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
263 270 end
264 271 end
265 272 end
266 273
267 274 def test_diff_latin_1
268 275 [21, 'adf805632193'].each do |r1|
269 276 get :diff, :id => PRJ_ID, :rev => r1
270 277 assert_response :success
271 278 assert_template 'diff'
272 279 assert_tag :tag => 'th',
273 280 :content => '2',
274 281 :sibling => { :tag => 'td',
275 282 :attributes => { :class => /diff_in/ },
276 283 :content => /It is written in Python/ }
277 284 end
278 285 end
279 286
280 287 def test_annotate
281 288 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
282 289 assert_response :success
283 290 assert_template 'annotate'
284 291 # Line 23, revision 4:def6d2f1254a
285 292 assert_tag :tag => 'th',
286 293 :content => '23',
287 294 :attributes => { :class => 'line-num' },
288 295 :sibling =>
289 296 {
290 297 :tag => 'td',
291 298 :attributes => { :class => 'revision' },
292 299 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
293 300 }
294 301 assert_tag :tag => 'th',
295 302 :content => '23',
296 303 :attributes => { :class => 'line-num' },
297 304 :sibling =>
298 305 {
299 306 :tag => 'td' ,
300 307 :content => 'jsmith' ,
301 308 :attributes => { :class => 'author' },
302 309 }
303 310 assert_tag :tag => 'th',
304 311 :content => '23',
305 312 :attributes => { :class => 'line-num' },
306 313 :sibling => { :tag => 'td', :content => /watcher =/ }
307 314 end
308 315
309 316 def test_annotate_at_given_revision
310 317 @repository.fetch_changesets
311 318 @repository.reload
312 319 [2, '400bb8672109', '400', 400].each do |r1|
313 320 get :annotate, :id => PRJ_ID, :rev => r1, :path => ['sources', 'watchers_controller.rb']
314 321 assert_response :success
315 322 assert_template 'annotate'
316 323 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
317 324 end
318 325 end
319 326
320 327 def test_annotate_latin_1
321 328 [21, '21', 'adf805632193'].each do |r1|
322 329 get :annotate, :id => PRJ_ID, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
323 330 assert_response :success
324 331 assert_template 'annotate'
325 332 assert_tag :tag => 'th',
326 333 :content => '1',
327 334 :attributes => { :class => 'line-num' },
328 335 :sibling =>
329 336 {
330 337 :tag => 'td',
331 338 :attributes => { :class => 'revision' },
332 339 :child => { :tag => 'a', :content => '20:709858aafd1b' }
333 340 }
334 341 assert_tag :tag => 'th',
335 342 :content => '1',
336 343 :attributes => { :class => 'line-num' },
337 344 :sibling =>
338 345 {
339 346 :tag => 'td' ,
340 347 :content => 'jsmith' ,
341 348 :attributes => { :class => 'author' },
342 349
343 350 }
344 351 assert_tag :tag => 'th',
345 352 :content => '1',
346 353 :attributes => { :class => 'line-num' },
347 354 :sibling => { :tag => 'td',
348 355 :content => /Mercurial is a distributed version control system/ }
349 356
350 357 end
351 358 end
352 359
353 360 def test_empty_revision
354 361 @repository.fetch_changesets
355 362 @repository.reload
356 363 ['', ' ', nil].each do |r|
357 364 get :revision, :id => PRJ_ID, :rev => r
358 365 assert_response 404
359 366 assert_error_tag :content => /was not found/
360 367 end
361 368 end
362 369 else
363 370 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
364 371 def test_fake; assert true end
365 372 end
366 373 end
General Comments 0
You need to be logged in to leave comments. Login now