You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sys_controller_test.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. require File.expand_path('../../test_helper', __FILE__)
  18. class SysControllerTest < ActionController::TestCase
  19. fixtures :projects, :repositories, :enabled_modules
  20. def setup
  21. Setting.sys_api_enabled = '1'
  22. Setting.enabled_scm = %w(Subversion Git)
  23. end
  24. def teardown
  25. Setting.clear_cache
  26. end
  27. def test_projects_with_repository_enabled
  28. get :projects
  29. assert_response :success
  30. assert_equal 'application/xml', @response.content_type
  31. with_options :tag => 'projects' do |test|
  32. test.assert_tag :children => { :count => Project.active.has_module(:repository).count }
  33. test.assert_tag 'project', :child => {:tag => 'identifier', :sibling => {:tag => 'is-public'}}
  34. end
  35. assert_no_tag 'extra-info'
  36. assert_no_tag 'extra_info'
  37. end
  38. def test_create_project_repository
  39. assert_nil Project.find(4).repository
  40. post :create_project_repository, :id => 4,
  41. :vendor => 'Subversion',
  42. :repository => { :url => 'file:///create/project/repository/subproject2'}
  43. assert_response :created
  44. assert_equal 'application/xml', @response.content_type
  45. r = Project.find(4).repository
  46. assert r.is_a?(Repository::Subversion)
  47. assert_equal 'file:///create/project/repository/subproject2', r.url
  48. assert_tag 'repository-subversion',
  49. :child => {
  50. :tag => 'id', :content => r.id.to_s,
  51. :sibling => {:tag => 'url', :content => r.url}
  52. }
  53. assert_no_tag 'extra-info'
  54. assert_no_tag 'extra_info'
  55. end
  56. def test_create_already_existing
  57. post :create_project_repository, :id => 1,
  58. :vendor => 'Subversion',
  59. :repository => { :url => 'file:///create/project/repository/subproject2'}
  60. assert_response :conflict
  61. end
  62. def test_create_with_failure
  63. post :create_project_repository, :id => 4,
  64. :vendor => 'Subversion',
  65. :repository => { :url => 'invalid url'}
  66. assert_response :unprocessable_entity
  67. end
  68. def test_fetch_changesets
  69. Repository::Subversion.any_instance.expects(:fetch_changesets).twice.returns(true)
  70. get :fetch_changesets
  71. assert_response :success
  72. end
  73. def test_fetch_changesets_one_project_by_identifier
  74. Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
  75. get :fetch_changesets, :id => 'ecookbook'
  76. assert_response :success
  77. end
  78. def test_fetch_changesets_one_project_by_id
  79. Repository::Subversion.any_instance.expects(:fetch_changesets).once.returns(true)
  80. get :fetch_changesets, :id => '1'
  81. assert_response :success
  82. end
  83. def test_fetch_changesets_unknown_project
  84. get :fetch_changesets, :id => 'unknown'
  85. assert_response 404
  86. end
  87. def test_disabled_ws_should_respond_with_403_error
  88. with_settings :sys_api_enabled => '0' do
  89. get :projects
  90. assert_response 403
  91. end
  92. end
  93. def test_api_key
  94. with_settings :sys_api_key => 'my_secret_key' do
  95. get :projects, :key => 'my_secret_key'
  96. assert_response :success
  97. end
  98. end
  99. def test_wrong_key_should_respond_with_403_error
  100. with_settings :sys_api_enabled => 'my_secret_key' do
  101. get :projects, :key => 'wrong_key'
  102. assert_response 403
  103. end
  104. end
  105. end