testlink-api-client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +15 -0
- data/README.rdoc +14 -0
- data/features/create_test_suite.feature +90 -0
- data/features/get_first_level_test_suites_for_test_project.feature +25 -0
- data/features/get_projects.feature +47 -0
- data/features/get_test_suite_by_id.feature +24 -0
- data/features/get_test_suites_for_test_suite.feature +33 -0
- data/features/step_definitions/common.rb +69 -0
- data/features/step_definitions/create_test_suite.rb +14 -0
- data/features/step_definitions/get_first_level_test_suites_for_test_project.rb +14 -0
- data/features/step_definitions/get_projects.rb +56 -0
- data/features/support/db/one_project.sql +1311 -0
- data/features/support/db/some_testsuites.sql +1312 -0
- data/features/support/env.rb +32 -0
- data/features/support/test_link_test_module.rb +32 -0
- data/lib/test_link.rb +22 -0
- data/lib/test_link/adapters.rb +24 -0
- data/lib/test_link/adapters/base.rb +35 -0
- data/lib/test_link/adapters/node_adapter.rb +47 -0
- data/lib/test_link/adapters/project_adapter.rb +32 -0
- data/lib/test_link/adapters/status_adapter.rb +33 -0
- data/lib/test_link/api_link.rb +62 -0
- data/lib/test_link/command.rb +29 -0
- data/lib/test_link/command/argument.rb +31 -0
- data/lib/test_link/command/base.rb +63 -0
- data/lib/test_link/command/create_test_case.rb +40 -0
- data/lib/test_link/command/create_test_suite.rb +35 -0
- data/lib/test_link/command/definition.rb +45 -0
- data/lib/test_link/command/get_first_level_test_suites_for_test_project.rb +29 -0
- data/lib/test_link/command/get_projects.rb +26 -0
- data/lib/test_link/command/get_test_suite_by_id.rb +29 -0
- data/lib/test_link/command/get_test_suites_for_test_suite.rb +29 -0
- data/lib/test_link/exceptions.rb +23 -0
- data/lib/test_link/exceptions/command_failed_exception.rb +26 -0
- data/lib/test_link/exceptions/empty_response_exception.rb +26 -0
- data/lib/test_link/exceptions/error_response_exception.rb +28 -0
- data/lib/test_link/exceptions/exception.rb +21 -0
- data/lib/test_link/objects.rb +24 -0
- data/lib/test_link/objects/methods.rb +29 -0
- data/lib/test_link/objects/node.rb +25 -0
- data/lib/test_link/objects/project.rb +25 -0
- data/lib/test_link/objects/status.rb +25 -0
- data/lib/testlink-api-client.rb +16 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/test_link/adapters/base_spec.rb +56 -0
- data/spec/test_link/adapters/node_adapter_spec.rb +102 -0
- data/spec/test_link/adapters/project_adapter_spec.rb +81 -0
- data/spec/test_link/adapters/status_adapter_spec.rb +51 -0
- data/spec/test_link/api_link_spec.rb +106 -0
- data/spec/test_link/command/argument_spec.rb +43 -0
- data/spec/test_link/command/base_spec.rb +94 -0
- data/spec/test_link/command/create_test_case_spec.rb +88 -0
- data/spec/test_link/command/create_test_suite_spec.rb +67 -0
- data/spec/test_link/command/get_first_level_test_suites_for_test_project_spec.rb +43 -0
- data/spec/test_link/command/get_projets_spec.rb +33 -0
- data/spec/test_link/command/get_test_suite_by_id_spec.rb +43 -0
- data/spec/test_link/command/get_test_suites_for_test_suite_spec.rb +43 -0
- data/spec/test_link/exceptions/command_failed_exception_spec.rb +28 -0
- data/spec/test_link/exceptions/empty_response_exception_spec.rb +28 -0
- data/spec/test_link/exceptions/error_response_exception_spec.rb +30 -0
- data/spec/test_link/objects/node_spec.rb +49 -0
- data/spec/test_link/objects/project_spec.rb +39 -0
- data/spec/test_link/objects/status_spec.rb +43 -0
- metadata +194 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
$:.unshift File.dirname(__FILE__)+'/../../lib'
|
17
|
+
|
18
|
+
require 'testlink-api-client'
|
19
|
+
require 'cucumber/rspec/doubles'
|
20
|
+
require File.join(File.dirname(__FILE__), 'test_link_test_module.rb')
|
21
|
+
|
22
|
+
class TestLinkWorld
|
23
|
+
include TestLinkTestModule
|
24
|
+
end
|
25
|
+
|
26
|
+
World do
|
27
|
+
TestLinkWorld.new
|
28
|
+
end
|
29
|
+
|
30
|
+
Before do
|
31
|
+
@parameters = {}
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module TestLinkTestModule
|
17
|
+
def reset_db sql_file
|
18
|
+
fail('MYSQL_USER environment variable should be set') if ENV['MYSQL_USER'].nil?
|
19
|
+
fail('MYSQL_DB environment variable should be set') if ENV['MYSQL_DB'].nil?
|
20
|
+
mysql_passwd = ENV['MYSQL_PASSWD']
|
21
|
+
`mysql -u #{ENV['MYSQL_USER']} #{("-p " + mysql_passwd) unless mysql_passwd.nil?} #{ENV['MYSQL_DB']} < #{File.dirname(__FILE__)}/db/#{sql_file}`
|
22
|
+
end
|
23
|
+
|
24
|
+
def string2boolean str
|
25
|
+
case str
|
26
|
+
when 'true', '1', 'yes', 'ok'
|
27
|
+
true
|
28
|
+
else
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/test_link.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/api_link'
|
17
|
+
require 'test_link/command'
|
18
|
+
require 'test_link/adapters'
|
19
|
+
require 'test_link/exceptions'
|
20
|
+
|
21
|
+
module TestLink
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/adapters/base'
|
17
|
+
require 'test_link/adapters/project_adapter'
|
18
|
+
require 'test_link/adapters/status_adapter'
|
19
|
+
require 'test_link/adapters/node_adapter'
|
20
|
+
|
21
|
+
module TestLink
|
22
|
+
module Adapters
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/exceptions/empty_response_exception'
|
17
|
+
require 'test_link/exceptions/command_failed_exception'
|
18
|
+
require 'test_link/exceptions/error_response_exception'
|
19
|
+
|
20
|
+
module TestLink
|
21
|
+
module Adapters
|
22
|
+
class Base
|
23
|
+
attr_accessor :response
|
24
|
+
|
25
|
+
def adapt
|
26
|
+
raise TestLink::Exceptions::EmptyResponseException.new if response.nil? || response.empty?
|
27
|
+
raise TestLink::Exceptions::CommandFailedException.new response['msg'] if (response.instance_of? Hash) && (response['status_ok'] == 0)
|
28
|
+
response.map do |row|
|
29
|
+
raise TestLink::Exceptions::ErrorResponseException.new row['message'], row['code'] if row.keys.include? 'code'
|
30
|
+
adapt_row row
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/adapters/base'
|
17
|
+
require 'test_link/objects/node'
|
18
|
+
|
19
|
+
module TestLink
|
20
|
+
module Adapters
|
21
|
+
class NodeAdapter < Base
|
22
|
+
|
23
|
+
def response= response
|
24
|
+
if response.instance_of? Hash
|
25
|
+
if response.has_key?('node_type_id')
|
26
|
+
response = [ response ]
|
27
|
+
elsif response.count > 1 && response.keys.reject { |key| key =~ /\A\d+?\z/ }.count == 0
|
28
|
+
response = response.values
|
29
|
+
end
|
30
|
+
end
|
31
|
+
super response
|
32
|
+
end
|
33
|
+
|
34
|
+
def adapt_row row
|
35
|
+
node = TestLink::Objects::Node.new
|
36
|
+
node.id = row['id'].to_i
|
37
|
+
node.parent_id = row['parent_id'].to_i
|
38
|
+
node.type_id = row['node_type_id'].to_i
|
39
|
+
node.table = row['node_table'] if row.has_key? 'node_table'
|
40
|
+
node.order = row['node_order'].to_i
|
41
|
+
node.name = row['name']
|
42
|
+
node.details = row['details'] if row.has_key? 'details'
|
43
|
+
node
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/adapters/base'
|
17
|
+
require 'test_link/objects/project'
|
18
|
+
|
19
|
+
module TestLink
|
20
|
+
module Adapters
|
21
|
+
class ProjectAdapter < Base
|
22
|
+
def adapt_row row
|
23
|
+
project = Objects::Project.new
|
24
|
+
project.id = row['id'].to_i
|
25
|
+
project.name = row['name']
|
26
|
+
project.prefix = row['prefix']
|
27
|
+
project.notes = row['notes']
|
28
|
+
project
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/adapters/base'
|
17
|
+
require 'test_link/objects/status'
|
18
|
+
|
19
|
+
module TestLink
|
20
|
+
module Adapters
|
21
|
+
class StatusAdapter < Base
|
22
|
+
def adapt_row row
|
23
|
+
status = Objects::Status.new
|
24
|
+
status.id = row['id'].to_i
|
25
|
+
status.message = row['message']
|
26
|
+
status.status = row['status']
|
27
|
+
status.additional_info = row['additionalInfo']
|
28
|
+
status.operation = row['operation']
|
29
|
+
status
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'xmlrpc/client'
|
17
|
+
|
18
|
+
module TestLink
|
19
|
+
class ApiLink
|
20
|
+
attr_accessor :key
|
21
|
+
attr_reader :client, :url
|
22
|
+
@@remote_methods = {}
|
23
|
+
@@adapters = {}
|
24
|
+
def initialize(url, key)
|
25
|
+
@url = url
|
26
|
+
@key = key
|
27
|
+
@client = XMLRPC::Client.new2 self.api_url
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_url()
|
31
|
+
@url + '/lib/api/xmlrpc.php'
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.remote_method(klass)
|
35
|
+
method_name = klass.command_name.to_sym
|
36
|
+
@@remote_methods[method_name] = klass.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def respond_to_missing?(symbol, include_private)
|
40
|
+
return true if @@remote_methods.include? symbol
|
41
|
+
super symbol, include_private
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(symbol, *args)
|
45
|
+
command = @@remote_methods[symbol]
|
46
|
+
adapter = @@adapters[symbol]
|
47
|
+
return super(symbol, args) if command.nil?
|
48
|
+
command_args = args.first || {}
|
49
|
+
command.reset_arguments_hash command_args
|
50
|
+
adapter.response = command.execute self
|
51
|
+
adapter.adapt
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.set_adapter_for command_name, klass
|
55
|
+
@@adapters[command_name.to_sym] = klass.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.adapter_for(command_name)
|
59
|
+
@@adapters[command_name.to_sym]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/command/argument'
|
17
|
+
require 'test_link/command/base'
|
18
|
+
require 'test_link/command/definition'
|
19
|
+
require 'test_link/command/get_projects'
|
20
|
+
require 'test_link/command/create_test_suite'
|
21
|
+
require 'test_link/command/get_first_level_test_suites_for_test_project'
|
22
|
+
require 'test_link/command/get_test_suites_for_test_suite'
|
23
|
+
require 'test_link/command/get_test_suite_by_id'
|
24
|
+
require 'test_link/command/create_test_case'
|
25
|
+
|
26
|
+
module TestLink
|
27
|
+
module Command
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module TestLink
|
17
|
+
module Command
|
18
|
+
class Argument
|
19
|
+
attr_reader :default
|
20
|
+
|
21
|
+
def initialize(default = nil, mandatory = false)
|
22
|
+
@default = default
|
23
|
+
@mandatory = mandatory
|
24
|
+
end
|
25
|
+
|
26
|
+
def mandatory?
|
27
|
+
@mandatory
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# This file is part of testlink-api-client.
|
2
|
+
#
|
3
|
+
# testlink-api-client is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# testlink-api-client is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test_link/command/definition'
|
17
|
+
require 'test_link/api_link'
|
18
|
+
|
19
|
+
module TestLink
|
20
|
+
module Command
|
21
|
+
class Base < Definition
|
22
|
+
argument :devKey, :mandatory => true
|
23
|
+
|
24
|
+
def execute link
|
25
|
+
self.devKey ||= link.key
|
26
|
+
errors = check_arguments
|
27
|
+
raise ArgumentError.new "Missing mandatory argument(s) #{errors}" unless errors.empty?
|
28
|
+
link.client.call 'tl.' + self.class.command_name, arguments_hash.reject { |key, value| value.nil? }
|
29
|
+
end
|
30
|
+
|
31
|
+
def arguments_hash
|
32
|
+
args = {}
|
33
|
+
(Base.arguments.keys + self.class.arguments.keys).each do |name|
|
34
|
+
args[name] = self.send(name)
|
35
|
+
end
|
36
|
+
args
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_arguments_hash hash
|
40
|
+
arguments_hash.keys.each do |name|
|
41
|
+
assignment = (name.to_s + '=').to_sym
|
42
|
+
send(assignment, hash[name])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_arguments
|
47
|
+
errors = []
|
48
|
+
self.class.arguments.select{ |name, argument| argument.mandatory? }.keys.each do |name|
|
49
|
+
errors.push name if arguments_hash[name].nil?
|
50
|
+
end
|
51
|
+
errors
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.remote_method
|
55
|
+
TestLink::ApiLink.remote_method self
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.adapt_with klass
|
59
|
+
TestLink::ApiLink.set_adapter_for self.command_name, klass
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|