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