annotate .svn/pristine/69/691cb013234fff89bbec068a998908bf8831df85.svn-base @ 1516:b450a9d58aed redmine-2.4

Update to Redmine SVN revision 13356 on 2.4-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:28:31 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
Chris@1494 21 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
Chris@1494 22 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
Chris@1494 23 :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories
Chris@1494 24
Chris@1494 25 def setup
Chris@1494 26 Setting.rest_api_enabled = '1'
Chris@1494 27 set_tmp_attachments_directory
Chris@1494 28 end
Chris@1494 29
Chris@1494 30 # TODO: A private project is needed because should_allow_api_authentication
Chris@1494 31 # actually tests that authentication is *required*, not just allowed
Chris@1494 32 should_allow_api_authentication(:get, "/projects/2.xml")
Chris@1494 33 should_allow_api_authentication(:get, "/projects/2.json")
Chris@1494 34 should_allow_api_authentication(:post,
Chris@1494 35 '/projects.xml',
Chris@1494 36 {:project => {:name => 'API test', :identifier => 'api-test'}},
Chris@1494 37 {:success_code => :created})
Chris@1494 38 should_allow_api_authentication(:put,
Chris@1494 39 '/projects/2.xml',
Chris@1494 40 {:project => {:name => 'API update'}},
Chris@1494 41 {:success_code => :ok})
Chris@1494 42 should_allow_api_authentication(:delete,
Chris@1494 43 '/projects/2.xml',
Chris@1494 44 {},
Chris@1494 45 {:success_code => :ok})
Chris@1494 46
Chris@1494 47 test "GET /projects.xml should return projects" do
Chris@1494 48 get '/projects.xml'
Chris@1494 49 assert_response :success
Chris@1494 50 assert_equal 'application/xml', @response.content_type
Chris@1494 51
Chris@1494 52 assert_tag :tag => 'projects',
Chris@1494 53 :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
Chris@1494 54 end
Chris@1494 55
Chris@1494 56 test "GET /projects.json should return projects" do
Chris@1494 57 get '/projects.json'
Chris@1494 58 assert_response :success
Chris@1494 59 assert_equal 'application/json', @response.content_type
Chris@1494 60
Chris@1494 61 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 62 assert_kind_of Hash, json
Chris@1494 63 assert_kind_of Array, json['projects']
Chris@1494 64 assert_kind_of Hash, json['projects'].first
Chris@1494 65 assert json['projects'].first.has_key?('id')
Chris@1494 66 end
Chris@1494 67
Chris@1494 68 test "GET /projects/:id.xml should return the project" do
Chris@1494 69 get '/projects/1.xml'
Chris@1494 70 assert_response :success
Chris@1494 71 assert_equal 'application/xml', @response.content_type
Chris@1494 72
Chris@1494 73 assert_tag :tag => 'project',
Chris@1494 74 :child => {:tag => 'id', :content => '1'}
Chris@1494 75 assert_tag :tag => 'custom_field',
Chris@1494 76 :attributes => {:name => 'Development status'}, :content => 'Stable'
Chris@1494 77
Chris@1494 78 assert_no_tag 'trackers'
Chris@1494 79 assert_no_tag 'issue_categories'
Chris@1494 80 end
Chris@1494 81
Chris@1494 82 test "GET /projects/:id.json should return the project" do
Chris@1494 83 get '/projects/1.json'
Chris@1494 84
Chris@1494 85 json = ActiveSupport::JSON.decode(response.body)
Chris@1494 86 assert_kind_of Hash, json
Chris@1494 87 assert_kind_of Hash, json['project']
Chris@1494 88 assert_equal 1, json['project']['id']
Chris@1494 89 end
Chris@1494 90
Chris@1494 91 test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
Chris@1494 92 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
Chris@1494 93
Chris@1494 94 get '/projects/1.xml'
Chris@1494 95 assert_response :success
Chris@1494 96 assert_equal 'application/xml', @response.content_type
Chris@1494 97
Chris@1494 98 assert_no_tag 'custom_field',
Chris@1494 99 :attributes => {:name => 'Development status'}
Chris@1494 100 end
Chris@1494 101
Chris@1494 102 test "GET /projects/:id.xml with include=issue_categories should return categories" do
Chris@1494 103 get '/projects/1.xml?include=issue_categories'
Chris@1494 104 assert_response :success
Chris@1494 105 assert_equal 'application/xml', @response.content_type
Chris@1494 106
Chris@1494 107 assert_tag 'issue_categories',
Chris@1494 108 :attributes => {:type => 'array'},
Chris@1494 109 :child => {
Chris@1494 110 :tag => 'issue_category',
Chris@1494 111 :attributes => {
Chris@1494 112 :id => '2',
Chris@1494 113 :name => 'Recipes'
Chris@1494 114 }
Chris@1494 115 }
Chris@1494 116 end
Chris@1494 117
Chris@1494 118 test "GET /projects/:id.xml with include=trackers should return trackers" do
Chris@1494 119 get '/projects/1.xml?include=trackers'
Chris@1494 120 assert_response :success
Chris@1494 121 assert_equal 'application/xml', @response.content_type
Chris@1494 122
Chris@1494 123 assert_tag 'trackers',
Chris@1494 124 :attributes => {:type => 'array'},
Chris@1494 125 :child => {
Chris@1494 126 :tag => 'tracker',
Chris@1494 127 :attributes => {
Chris@1494 128 :id => '2',
Chris@1494 129 :name => 'Feature request'
Chris@1494 130 }
Chris@1494 131 }
Chris@1494 132 end
Chris@1494 133
Chris@1494 134 test "POST /projects.xml with valid parameters should create the project" do
Chris@1494 135 Setting.default_projects_modules = ['issue_tracking', 'repository']
Chris@1494 136
Chris@1494 137 assert_difference('Project.count') do
Chris@1494 138 post '/projects.xml',
Chris@1494 139 {:project => {:name => 'API test', :identifier => 'api-test'}},
Chris@1494 140 credentials('admin')
Chris@1494 141 end
Chris@1494 142
Chris@1494 143 project = Project.first(:order => 'id DESC')
Chris@1494 144 assert_equal 'API test', project.name
Chris@1494 145 assert_equal 'api-test', project.identifier
Chris@1494 146 assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
Chris@1494 147 assert_equal Tracker.all.size, project.trackers.size
Chris@1494 148
Chris@1494 149 assert_response :created
Chris@1494 150 assert_equal 'application/xml', @response.content_type
Chris@1494 151 assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
Chris@1494 152 end
Chris@1494 153
Chris@1494 154 test "POST /projects.xml should accept enabled_module_names attribute" do
Chris@1494 155 assert_difference('Project.count') do
Chris@1494 156 post '/projects.xml',
Chris@1494 157 {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
Chris@1494 158 credentials('admin')
Chris@1494 159 end
Chris@1494 160
Chris@1494 161 project = Project.first(:order => 'id DESC')
Chris@1494 162 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
Chris@1494 163 end
Chris@1494 164
Chris@1494 165 test "POST /projects.xml should accept tracker_ids attribute" do
Chris@1494 166 assert_difference('Project.count') do
Chris@1494 167 post '/projects.xml',
Chris@1494 168 {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
Chris@1494 169 credentials('admin')
Chris@1494 170 end
Chris@1494 171
Chris@1494 172 project = Project.first(:order => 'id DESC')
Chris@1494 173 assert_equal [1, 3], project.trackers.map(&:id).sort
Chris@1494 174 end
Chris@1494 175
Chris@1494 176 test "POST /projects.xml with invalid parameters should return errors" do
Chris@1494 177 assert_no_difference('Project.count') do
Chris@1494 178 post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin')
Chris@1494 179 end
Chris@1494 180
Chris@1494 181 assert_response :unprocessable_entity
Chris@1494 182 assert_equal 'application/xml', @response.content_type
Chris@1494 183 assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
Chris@1494 184 end
Chris@1494 185
Chris@1494 186 test "PUT /projects/:id.xml with valid parameters should update the project" do
Chris@1494 187 assert_no_difference 'Project.count' do
Chris@1494 188 put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith')
Chris@1494 189 end
Chris@1494 190 assert_response :ok
Chris@1494 191 assert_equal '', @response.body
Chris@1494 192 assert_equal 'application/xml', @response.content_type
Chris@1494 193 project = Project.find(2)
Chris@1494 194 assert_equal 'API update', project.name
Chris@1494 195 end
Chris@1494 196
Chris@1494 197 test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
Chris@1494 198 assert_no_difference 'Project.count' do
Chris@1494 199 put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin')
Chris@1494 200 end
Chris@1494 201 assert_response :ok
Chris@1494 202 assert_equal '', @response.body
Chris@1494 203 project = Project.find(2)
Chris@1494 204 assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
Chris@1494 205 end
Chris@1494 206
Chris@1494 207 test "PUT /projects/:id.xml should accept tracker_ids attribute" do
Chris@1494 208 assert_no_difference 'Project.count' do
Chris@1494 209 put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin')
Chris@1494 210 end
Chris@1494 211 assert_response :ok
Chris@1494 212 assert_equal '', @response.body
Chris@1494 213 project = Project.find(2)
Chris@1494 214 assert_equal [1, 3], project.trackers.map(&:id).sort
Chris@1494 215 end
Chris@1494 216
Chris@1494 217 test "PUT /projects/:id.xml with invalid parameters should return errors" do
Chris@1494 218 assert_no_difference('Project.count') do
Chris@1494 219 put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin')
Chris@1494 220 end
Chris@1494 221
Chris@1494 222 assert_response :unprocessable_entity
Chris@1494 223 assert_equal 'application/xml', @response.content_type
Chris@1494 224 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
Chris@1494 225 end
Chris@1494 226
Chris@1494 227 test "DELETE /projects/:id.xml should delete the project" do
Chris@1494 228 assert_difference('Project.count',-1) do
Chris@1494 229 delete '/projects/2.xml', {}, credentials('admin')
Chris@1494 230 end
Chris@1494 231 assert_response :ok
Chris@1494 232 assert_equal '', @response.body
Chris@1494 233 assert_nil Project.find_by_id(2)
Chris@1494 234 end
Chris@1494 235 end