testlink-api-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,25 @@
|
|
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/objects/methods'
|
17
|
+
|
18
|
+
module TestLink
|
19
|
+
module Objects
|
20
|
+
class Project
|
21
|
+
include Methods
|
22
|
+
attr_accessor :id, :name, :prefix, :notes
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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/objects/methods'
|
17
|
+
|
18
|
+
module TestLink
|
19
|
+
module Objects
|
20
|
+
class Status
|
21
|
+
include Methods
|
22
|
+
attr_accessor :id, :status, :message, :additional_info, :operation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
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 RSpec::Matchers
|
17
|
+
def attribute_provided? object, attribute
|
18
|
+
assignment = (attribute.to_s + '=').to_sym
|
19
|
+
(object.respond_to? attribute) && (object.respond_to? assignment)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
RSpec::Matchers.define :provide do |attribute|
|
24
|
+
match do |object|
|
25
|
+
attribute_provided? object, attribute
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec::Matchers.define :provide_mandatory_argument do |argument|
|
30
|
+
match do |command|
|
31
|
+
(attribute_provided? command, argument) && command.class.arguments[argument].mandatory?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Matchers.define :provide_argument do |argument|
|
36
|
+
match do |command|
|
37
|
+
(attribute_provided? command, argument) && (command.class.arguments.has_key? argument)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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/exceptions/error_response_exception"
|
18
|
+
require "test_link/exceptions/empty_response_exception"
|
19
|
+
|
20
|
+
describe TestLink::Adapters::Base do
|
21
|
+
before :each do
|
22
|
+
@adapter = TestLink::Adapters::Base.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "manages responses" do
|
26
|
+
@adapter.should provide :response
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises an exception when an error code is detected in the response" do
|
30
|
+
@adapter.response = [{"code"=> 2000, "message"=>"Can not authenticate client: invalid developer key"}]
|
31
|
+
expect { @adapter.adapt }.to raise_exception TestLink::Exceptions::ErrorResponseException, "Can not authenticate client: invalid developer key"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises an exception when response is empty" do
|
35
|
+
@adapter.response = []
|
36
|
+
expect { @adapter.adapt }.to raise_exception TestLink::Exceptions::EmptyResponseException, "Response is empty"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises an exception when response is nil" do
|
40
|
+
@adapter.response = nil
|
41
|
+
expect { @adapter.adapt }.to raise_exception TestLink::Exceptions::EmptyResponseException, "Response is empty"
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'calls adapt_row' do
|
45
|
+
def @adapter.adapt_row row
|
46
|
+
end
|
47
|
+
@adapter.response = [{'name' => 'a'}, {'name' => 'b'}]
|
48
|
+
@adapter.response.each { |row| @adapter.should_receive(:adapt_row).with(row) }
|
49
|
+
@adapter.adapt
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'recognises when a command failed' do
|
53
|
+
@adapter.response = {"status_ok" => 0, 'id' => 0, 'msg' => msg = 'Rorem ipsum erroor sit amet'}
|
54
|
+
expect { @adapter.adapt }.to raise_exception TestLink::Exceptions::CommandFailedException, "Command has failed: #{msg}"
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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/node_adapter"
|
17
|
+
require "test_link/objects/node"
|
18
|
+
|
19
|
+
describe TestLink::Adapters::NodeAdapter do
|
20
|
+
before :each do
|
21
|
+
@adapter = TestLink::Adapters::NodeAdapter.new
|
22
|
+
end
|
23
|
+
|
24
|
+
it "inherits from TestLink::Adapters::Base" do
|
25
|
+
TestLink::Adapters::NodeAdapter.should < TestLink::Adapters::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should know how to adapt a single row of a response" do
|
29
|
+
node = TestLink::Objects::Node.new
|
30
|
+
row = { "id" => (node.id = 2).to_s,
|
31
|
+
"parent_id" => (node.parent_id = 1).to_s,
|
32
|
+
"node_type_id" => (node.type_id = 2).to_s,
|
33
|
+
"node_order" => (node.order = 1).to_s,
|
34
|
+
"node_table" => node.table = "testsuites",
|
35
|
+
"name" => node.name = "First Testsuite"}
|
36
|
+
|
37
|
+
@adapter.adapt_row(row).should == node
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should should adapt raw response to Project objects" do
|
41
|
+
node1 = TestLink::Objects::Node.new
|
42
|
+
node2 = TestLink::Objects::Node.new
|
43
|
+
|
44
|
+
response = [
|
45
|
+
{ "id" => (node1.id = 2).to_s,
|
46
|
+
"parent_id" => (node1.parent_id = 1).to_s,
|
47
|
+
"node_type_id" => (node1.type_id = 2).to_s,
|
48
|
+
"node_order" => (node1.order = 1).to_s,
|
49
|
+
"node_table" => node1.table = "testsuites",
|
50
|
+
"name" => node1.name = "First Testsuite"},
|
51
|
+
{ "id" => (node2.id = 3).to_s,
|
52
|
+
"parent_id" => (node2.parent_id = 1).to_s,
|
53
|
+
"node_type_id" => (node2.type_id = 2).to_s,
|
54
|
+
"node_order" => (node2.order = 2).to_s,
|
55
|
+
"node_table" => node2.table = "testsuites",
|
56
|
+
"name" => node2.name = "Second Testsuite"}]
|
57
|
+
|
58
|
+
@adapter.response = response
|
59
|
+
@adapter.adapt.should == [ node1, node2 ]
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "workaround unexpected messages form" do
|
63
|
+
it 'allows to receive hashes pretending do be arrays' do
|
64
|
+
node1 = TestLink::Objects::Node.new
|
65
|
+
node2 = TestLink::Objects::Node.new
|
66
|
+
|
67
|
+
response = {
|
68
|
+
"4" => {
|
69
|
+
"id" => (node1.id = 4).to_s,
|
70
|
+
"details" => node1.details = "<p>First one's child</p>",
|
71
|
+
"name" => node1.name = "First Testsuite's child",
|
72
|
+
"node_type_id" => (node1.type_id = 2).to_s,
|
73
|
+
"node_order"=> (node1.order = 1).to_s,
|
74
|
+
"parent_id" => (node1.parent_id = 2).to_s},
|
75
|
+
"5" => {
|
76
|
+
"id" => (node2.id = 5).to_s,
|
77
|
+
"details" => node2.details = "",
|
78
|
+
"name" => node2.name = "Frist's Second testsuite",
|
79
|
+
"node_type_id" => (node2.type_id = 2).to_s,
|
80
|
+
"node_order" => (node2.order = 2).to_s,
|
81
|
+
"parent_id"=> (node2.parent_id = 2).to_s}}
|
82
|
+
|
83
|
+
@adapter.response = response
|
84
|
+
@adapter.adapt.should == [ node1, node2 ]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'allows to receive a single node out of an array' do
|
88
|
+
node = TestLink::Objects::Node.new
|
89
|
+
|
90
|
+
response = {
|
91
|
+
"id" => (node.id = 4).to_s,
|
92
|
+
"details" => node.details = "<p>First one's child</p>",
|
93
|
+
"name" => node.name = "First Testsuite's child",
|
94
|
+
"node_type_id" => (node.type_id = 2).to_s,
|
95
|
+
"node_order" => (node.order = 1).to_s,
|
96
|
+
"parent_id" => (node.parent_id = 2).to_s}
|
97
|
+
|
98
|
+
@adapter.response = response
|
99
|
+
@adapter.adapt.should == [ node ]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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/project_adapter"
|
17
|
+
require "test_link/objects/project"
|
18
|
+
|
19
|
+
describe TestLink::Adapters::ProjectAdapter do
|
20
|
+
before :each do
|
21
|
+
@project_adapter = TestLink::Adapters::ProjectAdapter.new
|
22
|
+
end
|
23
|
+
|
24
|
+
it "inherits from TestLink::Adapters::Base" do
|
25
|
+
TestLink::Adapters::ProjectAdapter.should < TestLink::Adapters::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should know how to adapt a single row of a response" do
|
29
|
+
p_formation = TestLink::Objects::Project.new
|
30
|
+
row = {"id"=> (p_formation.id = 203).to_s ,
|
31
|
+
"notes"=> p_formation.notes = "",
|
32
|
+
"color"=>"",
|
33
|
+
"active"=>"1",
|
34
|
+
"prefix"=> p_formation.prefix = "FOR",
|
35
|
+
"tc_counter"=>"0",
|
36
|
+
"is_public"=>"1",
|
37
|
+
"options"=>"O:8:\"stdClass\":4:{s:19:\"requirementsEnabled\";s:1:\"1\";s:19:\"testPriorityEnabled\";s:1:\"1\";s:17:\"automationEnabled\";s:1:\"1\";s:16:\"inventoryEnabled\";b:0;}",
|
38
|
+
"name"=> p_formation.name = 'Formation',
|
39
|
+
"opt"=>{"requirementsEnabled"=>"1",
|
40
|
+
"testPriorityEnabled"=>"1",
|
41
|
+
"automationEnabled"=>"1",
|
42
|
+
"inventoryEnabled"=>false}}
|
43
|
+
|
44
|
+
@project_adapter.adapt_row(row).should == p_formation
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should should adapt raw response to Project objects" do
|
48
|
+
p_formation = TestLink::Objects::Project.new
|
49
|
+
p_val = TestLink::Objects::Project.new
|
50
|
+
response = [
|
51
|
+
{"id"=> (p_formation.id = 203).to_s ,
|
52
|
+
"notes"=> p_formation.notes = "",
|
53
|
+
"color"=>"",
|
54
|
+
"active"=>"1",
|
55
|
+
"prefix"=> p_formation.prefix = "FOR",
|
56
|
+
"tc_counter"=>"0",
|
57
|
+
"is_public"=>"1",
|
58
|
+
"options"=>"O:8:\"stdClass\":4:{s:19:\"requirementsEnabled\";s:1:\"1\";s:19:\"testPriorityEnabled\";s:1:\"1\";s:17:\"automationEnabled\";s:1:\"1\";s:16:\"inventoryEnabled\";b:0;}",
|
59
|
+
"name"=> p_formation.name = 'Formation',
|
60
|
+
"opt"=>{"requirementsEnabled"=>"1",
|
61
|
+
"testPriorityEnabled"=>"1",
|
62
|
+
"automationEnabled"=>"1",
|
63
|
+
"inventoryEnabled"=>false}},
|
64
|
+
{"id"=>(p_val.id = 1),
|
65
|
+
"notes"=> p_val.notes = "",
|
66
|
+
"color"=>"",
|
67
|
+
"active"=>"1",
|
68
|
+
"prefix"=> p_val.prefix = "TC185",
|
69
|
+
"tc_counter"=>"74",
|
70
|
+
"is_public"=>"1",
|
71
|
+
"options"=>"O:8:\"stdClass\":4:{s:19:\"requirementsEnabled\";s:1:\"1\";s:19:\"testPriorityEnabled\";s:1:\"1\";s:17:\"automationEnabled\";s:1:\"1\";s:16:\"inventoryEnabled\";b:0;}",
|
72
|
+
"name"=> p_val.name = "Validation TestLink",
|
73
|
+
"opt"=>{"requirementsEnabled"=>"1",
|
74
|
+
"testPriorityEnabled"=>"1",
|
75
|
+
"automationEnabled"=>"1",
|
76
|
+
"inventoryEnabled"=>false}}]
|
77
|
+
|
78
|
+
@project_adapter.response = response
|
79
|
+
@project_adapter.adapt.should == [ p_formation, p_val ]
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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/status_adapter"
|
17
|
+
require "test_link/objects/status"
|
18
|
+
|
19
|
+
describe TestLink::Adapters::StatusAdapter do
|
20
|
+
before :each do
|
21
|
+
@status_adapter = TestLink::Adapters::StatusAdapter.new
|
22
|
+
end
|
23
|
+
|
24
|
+
it "inherits from TestLink::Adapters::Base" do
|
25
|
+
TestLink::Adapters::StatusAdapter.should < TestLink::Adapters::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
it "knows how to adapt a single row of a response" do
|
29
|
+
status = TestLink::Objects::Status.new
|
30
|
+
row = {
|
31
|
+
"id"=> (status.id = 2).to_s,
|
32
|
+
"status" => status.status = true,
|
33
|
+
"operation" => status.operation = "createTestSuite",
|
34
|
+
"additionalInfo" => status.additional_info = "some more infos",
|
35
|
+
"message" => status.message = "ok"}
|
36
|
+
@status_adapter.adapt_row(row).should == status
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should should adapt raw response to Status objects" do
|
40
|
+
status = TestLink::Objects::Status.new
|
41
|
+
response = [{
|
42
|
+
"id"=> (status.id = 2).to_s,
|
43
|
+
"status" => status.status = true,
|
44
|
+
"operation" => status.operation = "createTestSuite",
|
45
|
+
"additionalInfo" => status.additional_info = "some more infos",
|
46
|
+
"message" => status.message = "ok"}]
|
47
|
+
|
48
|
+
@status_adapter.response = response
|
49
|
+
@status_adapter.adapt.should == [ status ]
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,106 @@
|
|
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/base'
|
18
|
+
|
19
|
+
describe TestLink::ApiLink do
|
20
|
+
before :each do
|
21
|
+
@url = 'http://qa.example.com'
|
22
|
+
@key = '__dev_key__'
|
23
|
+
@link = TestLink::ApiLink.new @url, @key
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has a server url' do
|
27
|
+
@link.url.should == @url
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'has an API key' do
|
31
|
+
@link.key.should == @key
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has an API url' do
|
35
|
+
@link.api_url.should == (@url + '/lib/api/xmlrpc.php')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'holds a XMLRPC client' do
|
39
|
+
@link.client.should be_an_instance_of XMLRPC::Client
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'allows to add remote methods' do
|
43
|
+
TestLink::ApiLink.should respond_to :remote_method
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'allows to define an adapter for each remote method' do
|
47
|
+
TestLink::ApiLink.should respond_to :set_adapter_for
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'Adding remote method support' do
|
51
|
+
before :all do
|
52
|
+
class TestLink::ApiLink
|
53
|
+
def self.remote_methods
|
54
|
+
@@remote_methods
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class FooAdapter
|
59
|
+
attr_accessor :response
|
60
|
+
def adapt
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Foo < TestLink::Command::Base
|
65
|
+
adapt_with FooAdapter
|
66
|
+
|
67
|
+
def command_name
|
68
|
+
'foo'
|
69
|
+
end
|
70
|
+
|
71
|
+
def execute link
|
72
|
+
[{}]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
TestLink::ApiLink.remote_method Foo
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'finds out the name of the method with class command_name method' do
|
80
|
+
link = TestLink::ApiLink.new('http://qa.example.com/', '')
|
81
|
+
link.should respond_to :foo
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'registers a new class instance with the command symbol' do
|
85
|
+
TestLink::ApiLink.remote_methods[:foo].should be_an_instance_of Foo
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'execution' do
|
89
|
+
before :each do
|
90
|
+
@link = TestLink::ApiLink.new('http://qa.example.com/', '___dev_key___')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'calls the registered command class execute method with parameters' do
|
94
|
+
args = {:foo => 'bar', :baz => 42}
|
95
|
+
foo = TestLink::ApiLink.remote_methods[:foo]
|
96
|
+
foo.should_receive(:execute).with(@link)
|
97
|
+
foo.should_receive(:reset_arguments_hash).with(args)
|
98
|
+
@link.foo args
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'uses the command specified adapter' do
|
102
|
+
TestLink::ApiLink.adapter_for(Foo.command_name.to_sym).should be_an_instance_of FooAdapter
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|