2019-03-16 15:03:47 +00:00
# frozen_string_literal: true
2019-03-15 01:32:57 +00:00
2013-11-22 22:57:30 +00:00
# Redmine - project management software
2024-02-26 22:55:54 +00:00
# Copyright (C) 2006- Jean-Philippe Lang
2013-11-22 22:57:30 +00:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2023-01-01 07:13:39 +00:00
require_relative '../../test_helper'
2013-11-22 22:57:30 +00:00
class Redmine :: ApiTest :: ApiTest < Redmine :: ApiTest :: Base
2017-03-21 11:29:56 +00:00
fixtures :users , :email_addresses , :members , :member_roles , :roles , :projects
2013-11-22 22:57:30 +00:00
def test_api_should_work_with_protect_from_forgery
ActionController :: Base . allow_forgery_protection = true
assert_difference ( 'User.count' ) do
2019-11-09 16:04:53 +00:00
post (
'/users.xml' ,
2017-06-01 18:17:27 +00:00
:params = > {
:user = > {
:login = > 'foo' , :firstname = > 'Firstname' , :lastname = > 'Lastname' ,
2020-12-02 13:32:02 +00:00
:mail = > 'foo@example.net' , :password = > 'secret123'
}
} ,
:headers = > credentials ( 'admin' )
)
2024-05-18 05:56:55 +00:00
assert_response :created
2013-11-22 22:57:30 +00:00
end
ensure
ActionController :: Base . allow_forgery_protection = false
end
2015-03-15 09:49:35 +00:00
def test_json_datetime_format
2017-06-01 18:17:27 +00:00
get '/users/1.json' , :headers = > credentials ( 'admin' )
2019-06-08 06:44:20 +00:00
assert_include %Q|"created_on":"#{Time.zone.parse('2006-07-19T17:12:21Z').iso8601}"| , response . body
2015-03-15 09:49:35 +00:00
end
def test_xml_datetime_format
2017-06-01 18:17:27 +00:00
get '/users/1.xml' , :headers = > credentials ( 'admin' )
2019-06-08 06:44:20 +00:00
assert_include " <created_on> #{ Time . zone . parse ( '2006-07-19T17:12:21Z' ) . iso8601 } </created_on> " , response . body
2015-03-15 09:49:35 +00:00
end
2016-07-21 20:49:14 +00:00
def test_head_response_should_have_empty_body
2017-06-01 18:17:27 +00:00
put '/users/7.xml' , :params = > { :user = > { :login = > 'foo' } } , :headers = > credentials ( 'admin' )
2016-07-21 20:49:14 +00:00
2019-02-05 08:33:29 +00:00
assert_response :no_content
2016-10-04 20:31:32 +00:00
assert_equal '' , response . body
2016-07-21 20:49:14 +00:00
end
2022-01-30 13:39:55 +00:00
def test_api_with_invalid_format_should_return_406
get '/users/1' , :headers = > credentials ( 'admin' ) . merge ( { 'Accept' = > 'application/xml' , 'Content-type' = > 'application/xml' } )
assert_response :not_acceptable
assert_equal " We couldn't handle your request, sorry. If you were trying to access the API, make sure to append .json or .xml to your request URL. \n " , response . body
end
2015-03-15 09:49:35 +00:00
end