Initial Redmine tooling and local plugin forks
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<contact>
|
||||
<first_name>API contact name</first_name>
|
||||
<is_company>true</is_company>
|
||||
<project_id>contacts-plugin</project_id>
|
||||
<custom_fields>
|
||||
|
||||
</custom_fields>
|
||||
</contact>
|
||||
@@ -0,0 +1,89 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine CRM (redmine_contacts) plugin,
|
||||
# customer relationship management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2010-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_contacts 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
||||
|
||||
class Redmine::ApiTest::NotesTest < ActiveRecord::VERSION::MAJOR >= 4 ? Redmine::ApiTest::Base : ActionController::IntegrationTest
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
|
||||
:contacts_projects,
|
||||
:contacts_issues,
|
||||
:deals,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
Setting.rest_api_enabled = '1'
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
|
||||
test 'POST /contacts/:contact_id/projects.xml' do
|
||||
parameters = { :project => { :id => 2 } }
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:post, '/contacts/1/projects.xml', parameters, :success_code => :success)
|
||||
end
|
||||
|
||||
compatible_api_request :post, '/contacts/1/projects.xml', parameters, credentials('admin')
|
||||
assert_response :success
|
||||
assert_not_nil Contact.find(1).projects.where(:id => 2)
|
||||
end
|
||||
|
||||
test 'DELETE /contacts/:contact_id/projects.xml' do
|
||||
contact = Contact.find(1)
|
||||
contact.projects << Project.find(2)
|
||||
contact.save
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:delete, '/contacts/1/projects/2.xml', {}, :success_code => :success)
|
||||
end
|
||||
|
||||
compatible_api_request :delete, '/contacts/1/projects/2.xml', {}, credentials('admin')
|
||||
assert_response :success
|
||||
contact.reload
|
||||
assert_nil contact.projects.where(:id => 2).first
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,163 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine CRM (redmine_contacts) plugin,
|
||||
# customer relationship management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2010-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_contacts 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
||||
|
||||
class Redmine::ApiTest::ContactsTest < ActiveRecord::VERSION::MAJOR >= 4 ? Redmine::ApiTest::Base : ActionController::IntegrationTest
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
|
||||
:contacts_projects,
|
||||
:contacts_issues,
|
||||
:deals,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
Setting.rest_api_enabled = '1'
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
|
||||
def test_get_contacts_xml
|
||||
# Use a private project to make sure auth is really working and not just
|
||||
# only showing public issues.
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:get, '/projects/private-child/contacts.xml') if ActiveRecord::VERSION::MAJOR < 4
|
||||
|
||||
compatible_api_request :get, '/contacts.xml', {}, credentials('admin')
|
||||
|
||||
att = { :type => 'array', :total_count => 5, :limit => 25, :offset => 0 }
|
||||
assert_select 'contacts', :attributes => att
|
||||
end
|
||||
|
||||
def test_post_contacts_xml
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:post, '/contacts.xml', { :contact => { :project_id => 1, :first_name => 'API test' } },
|
||||
{ :success_code => :created })
|
||||
end
|
||||
|
||||
assert_difference('Contact.count') do
|
||||
compatible_api_request :post, '/contacts.xml', { :contact => { :project_id => 1, :first_name => 'API test' } }, credentials('admin')
|
||||
end
|
||||
|
||||
contact = Contact.order('id DESC').first
|
||||
assert_equal 'API test', contact.first_name
|
||||
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'contact', :child => { :tag => 'id', :content => contact.id.to_s }
|
||||
end
|
||||
|
||||
def test_post_contacts_xml_redirect
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:post, '/contacts.xml', { :contact => { :project_id => 1, :first_name => 'API test' } },
|
||||
{ :success_code => :created })
|
||||
end
|
||||
|
||||
assert_difference('Contact.count') do
|
||||
compatible_api_request :post, '/contacts.xml', { :contact => { :project_id => 1, :first_name => 'API test' }, :redirect_on_success => 'http://ya.ru' }, credentials('admin')
|
||||
end
|
||||
|
||||
assert_redirected_to 'http://ya.ru'
|
||||
end
|
||||
|
||||
# Issue 6 is on a private project
|
||||
def test_put_contacts_1_xml
|
||||
parameters = { :contact => { :first_name => 'API update' } }
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:put, '/contacts/1.xml', { :contact => { :first_name => 'API update' } },
|
||||
{ :success_code => :ok })
|
||||
end
|
||||
|
||||
assert_no_difference('Contact.count') do
|
||||
compatible_api_request :put, '/contacts/1.xml', parameters, credentials('admin')
|
||||
end
|
||||
|
||||
contact = Contact.where(:id => 1).first
|
||||
assert_equal 'API update', contact.first_name
|
||||
end
|
||||
def test_update_contact_with_uploaded_file
|
||||
set_tmp_attachments_directory
|
||||
# upload the file
|
||||
assert_difference 'Attachment.count' do
|
||||
compatible_api_request :post, '/uploads.xml', 'test_upload_with_upload', { 'CONTENT_TYPE' => 'application/octet-stream' }.merge(credentials('admin'))
|
||||
assert_response :created
|
||||
end
|
||||
xml = Hash.from_xml(response.body)
|
||||
token = xml['upload']['token']
|
||||
attachment = Attachment.order('id DESC').first
|
||||
|
||||
# update the issue with the upload's token
|
||||
compatible_api_request :put, '/contacts/1.xml', { :contact => {:name => 'Attachment added', :uploads => [{ :token => token, :filename => 'test.png',
|
||||
:description => 'avatar',
|
||||
:content_type => 'image/png' }] } },
|
||||
credentials('admin')
|
||||
assert_response :ok
|
||||
assert_equal '', @response.body
|
||||
|
||||
contact = Contact.where(:id => 1).first
|
||||
assert_include attachment, contact.attachments
|
||||
assert_equal attachment, contact.avatar
|
||||
end
|
||||
|
||||
def test_should_post_with_custom_fields
|
||||
field = ContactCustomField.create!(:name => 'Test', :field_format => 'int')
|
||||
assert_difference('Contact.count') do
|
||||
compatible_api_request :post, '/contacts.xml', { :contact => { :project_id => 1, :first_name => 'API test',
|
||||
:custom_fields => [{ 'id' => field.id.to_s, 'value' => '12' }] } }, credentials('admin')
|
||||
end
|
||||
contact = Contact.last
|
||||
assert_equal '12', contact.custom_value_for(field.id).value
|
||||
end
|
||||
|
||||
def test_should_put_with_custom_fields
|
||||
field = ContactCustomField.create!(:name => 'Test', :field_format => 'text')
|
||||
assert_no_difference('Contact.count') do
|
||||
compatible_api_request :put, '/contacts/1.xml', { :contact => { :custom_fields => [{ 'id' => field.id.to_s, 'value' => 'Hello' }] } }, credentials('admin')
|
||||
end
|
||||
contact = Contact.where(:id => 1).first
|
||||
assert_equal 'Hello', contact.custom_value_for(field.id).value
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<deal>
|
||||
<name>API deal name</name>
|
||||
<currency>USD</currency>
|
||||
<project_id>contacts-plugin</project_id>
|
||||
</deal>
|
||||
@@ -0,0 +1,128 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine CRM (redmine_contacts) plugin,
|
||||
# customer relationship management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2010-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_contacts 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
||||
|
||||
class Redmine::ApiTest::DealsTest < ActiveRecord::VERSION::MAJOR >= 4 ? Redmine::ApiTest::Base : ActionController::IntegrationTest
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
|
||||
:contacts_projects,
|
||||
:contacts_issues,
|
||||
:deals,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
Setting.rest_api_enabled = '1'
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
|
||||
test 'GET /deals.xml' do
|
||||
# Use a private project to make sure auth is really working and not just
|
||||
# only showing public issues.
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:get, '/projects/private-child/deals.xml') if ActiveRecord::VERSION::MAJOR < 4
|
||||
compatible_api_request :get, '/deals.xml', {}, credentials('admin')
|
||||
|
||||
att = { :type => 'array', :total_count => 2, :limit => 25, :offset => 0 }
|
||||
assert_select 'deals', :attributes => att
|
||||
end
|
||||
|
||||
test 'POST /deals.xml' do
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:post, '/deals.xml', { :deal => { :project_id => 1, :name => 'API test', :contact_id => 1 } },
|
||||
{ :success_code => :created })
|
||||
end
|
||||
|
||||
assert_difference('Deal.count') do
|
||||
compatible_api_request :post, '/deals.xml', { :deal => { :project_id => 1, :name => 'API test', :contact_id => 1 } }, credentials('admin')
|
||||
end
|
||||
|
||||
deal = Deal.order('id DESC').first
|
||||
assert_equal 'API test', deal.name
|
||||
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'deal', :child => { :tag => 'id', :content => deal.id.to_s }
|
||||
end
|
||||
|
||||
# Issue 6 is on a private project
|
||||
test 'PUT /deals/1.xml' do
|
||||
@parameters = { :deal => { :name => 'API update' } }
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:put, '/deals/1.xml', { :deal => { :name => 'API update' } },
|
||||
{ :success_code => :ok })
|
||||
end
|
||||
|
||||
assert_no_difference('Deal.count') do
|
||||
compatible_api_request :put, '/deals/1.xml', @parameters, credentials('admin')
|
||||
end
|
||||
|
||||
deal = Deal.where(:id => 1).first
|
||||
assert_equal 'API update', deal.name
|
||||
end
|
||||
|
||||
def test_post_with_custom_fields
|
||||
field = DealCustomField.create!(:name => 'Test', :field_format => 'int')
|
||||
assert_difference('Deal.count') do
|
||||
compatible_api_request :post, '/deals.xml', { :deal => { :project_id => 1, :name => 'API test',
|
||||
:custom_fields => [{ 'id' => field.id.to_s, 'value' => '14' }] } },
|
||||
credentials('admin')
|
||||
end
|
||||
deal = Deal.last
|
||||
assert_equal '14', deal.custom_value_for(field.id).value
|
||||
end
|
||||
|
||||
def test_put_with_custom_fields
|
||||
field = DealCustomField.create!(:name => 'Test', :field_format => 'text')
|
||||
assert_no_difference('Deal.count') do
|
||||
compatible_api_request :put, '/deals/1.xml', { :deal => { :custom_fields => [{ 'id' => field.id.to_s, 'value' => 'Hello deal' }] } },
|
||||
credentials('admin')
|
||||
end
|
||||
deal = Deal.where(:id => 1).first
|
||||
assert_equal 'Hello deal', deal.custom_value_for(field.id).value
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<note>
|
||||
<content>API note content</content>
|
||||
<subject>Test note</subject>
|
||||
</note>
|
||||
@@ -0,0 +1,113 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This file is a part of Redmine CRM (redmine_contacts) plugin,
|
||||
# customer relationship management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2010-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_contacts 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_contacts 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 redmine_contacts. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
||||
|
||||
class Redmine::ApiTest::NotesTest < ActiveRecord::VERSION::MAJOR >= 4 ? Redmine::ApiTest::Base : ActionController::IntegrationTest
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:versions,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:issue_categories,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:attachments,
|
||||
:workflows,
|
||||
:custom_fields,
|
||||
:custom_values,
|
||||
:custom_fields_projects,
|
||||
:custom_fields_trackers,
|
||||
:time_entries,
|
||||
:journals,
|
||||
:journal_details,
|
||||
:queries
|
||||
|
||||
RedmineContacts::TestCase.create_fixtures(Redmine::Plugin.find(:redmine_contacts).directory + '/test/fixtures/', [:contacts,
|
||||
:contacts_projects,
|
||||
:contacts_issues,
|
||||
:deals,
|
||||
:notes,
|
||||
:tags,
|
||||
:taggings,
|
||||
:queries])
|
||||
|
||||
def setup
|
||||
Setting.rest_api_enabled = '1'
|
||||
RedmineContacts::TestCase.prepare
|
||||
end
|
||||
|
||||
test 'POST /notes.xml' do
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:post, '/notes.xml', { :note => { :project_id => 1,
|
||||
:source_id => 1,
|
||||
:source_type => 'Contact',
|
||||
:content => 'API test' } },
|
||||
{ :success_code => :created })
|
||||
end
|
||||
|
||||
assert_difference('Note.count', 1) do
|
||||
compatible_api_request :post, '/notes.xml', { :note => { :content => 'API test' }, :project_id => 1, :source_id => 1, :source_type => 'Contact' }, credentials('admin')
|
||||
end
|
||||
|
||||
note = Note.order('id DESC').first
|
||||
assert_equal 'API test', note.content
|
||||
|
||||
assert_response :created
|
||||
assert_equal 'application/xml', @response.content_type
|
||||
assert_select 'note', :child => { :tag => 'id', :content => note.id.to_s }
|
||||
end
|
||||
|
||||
test 'PUT /notes/1.xml' do
|
||||
@parameters = { :note => { :content => 'API update' } }
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:put, '/notes/1.xml', @parameters, :success_code => :ok)
|
||||
end
|
||||
|
||||
assert_no_difference('Note.count') do
|
||||
compatible_api_request :put, '/notes/1.xml', @parameters, credentials('admin')
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
note = Note.where(:id => 1).first
|
||||
assert_equal 'API update', note.content
|
||||
end
|
||||
|
||||
test 'DELETE /notes/1.xml' do
|
||||
@parameters = { :note => { :content => 'API update' } }
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 4
|
||||
Redmine::ApiTest::Base.should_allow_api_authentication(:put, '/notes/1.xml', @parameters, :success_code => :ok)
|
||||
end
|
||||
|
||||
assert_difference('Note.count', -1) do
|
||||
compatible_api_request :delete, '/notes/1.xml', @parameters, credentials('admin')
|
||||
assert_response :success
|
||||
end
|
||||
assert_nil Note.where(:id => 1).first
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user