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