@@ -47,7 +47,7 class ActiveSupport::TestCase | |||||
47 | self.use_instantiated_fixtures = false |
|
47 | self.use_instantiated_fixtures = false | |
48 |
|
48 | |||
49 | # Add more helper methods to be used by all tests here... |
|
49 | # Add more helper methods to be used by all tests here... | |
50 |
|
50 | |||
51 | def log_user(login, password) |
|
51 | def log_user(login, password) | |
52 | User.anonymous |
|
52 | User.anonymous | |
53 | get "/login" |
|
53 | get "/login" | |
@@ -57,7 +57,7 class ActiveSupport::TestCase | |||||
57 | post "/login", :username => login, :password => password |
|
57 | post "/login", :username => login, :password => password | |
58 | assert_equal login, User.find(session[:user_id]).login |
|
58 | assert_equal login, User.find(session[:user_id]).login | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def uploaded_test_file(name, mime) |
|
61 | def uploaded_test_file(name, mime) | |
62 | ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime, true) |
|
62 | ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime, true) | |
63 | end |
|
63 | end | |
@@ -127,7 +127,7 class ActiveSupport::TestCase | |||||
127 | def assert_error_tag(options={}) |
|
127 | def assert_error_tag(options={}) | |
128 | assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options)) |
|
128 | assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options)) | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def assert_include(expected, s) |
|
131 | def assert_include(expected, s) | |
132 | assert s.include?(expected), "\"#{expected}\" not found in \"#{s}\"" |
|
132 | assert s.include?(expected), "\"#{expected}\" not found in \"#{s}\"" | |
133 | end |
|
133 | end | |
@@ -176,7 +176,7 class ActiveSupport::TestCase | |||||
176 | :old_value => @old_value.id, |
|
176 | :old_value => @old_value.id, | |
177 | :value => @new_value.id, |
|
177 | :value => @new_value.id, | |
178 | :prop_key => prop_key) |
|
178 | :prop_key => prop_key) | |
179 |
|
179 | |||
180 | assert_match @new_value.name, show_detail(@detail, true) |
|
180 | assert_match @new_value.name, show_detail(@detail, true) | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
@@ -185,7 +185,7 class ActiveSupport::TestCase | |||||
185 | :old_value => @old_value.id, |
|
185 | :old_value => @old_value.id, | |
186 | :value => @new_value.id, |
|
186 | :value => @new_value.id, | |
187 | :prop_key => prop_key) |
|
187 | :prop_key => prop_key) | |
188 |
|
188 | |||
189 | assert_match @old_value.name, show_detail(@detail, true) |
|
189 | assert_match @old_value.name, show_detail(@detail, true) | |
190 | end |
|
190 | end | |
191 | end |
|
191 | end | |
@@ -229,7 +229,7 class ActiveSupport::TestCase | |||||
229 | def self.should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters={}, options={}) |
|
229 | def self.should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters={}, options={}) | |
230 | success_code = options[:success_code] || :success |
|
230 | success_code = options[:success_code] || :success | |
231 | failure_code = options[:failure_code] || :unauthorized |
|
231 | failure_code = options[:failure_code] || :unauthorized | |
232 |
|
232 | |||
233 | context "should allow http basic auth using a username and password for #{http_method} #{url}" do |
|
233 | context "should allow http basic auth using a username and password for #{http_method} #{url}" do | |
234 | context "with a valid HTTP authentication" do |
|
234 | context "with a valid HTTP authentication" do | |
235 | setup do |
|
235 | setup do | |
@@ -237,7 +237,7 class ActiveSupport::TestCase | |||||
237 | @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') |
|
237 | @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') | |
238 | send(http_method, url, parameters, {:authorization => @authorization}) |
|
238 | send(http_method, url, parameters, {:authorization => @authorization}) | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | should_respond_with success_code |
|
241 | should_respond_with success_code | |
242 | should_respond_with_content_type_based_on_url(url) |
|
242 | should_respond_with_content_type_based_on_url(url) | |
243 | should "login as the user" do |
|
243 | should "login as the user" do | |
@@ -251,14 +251,14 class ActiveSupport::TestCase | |||||
251 | @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'wrong_password') |
|
251 | @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'wrong_password') | |
252 | send(http_method, url, parameters, {:authorization => @authorization}) |
|
252 | send(http_method, url, parameters, {:authorization => @authorization}) | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | should_respond_with failure_code |
|
255 | should_respond_with failure_code | |
256 | should_respond_with_content_type_based_on_url(url) |
|
256 | should_respond_with_content_type_based_on_url(url) | |
257 | should "not login as the user" do |
|
257 | should "not login as the user" do | |
258 | assert_equal User.anonymous, User.current |
|
258 | assert_equal User.anonymous, User.current | |
259 | end |
|
259 | end | |
260 | end |
|
260 | end | |
261 |
|
261 | |||
262 | context "without credentials" do |
|
262 | context "without credentials" do | |
263 | setup do |
|
263 | setup do | |
264 | send(http_method, url, parameters, {:authorization => ''}) |
|
264 | send(http_method, url, parameters, {:authorization => ''}) | |
@@ -294,7 +294,7 class ActiveSupport::TestCase | |||||
294 | @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X') |
|
294 | @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X') | |
295 | send(http_method, url, parameters, {:authorization => @authorization}) |
|
295 | send(http_method, url, parameters, {:authorization => @authorization}) | |
296 | end |
|
296 | end | |
297 |
|
297 | |||
298 | should_respond_with success_code |
|
298 | should_respond_with success_code | |
299 | should_respond_with_content_type_based_on_url(url) |
|
299 | should_respond_with_content_type_based_on_url(url) | |
300 | should_be_a_valid_response_string_based_on_url(url) |
|
300 | should_be_a_valid_response_string_based_on_url(url) | |
@@ -319,7 +319,7 class ActiveSupport::TestCase | |||||
319 | end |
|
319 | end | |
320 | end |
|
320 | end | |
321 | end |
|
321 | end | |
322 |
|
322 | |||
323 | # Test that a request allows full key authentication |
|
323 | # Test that a request allows full key authentication | |
324 | # |
|
324 | # | |
325 | # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete) |
|
325 | # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete) | |
@@ -345,7 +345,7 class ActiveSupport::TestCase | |||||
345 | end |
|
345 | end | |
346 | send(http_method, request_url, parameters) |
|
346 | send(http_method, request_url, parameters) | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | should_respond_with success_code |
|
349 | should_respond_with success_code | |
350 | should_respond_with_content_type_based_on_url(url) |
|
350 | should_respond_with_content_type_based_on_url(url) | |
351 | should_be_a_valid_response_string_based_on_url(url) |
|
351 | should_be_a_valid_response_string_based_on_url(url) | |
@@ -366,7 +366,7 class ActiveSupport::TestCase | |||||
366 | end |
|
366 | end | |
367 | send(http_method, request_url, parameters) |
|
367 | send(http_method, request_url, parameters) | |
368 | end |
|
368 | end | |
369 |
|
369 | |||
370 | should_respond_with failure_code |
|
370 | should_respond_with failure_code | |
371 | should_respond_with_content_type_based_on_url(url) |
|
371 | should_respond_with_content_type_based_on_url(url) | |
372 | should "not login as the user" do |
|
372 | should "not login as the user" do | |
@@ -374,14 +374,14 class ActiveSupport::TestCase | |||||
374 | end |
|
374 | end | |
375 | end |
|
375 | end | |
376 | end |
|
376 | end | |
377 |
|
377 | |||
378 | context "should allow key based auth using X-Redmine-API-Key header for #{http_method} #{url}" do |
|
378 | context "should allow key based auth using X-Redmine-API-Key header for #{http_method} #{url}" do | |
379 | setup do |
|
379 | setup do | |
380 | @user = User.generate_with_protected!(:admin => true) |
|
380 | @user = User.generate_with_protected!(:admin => true) | |
381 | @token = Token.generate!(:user => @user, :action => 'api') |
|
381 | @token = Token.generate!(:user => @user, :action => 'api') | |
382 | send(http_method, url, parameters, {'X-Redmine-API-Key' => @token.value.to_s}) |
|
382 | send(http_method, url, parameters, {'X-Redmine-API-Key' => @token.value.to_s}) | |
383 | end |
|
383 | end | |
384 |
|
384 | |||
385 | should_respond_with success_code |
|
385 | should_respond_with success_code | |
386 | should_respond_with_content_type_based_on_url(url) |
|
386 | should_respond_with_content_type_based_on_url(url) | |
387 | should_be_a_valid_response_string_based_on_url(url) |
|
387 | should_be_a_valid_response_string_based_on_url(url) | |
@@ -406,7 +406,7 class ActiveSupport::TestCase | |||||
406 | else |
|
406 | else | |
407 | raise "Unknown content type for should_respond_with_content_type_based_on_url: #{url}" |
|
407 | raise "Unknown content type for should_respond_with_content_type_based_on_url: #{url}" | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | end |
|
410 | end | |
411 |
|
411 | |||
412 | # Uses the url to assert which format the response should be in |
|
412 | # Uses the url to assert which format the response should be in | |
@@ -424,9 +424,9 class ActiveSupport::TestCase | |||||
424 | else |
|
424 | else | |
425 | raise "Unknown content type for should_be_a_valid_response_based_on_url: #{url}" |
|
425 | raise "Unknown content type for should_be_a_valid_response_based_on_url: #{url}" | |
426 | end |
|
426 | end | |
427 |
|
427 | |||
428 | end |
|
428 | end | |
429 |
|
429 | |||
430 | # Checks that the response is a valid JSON string |
|
430 | # Checks that the response is a valid JSON string | |
431 | def self.should_be_a_valid_json_string |
|
431 | def self.should_be_a_valid_json_string | |
432 | should "be a valid JSON string (or empty)" do |
|
432 | should "be a valid JSON string (or empty)" do | |
@@ -440,7 +440,7 class ActiveSupport::TestCase | |||||
440 | assert REXML::Document.new(response.body) |
|
440 | assert REXML::Document.new(response.body) | |
441 | end |
|
441 | end | |
442 | end |
|
442 | end | |
443 |
|
443 | |||
444 | end |
|
444 | end | |
445 |
|
445 | |||
446 | # Simple module to "namespace" all of the API tests |
|
446 | # Simple module to "namespace" all of the API tests |
General Comments 0
You need to be logged in to leave comments.
Login now