@@ -1,92 +1,95 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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 | require 'sys_controller' |
|
19 | require 'sys_controller' | |
|
20 | require 'mocha' | |||
20 |
|
21 | |||
21 | # Re-raise errors caught by the controller. |
|
22 | # Re-raise errors caught by the controller. | |
22 | class SysController; def rescue_action(e) raise e end; end |
|
23 | class SysController; def rescue_action(e) raise e end; end | |
23 |
|
24 | |||
24 | class SysControllerTest < ActionController::TestCase |
|
25 | class SysControllerTest < ActionController::TestCase | |
25 | fixtures :projects, :repositories |
|
26 | fixtures :projects, :repositories, :enabled_modules | |
26 |
|
27 | |||
27 | def setup |
|
28 | def setup | |
28 | @controller = SysController.new |
|
29 | @controller = SysController.new | |
29 | @request = ActionController::TestRequest.new |
|
30 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
31 | @response = ActionController::TestResponse.new | |
31 | Setting.sys_api_enabled = '1' |
|
32 | Setting.sys_api_enabled = '1' | |
32 | Setting.enabled_scm = %w(Subversion Git) |
|
33 | Setting.enabled_scm = %w(Subversion Git) | |
33 | end |
|
34 | end | |
34 |
|
35 | |||
35 | def test_projects_with_repository_enabled |
|
36 | def test_projects_with_repository_enabled | |
36 | get :projects |
|
37 | get :projects | |
37 | assert_response :success |
|
38 | assert_response :success | |
38 | assert_equal 'application/xml', @response.content_type |
|
39 | assert_equal 'application/xml', @response.content_type | |
39 | with_options :tag => 'projects' do |test| |
|
40 | with_options :tag => 'projects' do |test| | |
40 | test.assert_tag :children => { :count => Project.active.has_module(:repository).count } |
|
41 | test.assert_tag :children => { :count => Project.active.has_module(:repository).count } | |
41 | end |
|
42 | end | |
42 | end |
|
43 | end | |
43 |
|
44 | |||
44 | def test_create_project_repository |
|
45 | def test_create_project_repository | |
45 | assert_nil Project.find(4).repository |
|
46 | assert_nil Project.find(4).repository | |
46 |
|
47 | |||
47 | post :create_project_repository, :id => 4, |
|
48 | post :create_project_repository, :id => 4, | |
48 | :vendor => 'Subversion', |
|
49 | :vendor => 'Subversion', | |
49 | :repository => { :url => 'file:///create/project/repository/subproject2'} |
|
50 | :repository => { :url => 'file:///create/project/repository/subproject2'} | |
50 | assert_response :created |
|
51 | assert_response :created | |
51 |
|
52 | |||
52 | r = Project.find(4).repository |
|
53 | r = Project.find(4).repository | |
53 | assert r.is_a?(Repository::Subversion) |
|
54 | assert r.is_a?(Repository::Subversion) | |
54 | assert_equal 'file:///create/project/repository/subproject2', r.url |
|
55 | assert_equal 'file:///create/project/repository/subproject2', r.url | |
55 | end |
|
56 | end | |
56 |
|
57 | |||
57 | def test_fetch_changesets |
|
58 | def test_fetch_changesets | |
|
59 | Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true) | |||
58 | get :fetch_changesets |
|
60 | get :fetch_changesets | |
59 | assert_response :success |
|
61 | assert_response :success | |
60 | end |
|
62 | end | |
61 |
|
63 | |||
62 | def test_fetch_changesets_one_project |
|
64 | def test_fetch_changesets_one_project | |
|
65 | Repository::Subversion.any_instance.expects(:fetch_changesets).returns(true) | |||
63 | get :fetch_changesets, :id => 'ecookbook' |
|
66 | get :fetch_changesets, :id => 'ecookbook' | |
64 | assert_response :success |
|
67 | assert_response :success | |
65 | end |
|
68 | end | |
66 |
|
69 | |||
67 | def test_fetch_changesets_unknown_project |
|
70 | def test_fetch_changesets_unknown_project | |
68 | get :fetch_changesets, :id => 'unknown' |
|
71 | get :fetch_changesets, :id => 'unknown' | |
69 | assert_response 404 |
|
72 | assert_response 404 | |
70 | end |
|
73 | end | |
71 |
|
74 | |||
72 | def test_disabled_ws_should_respond_with_403_error |
|
75 | def test_disabled_ws_should_respond_with_403_error | |
73 | with_settings :sys_api_enabled => '0' do |
|
76 | with_settings :sys_api_enabled => '0' do | |
74 | get :projects |
|
77 | get :projects | |
75 | assert_response 403 |
|
78 | assert_response 403 | |
76 | end |
|
79 | end | |
77 | end |
|
80 | end | |
78 |
|
81 | |||
79 | def test_api_key |
|
82 | def test_api_key | |
80 | with_settings :sys_api_key => 'my_secret_key' do |
|
83 | with_settings :sys_api_key => 'my_secret_key' do | |
81 | get :projects, :key => 'my_secret_key' |
|
84 | get :projects, :key => 'my_secret_key' | |
82 | assert_response :success |
|
85 | assert_response :success | |
83 | end |
|
86 | end | |
84 | end |
|
87 | end | |
85 |
|
88 | |||
86 | def test_wrong_key_should_respond_with_403_error |
|
89 | def test_wrong_key_should_respond_with_403_error | |
87 | with_settings :sys_api_enabled => 'my_secret_key' do |
|
90 | with_settings :sys_api_enabled => 'my_secret_key' do | |
88 | get :projects, :key => 'wrong_key' |
|
91 | get :projects, :key => 'wrong_key' | |
89 | assert_response 403 |
|
92 | assert_response 403 | |
90 | end |
|
93 | end | |
91 | end |
|
94 | end | |
92 | end |
|
95 | end |
General Comments 0
You need to be logged in to leave comments.
Login now