REST API Unit tests
This commit is contained in:
parent
3889c4eb93
commit
efc9368b60
@ -50,7 +50,7 @@ class DmsfController < ApplicationController
|
|||||||
# also try to lookup folder by title if this is API call
|
# also try to lookup folder by title if this is API call
|
||||||
find_folder_by_title if [:xml, :json].include? request.format.to_sym
|
find_folder_by_title if [:xml, :json].include? request.format.to_sym
|
||||||
get_display_params
|
get_display_params
|
||||||
if @folder && @folder.deleted?
|
if (@folder && @folder.deleted?) || (params[:folder_title].present? && !@folder)
|
||||||
render_404
|
render_404
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@ -118,6 +118,7 @@ class DmsfUploadController < ApplicationController
|
|||||||
|
|
||||||
# REST API file commit
|
# REST API file commit
|
||||||
def commit
|
def commit
|
||||||
|
@files = []
|
||||||
attachments = params[:attachments]
|
attachments = params[:attachments]
|
||||||
if attachments && attachments.is_a?(Hash)
|
if attachments && attachments.is_a?(Hash)
|
||||||
@folder = DmsfFolder.visible.find_by_id attachments[:folder_id].to_i if attachments[:folder_id].present?
|
@folder = DmsfFolder.visible.find_by_id attachments[:folder_id].to_i if attachments[:folder_id].present?
|
||||||
@ -127,9 +128,9 @@ class DmsfUploadController < ApplicationController
|
|||||||
upload = DmsfUpload.create_from_uploaded_attachment(@project, @folder, uploaded_file)
|
upload = DmsfUpload.create_from_uploaded_attachment(@project, @folder, uploaded_file)
|
||||||
uploaded_file[:disk_filename] = upload.disk_filename
|
uploaded_file[:disk_filename] = upload.disk_filename
|
||||||
end
|
end
|
||||||
end
|
|
||||||
commit_files_internal uploaded_files
|
commit_files_internal uploaded_files
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete_dmsf_attachment
|
def delete_dmsf_attachment
|
||||||
attachment = Attachment.find(params[:id])
|
attachment = Attachment.find(params[:id])
|
||||||
@ -141,7 +142,7 @@ class DmsfUploadController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def commit_files_internal(commited_files)
|
def commit_files_internal(commited_files)
|
||||||
DmsfUploadHelper.commit_files_internal(commited_files, @project, @folder, self)
|
@files, failed_uploads = DmsfUploadHelper.commit_files_internal(commited_files, @project, @folder, self)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
format.api { render_validation_errors(failed_uploads) unless failed_uploads.empty? }
|
format.api { render_validation_errors(failed_uploads) unless failed_uploads.empty? }
|
||||||
|
|||||||
@ -22,13 +22,14 @@ module DmsfUploadHelper
|
|||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
|
|
||||||
def self.commit_files_internal(commited_files, container, folder, controller)
|
def self.commit_files_internal(commited_files, container, folder, controller)
|
||||||
|
failed_uploads = []
|
||||||
|
files = []
|
||||||
if container.is_a?(Project)
|
if container.is_a?(Project)
|
||||||
project = container
|
project = container
|
||||||
else
|
else
|
||||||
project = container.project
|
project = container.project
|
||||||
end
|
end
|
||||||
if commited_files && commited_files.is_a?(Hash)
|
if commited_files && commited_files.is_a?(Hash)
|
||||||
files = []
|
|
||||||
failed_uploads = []
|
failed_uploads = []
|
||||||
commited_files.each_value do |commited_file|
|
commited_files.each_value do |commited_file|
|
||||||
name = commited_file[:name]
|
name = commited_file[:name]
|
||||||
@ -136,9 +137,10 @@ module DmsfUploadHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
unless failed_uploads.empty?
|
if failed_uploads.present?
|
||||||
controller.flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', '))
|
controller.flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', '))
|
||||||
end
|
end
|
||||||
|
[files, failed_uploads]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
api.dmsf_file do
|
api.dmsf_file do
|
||||||
api.id @file.id
|
api.id @file.id
|
||||||
api.name @file.name
|
api.name @file.name
|
||||||
api.project_id @file.project_id
|
api.container_id @file.container_id
|
||||||
|
api.container_type @file.container_type
|
||||||
api.dmsf_folder_id @file.folder if @file.dmsf_folder_id
|
api.dmsf_folder_id @file.folder if @file.dmsf_folder_id
|
||||||
api.version "#{@file.last_revision.major_version}.#{@file.last_revision.minor_version}" if @file.last_revision
|
api.version "#{@file.last_revision.major_version}.#{@file.last_revision.minor_version}" if @file.last_revision
|
||||||
api.content_url url_for(:controller => :dmsf_files, :action => 'show', :download => '', :id => @file)
|
api.content_url url_for(:controller => :dmsf_files, :action => 'show', :download => '', :id => @file)
|
||||||
|
|||||||
@ -44,6 +44,7 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:
|
|||||||
|
|
||||||
# 5. list folder contents & check folder existence (by folder title)
|
# 5. list folder contents & check folder existence (by folder title)
|
||||||
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
|
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
|
||||||
|
|
||||||
# 6. list folder contents & check folder existence (by folder id)
|
# 6. list folder contents & check folder existence (by folder id)
|
||||||
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3
|
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3
|
||||||
# both returns 404 not found, or json with following structure:
|
# both returns 404 not found, or json with following structure:
|
||||||
@ -67,8 +68,7 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:
|
|||||||
#}
|
#}
|
||||||
|
|
||||||
# 7. update folder
|
# 7. update folder
|
||||||
# curl -v -H "Content-Type: application/json" -X POST --data "@update-folder-payload.json" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000//projects/#{project_id}/dmsf/save.json
|
# curl -v -H "Content-Type: application/json" -X POST --data "@update-folder-payload.json" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000//projects/#{project_id}/dmsf/save.json?folder_id=#{folder_id}
|
||||||
|
|
||||||
|
|
||||||
# update-folder-payload.json
|
# update-folder-payload.json
|
||||||
# {
|
# {
|
||||||
@ -76,5 +76,4 @@ curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:
|
|||||||
# "title": title,
|
# "title": title,
|
||||||
# "description": description
|
# "description": description
|
||||||
# },
|
# },
|
||||||
# "folder_id": id -- id of folder to be updated
|
|
||||||
# }
|
# }
|
||||||
125
test/integration/rest_api/dmsf_file_api_test.rb
Normal file
125
test/integration/rest_api/dmsf_file_api_test.rb
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Document Management System "Features"
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
|
class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
|
fixtures :projects, :users, :dmsf_files, :dmsf_file_revisions, :members, :roles
|
||||||
|
|
||||||
|
def setup
|
||||||
|
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||||
|
timestamp = DateTime.now.strftime("%y%m%d%H%M")
|
||||||
|
@tmp_storage_path = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||||
|
Dir.mkdir(@tmp_storage_path) unless File.directory?(@tmp_storage_path)
|
||||||
|
@jsmith = User.find_by_id 2
|
||||||
|
@file1 = DmsfFile.find_by_id 1
|
||||||
|
Setting.rest_api_enabled = '1'
|
||||||
|
@role = Role.find_by_id 1
|
||||||
|
@project1 = Project.find_by_id 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
# Delete our tmp folder
|
||||||
|
begin
|
||||||
|
FileUtils.rm_rf @tmp_storage_path
|
||||||
|
rescue Exception => e
|
||||||
|
error e.message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_truth
|
||||||
|
assert_kind_of User, @jsmith
|
||||||
|
assert_kind_of DmsfFile, @file1
|
||||||
|
assert_kind_of Role, @role
|
||||||
|
assert_kind_of Project, @project1
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_get_document
|
||||||
|
@role.add_permission! :view_dmsf_files
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml
|
||||||
|
get "/dmsf/files/#{@file1.id}.xml?key=#{token.value}"
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'application/xml', @response.content_type
|
||||||
|
#<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <dmsf_file>
|
||||||
|
# <id>1</id>
|
||||||
|
# <name>test.txt</name>
|
||||||
|
# <container_id>1</container_id>
|
||||||
|
# <container_type>Project</container_type>
|
||||||
|
# <version>1.0</version>
|
||||||
|
# <content_url>/dmsf/files/1/download</content_url>
|
||||||
|
# </dmsf_file>
|
||||||
|
assert_select 'dmsf_file > id', :text => @file1.id.to_s
|
||||||
|
assert_select 'dmsf_file > name', :text => @file1.name
|
||||||
|
assert_select 'dmsf_file > container_id', :text => @file1.container_id.to_s
|
||||||
|
assert_select 'dmsf_file > container_type', :text => @file1.container_type.to_s
|
||||||
|
assert_select 'dmsf_file > version', :text => "#{@file1.last_revision.major_version}.#{@file1.last_revision.minor_version}"
|
||||||
|
assert_select 'dmsf_file > content_url', :text => "/dmsf/files/#{@file1.id}/download"
|
||||||
|
#curl -v -H "Content-Type: application/octet-stream" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/41532/download > file.txt
|
||||||
|
get "/dmsf/files/#{@file1.id}/download?key=#{token.value}"
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_upload_document
|
||||||
|
DmsfFile.storage_path = @tmp_storage_path
|
||||||
|
@role.add_permission! :file_manipulation
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
#curl --data-binary "@cat.gif" -H "Content-Type: application/octet-stream" -X POST -u ${1}:${2} http://localhost:3000/projects/12/dmsf/upload.xml?filename=cat.gif
|
||||||
|
post "/projects/#{@project1.id}/dmsf/upload.xml?filename=test.txt&key=#{token.value}", 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}
|
||||||
|
assert_response :created
|
||||||
|
assert_equal 'application/xml', response.content_type
|
||||||
|
#<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <upload>
|
||||||
|
# <token>2.8bb2564936980e92ceec8a5759ec34a8</token>
|
||||||
|
# </upload>
|
||||||
|
xml = Hash.from_xml(response.body)
|
||||||
|
assert_kind_of Hash, xml['upload']
|
||||||
|
ftoken = xml['upload']['token']
|
||||||
|
assert_not_nil ftoken
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@file.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/commit.xml
|
||||||
|
payload = %{
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<attachments>
|
||||||
|
<folder_id/>
|
||||||
|
<uploaded_file>
|
||||||
|
<disk_filename>test.txt</disk_filename>
|
||||||
|
<name>test.txt</name>
|
||||||
|
<title>test.txt</title>
|
||||||
|
<description>REST API</description>
|
||||||
|
<comment>From API</comment>
|
||||||
|
<version/>
|
||||||
|
<token>#{ftoken}</token>
|
||||||
|
</uploaded_file>
|
||||||
|
</attachments>
|
||||||
|
}
|
||||||
|
post "/projects/#{@project1.id}/dmsf/commit.xml?&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'}
|
||||||
|
#<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
#<dmsf_files total_count="1" type="array">
|
||||||
|
# <file>
|
||||||
|
# <id>17229</id>
|
||||||
|
# <name>test.txt</name>
|
||||||
|
# </file>
|
||||||
|
# </dmsf_files>
|
||||||
|
assert_select 'dmsf_files > file > name', :text => 'test.txt'
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
194
test/integration/rest_api/dmsf_folder_api_test.rb
Normal file
194
test/integration/rest_api/dmsf_folder_api_test.rb
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Document Management System "Features"
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
|
class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
|
fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :projects, :users, :members, :roles
|
||||||
|
|
||||||
|
def setup
|
||||||
|
DmsfFile.storage_path = File.expand_path '../../../../fixtures/files', __FILE__
|
||||||
|
@jsmith = User.find_by_id 2
|
||||||
|
@file1 = DmsfFile.find_by_id 1
|
||||||
|
@folder1 = DmsfFolder.find_by_id 1
|
||||||
|
Setting.rest_api_enabled = '1'
|
||||||
|
@role = Role.find_by_id 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_truth
|
||||||
|
assert_kind_of User, @jsmith
|
||||||
|
assert_kind_of DmsfFolder, @folder1
|
||||||
|
assert_kind_of DmsfFile, @file1
|
||||||
|
assert_kind_of Role, @role
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_list_folder
|
||||||
|
@role.add_permission! :view_dmsf_folders
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml
|
||||||
|
get "/projects/1/dmsf.xml?key=#{token.value}"
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'application/xml', @response.content_type
|
||||||
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <dmsf>
|
||||||
|
# <dmsf_folders total_count="2" type="array">
|
||||||
|
# <folder>
|
||||||
|
# <id>1</id>
|
||||||
|
# <title>folder1</title>
|
||||||
|
# </folder>
|
||||||
|
# <folder>
|
||||||
|
# <id>6</id>
|
||||||
|
# <title>folder6</title>
|
||||||
|
# </folder>
|
||||||
|
# </dmsf_folders>
|
||||||
|
# <dmsf_files total_count="1" type="array">
|
||||||
|
# <file>
|
||||||
|
# <id>1</id>
|
||||||
|
# <name>test.txt</name>
|
||||||
|
# </file>
|
||||||
|
# </dmsf_files>
|
||||||
|
# <dmsf_links total_count="0" type="array">
|
||||||
|
# </dmsf_links>
|
||||||
|
# </dmsf>
|
||||||
|
assert_select 'dmsf > dmsf_folders > folder > id', :text => @folder1.id.to_s
|
||||||
|
assert_select 'dmsf > dmsf_folders > folder > title', :text => @folder1.title.to_s
|
||||||
|
assert_select 'dmsf > dmsf_files > file > id', :text => @file1.id.to_s
|
||||||
|
assert_select 'dmsf > dmsf_files > file > name', :text => @file1.name.to_s
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_create_folder
|
||||||
|
@role.add_permission! :folder_manipulation
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
#curl -v -H "Content-Type: application/xml" -X POST --data "@folder.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/create.xml
|
||||||
|
payload = %{
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<dmsf_folder>
|
||||||
|
<title>rest_api</title>
|
||||||
|
<description>A folder created via REST API</description>
|
||||||
|
<dmsf_folder_id/>
|
||||||
|
</dmsf_folder>
|
||||||
|
}
|
||||||
|
post "/projects/1/dmsf/create.xml?&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'}
|
||||||
|
assert_response :success
|
||||||
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <dmsf_folder>
|
||||||
|
# <id>8</id>
|
||||||
|
# <title>rest_api</title>
|
||||||
|
# </dmsf_folder>
|
||||||
|
assert_select 'dmsf_folder > title', :text => 'rest_api'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_folder_by_title
|
||||||
|
@role.add_permission! :view_dmsf_folders
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
|
||||||
|
get "/projects/1/dmsf.xml?key=#{token.value}&folder_title=#{@folder1.title}"
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'application/xml', @response.content_type
|
||||||
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <dmsf>
|
||||||
|
# <dmsf_folders total_count="1" type="array">
|
||||||
|
# <folder>
|
||||||
|
# <id>2</id>
|
||||||
|
# <title>folder2</title>
|
||||||
|
# </folder>
|
||||||
|
# </dmsf_folders>
|
||||||
|
# <dmsf_files total_count="0" type="array">
|
||||||
|
# </dmsf_files>
|
||||||
|
# <dmsf_links total_count="0" type="array">
|
||||||
|
# </dmsf_links>
|
||||||
|
# <found_folder>
|
||||||
|
# <id>1</id>
|
||||||
|
# <title>folder1</title>
|
||||||
|
# </found_folder>
|
||||||
|
# </dmsf>
|
||||||
|
assert_select 'dmsf > found_folder > id', :text => @folder1.id.to_s
|
||||||
|
assert_select 'dmsf > found_folder > title', :text => @folder1.title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_folder_by_title_not_found
|
||||||
|
@role.add_permission! :view_dmsf_folders
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
|
||||||
|
get "/projects/1/dmsf.xml?key=#{token.value}&folder_title=xxx"
|
||||||
|
assert_response :missing
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_folder_by_id
|
||||||
|
@role.add_permission! :view_dmsf_folders
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3
|
||||||
|
get "/projects/1/dmsf.xml?key=#{token.value}&folder_id=#{@folder1.id}"
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'application/xml', @response.content_type
|
||||||
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <dmsf>
|
||||||
|
# <dmsf_folders total_count="1" type="array">
|
||||||
|
# <folder>
|
||||||
|
# <id>2</id>
|
||||||
|
# <title>folder2</title>
|
||||||
|
# </folder>
|
||||||
|
# </dmsf_folders>
|
||||||
|
# <dmsf_files total_count="0" type="array">
|
||||||
|
# </dmsf_files>
|
||||||
|
# <dmsf_links total_count="0" type="array">
|
||||||
|
# </dmsf_links>
|
||||||
|
# <found_folder>
|
||||||
|
# <id>1</id>
|
||||||
|
# <title>folder1</title>
|
||||||
|
# </found_folder>
|
||||||
|
# </dmsf>
|
||||||
|
assert_select 'dmsf > found_folder > id', :text => @folder1.id.to_s
|
||||||
|
assert_select 'dmsf > found_folder > title', :text => @folder1.title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_folder_by_id_not_found
|
||||||
|
@role.add_permission! :view_dmsf_folders
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3
|
||||||
|
get "/projects/1/dmsf.xml?key=#{token.value}&folder_id=99999999999"
|
||||||
|
assert_response :missing
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update_folder
|
||||||
|
@role.add_permission! :folder_manipulation
|
||||||
|
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||||
|
#curl -v -H "Content-Type: application/json" -X POST --data "@update-folder-payload.json" -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000//projects/#{project_id}/dmsf/save.json
|
||||||
|
payload = %{
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<dmsf_folder>
|
||||||
|
<title>rest_api</title>
|
||||||
|
<description>A folder updated via REST API</description>
|
||||||
|
</dmsf_folder>
|
||||||
|
}
|
||||||
|
post "/projects/1/dmsf/save.xml?folder_id=1&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'}
|
||||||
|
assert_response :success
|
||||||
|
# <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
# <dmsf_folder>
|
||||||
|
# <id>1</id>
|
||||||
|
# <title>rest_api</title>
|
||||||
|
# <description>A folder updated via REST API</description>
|
||||||
|
# </dmsf_folder>
|
||||||
|
assert_select 'dmsf_folder > title', :text => 'rest_api'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
@ -29,7 +29,6 @@ class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
:dmsf_locks
|
:dmsf_locks
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
|
||||||
DmsfLock.delete_all
|
DmsfLock.delete_all
|
||||||
@admin = credentials 'admin'
|
@admin = credentials 'admin'
|
||||||
@jsmith = credentials 'jsmith'
|
@jsmith = credentials 'jsmith'
|
||||||
@ -41,7 +40,7 @@ class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
@file1 = DmsfFile.find_by_id 1
|
@file1 = DmsfFile.find_by_id 1
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||||
User.current = nil
|
User.current = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
@role = Role.find_by_id 1 # Manager
|
@role = Role.find_by_id 1 # Manager
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||||
User.current = nil
|
User.current = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
@project2 = Project.find_by_id 2
|
@project2 = Project.find_by_id 2
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||||
User.current = nil
|
User.current = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
@folder6 = DmsfFolder.find_by_id 6
|
@folder6 = DmsfFolder.find_by_id 6
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||||
User.current = nil
|
User.current = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWebdavOptionsTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavOptionsTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfWebdavPostTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavPostTest < RedmineDmsf::Test::IntegrationTest
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../../test_helper', __FILE__)
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
||||||
@ -226,6 +226,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_put_non_versioned_files
|
def test_put_non_versioned_files
|
||||||
|
if Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] == 'WEBDAV_READ_WRITE'
|
||||||
@project1.enable_module! :dmsf
|
@project1.enable_module! :dmsf
|
||||||
@role.add_permission! :view_dmsf_folders
|
@role.add_permission! :view_dmsf_folders
|
||||||
@role.add_permission! :file_manipulation
|
@role.add_permission! :file_manipulation
|
||||||
@ -267,5 +268,6 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
assert_response :success # 201 - Created
|
assert_response :success # 201 - Created
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user