test_linker 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ class TestLinker
2
+ class Error < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,261 @@
1
+ require_relative 'error'
2
+
3
+ # This module contains methods that aren't a part of the TestLink API. They
4
+ # intend to make accessing TestLink database info easier.
5
+ module TestLinker::Helpers
6
+
7
+ # @return [String] The version of TestLink's API.
8
+ def api_version
9
+ if @api_version
10
+ @api_version
11
+ else
12
+ about =~ /Testlink API Version: (.+) initially/
13
+ @api_version = $1
14
+ end
15
+ end
16
+
17
+ # Gets ID of project matching the given project_name.
18
+ #
19
+ # @param [String] project_name Name of the project to search for.
20
+ # @return [Fixnum] ID of project matching project_name.
21
+ # @raise [TestLinker::Error] When ID cannot be found for given
22
+ # project_name.
23
+ def test_project_id project_name
24
+ if @version < "1.0"
25
+ project = projects.find { |project| project["name"] == project_name }
26
+ else
27
+ project = test_project_by_name(project_name).first
28
+ raise TestLinker::Error, project['message'] if project['code']
29
+ end
30
+
31
+ project.nil? ? nil : project['id'].to_i
32
+ end
33
+
34
+ # Gets info about test plans within a project
35
+ #
36
+ # @param [String] project_name Name of the project to search for.
37
+ # @param [String] plan_name Name of the plan to search for.
38
+ # @return [Fixnum] ID of plan matching project_name and plan_name. 0 if the
39
+ # test plan wasn't found.
40
+ # @raise [RuntimeError] When unable to find matching project and plan names.
41
+ def test_plan_id(project_name, plan_name)
42
+ if @version < "1.0"
43
+ project_id = test_project_id project_name
44
+ test_plans = project_test_plans(project_id)
45
+
46
+ test_plan = test_plans.first.values.find do |project_test_plan|
47
+ project_test_plan["name"] == plan_name
48
+ end
49
+ else
50
+ test_plan = test_plan_by_name(project_name, plan_name).first
51
+ raise TestLinker::Error, test_plan['message'] if test_plan['code']
52
+ end
53
+
54
+ test_plan.nil? ? nil : test_plan['id'].to_i
55
+ end
56
+
57
+ # Gets the ID for the given build name.
58
+ #
59
+ # @param [String] project_name Name of the project to search for.
60
+ # @param [String] plan_name Name of the plan to search for.
61
+ # @param [String] build_name Name of the build to search for.
62
+ # @return [Fixnum] ID of plan matching project_name and plan_name
63
+ # @raise [TestLinker::Error] When unable to find matching
64
+ # project/plan/build names.
65
+ def build_id(project_name, plan_name, build_name)
66
+ plan_id = test_plan_id(project_name, plan_name)
67
+ builds = builds_for_test_plan plan_id
68
+
69
+ builds.each do |build|
70
+ if build['name'] == build_name
71
+ return build['id'].to_i
72
+ end
73
+ end
74
+
75
+ raise TestLinker::Error,
76
+ "Unable to find build named #{build_name} for #{plan_name} in #{project_name}"
77
+ end
78
+
79
+ # @param [Fixnum,String] project_id
80
+ # @param [Regexp] regex The expression to match test plan names on.
81
+ # @return [Array] An array of test plans that match the Regexp.
82
+ def find_test_plans(project_id, regex)
83
+ list = []
84
+ test_plan_list = project_test_plans(project_id).first
85
+
86
+ test_plan_list.each_value do |test_plan_info|
87
+ if test_plan_info["name"] =~ regex
88
+ list << test_plan_info
89
+ end
90
+ end
91
+
92
+ list
93
+ end
94
+
95
+ # @param [String] project_name
96
+ # @param [String] suite_name
97
+ # @return [Fixnum] ID of the requested test suite.
98
+ # @raise [TestLinker::Error] If no test suite was found by the given name.
99
+ def first_level_test_suite_id(project_name, suite_name)
100
+ test_suites = first_level_test_suites_for_test_project(test_project_id(project_name))
101
+
102
+ test_suites.each do |test_suite|
103
+ if test_suite['name'] == suite_name
104
+ return test_suite['id'].to_i
105
+ end
106
+ end
107
+
108
+ raise TestLinker::Error, "Suite #{suite_name} not found."
109
+ end
110
+
111
+ # Gets info about test case within a test plan within a project.
112
+ #
113
+ # @param [String] project_name Name of the project to search for.
114
+ # @param [String] plan_name Name of the plan to search for.
115
+ # @param [String] test_case_name Name of the test case to search for.
116
+ # @return [Hash] Info on the first matching test case.
117
+ # @raise [TestLinker::Error] When unable to find matching
118
+ # project/plan/test case names.
119
+ # @todo Need to update for having more than one of same test name inside test plan.
120
+ def test_info(project_name, plan_name, test_case_name)
121
+ test_plan_id = test_plan_id(project_name, plan_name)
122
+ test_cases = test_cases_for_test_plan(test_plan_id)
123
+
124
+ test_cases.each_value do |test_case_info|
125
+ if test_case_info['name'] == test_case_name
126
+ return test_case_info
127
+ end
128
+ end
129
+
130
+ raise TestLinker::Error,
131
+ "Unable to find test named #{test_case_name} for #{plan_name} in #{project_name}"
132
+ end
133
+
134
+ # Gets info about test suite within a test plan within a project.
135
+ #
136
+ # @param [String] project_name
137
+ # @param [String] plan_name
138
+ # @param [String] suite_name
139
+ # @return [Fixnum,String] SuiteID
140
+ # @raise [TestLinker::Error] When unable to find matching
141
+ # project/plan/test case names.
142
+ # @todo Need to update for having more than one of same test name inside test plan.
143
+ def suite_info(project_name, plan_name, suite_name)
144
+ test_plan_id = test_plan_id(project_name, plan_name)
145
+ test_suites = test_suites_for_test_plan(test_plan_id)
146
+
147
+ if test_suites.empty?
148
+ return "Unable to find test suites in test plan #{plan_name} in #{project_name}"
149
+ end
150
+
151
+ test_suites.each do |suite|
152
+ if suite["name"].include? suite_name
153
+ return suite
154
+ end
155
+ end
156
+
157
+ raise TestLinker::Error,
158
+ "Unable to find suite named #{suite_name} for #{plan_name} in #{project_name}"
159
+ end
160
+
161
+ # Get the ID of a first level suite, creating it if it does not exist.
162
+ #
163
+ # @param [String] project_name
164
+ # @param [String] suite_name
165
+ # @return [String] ID of the created or existing suite.
166
+ def create_first_level_suite(project_name, suite_name)
167
+ return first_level_test_suite_id(project_name, suite_name)
168
+ rescue RuntimeError
169
+
170
+ # Create suite if it doesn't exist.
171
+ project_id = test_project_id(project_name)
172
+
173
+ create_test_suite(project_id, suite_name).first['id']
174
+ end
175
+
176
+ # Get the ID of a suite with the given parent, creating it if it does not
177
+ # exist.
178
+ #
179
+ # @param [String] suite_name
180
+ # @param [String] project_name
181
+ # @return [String] ID of the created or existing suite.
182
+ # @raise [TestLinker::Error] When unable to find matching
183
+ # project/plan/test case names.
184
+ def create_suite(suite_name, project_name, parent_id)
185
+ project_id = test_project_id(project_name)
186
+ response = test_suites_for_test_suite(parent_id)
187
+
188
+ if response.class == Array
189
+ raise TestLinker::Error, response.first['message']
190
+ elsif response.class == Hash
191
+ return response['id'] if response['name'] == suite_name
192
+
193
+ response.each_value do |suite|
194
+ return suite['id'] if suite['name'] == suite_name
195
+ end
196
+ end
197
+
198
+ create_test_suite(project_id, suite_name, parent_id).first['id']
199
+ end
200
+
201
+ # Creates test in test suite within a test plan within a project.
202
+ #
203
+ # @param [String] test_case_name
204
+ # @param [String] suite_name
205
+ # @param [String] project_name
206
+ # @param [String] login
207
+ # @param [String] summary
208
+ # @param [String] steps
209
+ # @param [String] expected_results
210
+ # @return [Array] array-> array[0]=test case id, array[1]=test case version
211
+ # @todo Need to update for having more than one of same test name inside test plan.
212
+ def create_test_case_by_name(test_case_name, suite_name, project_name, login,
213
+ summary, steps, expected_results)
214
+
215
+ test_project_id = self.test_project_id(project_name)
216
+ test_suite_id = self.suite_info(project_name, plan_name, suite_name)
217
+
218
+ result = create_test_case(login, test_project_id, test_suite_id, test_case_name,
219
+ summary, steps, expected_results)
220
+
221
+ if result.any?
222
+ result.each do |result_ptr|
223
+ if result_ptr["message"].eql? "Success!"
224
+ if result_ptr.has_key? "additionalInfo"
225
+ result_info = result_ptr.fetch("additionalInfo")
226
+ if result_info["msg"].eql? "ok"
227
+ test_case_id = result_info["id"]
228
+ test_case_version = result_info["version_number"]
229
+ return [test_case_id, test_case_version]
230
+ else
231
+ return -1
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
238
+
239
+ # Creates test in test suite within a test plan within a project.
240
+ #
241
+ # @param [String] project_name
242
+ # @param [String] plan_name
243
+ # @param [Fixnum,String] test_case_id
244
+ # @param [String] test_case_version
245
+ # @return [Boolean] true on success, false on fail
246
+ # @todo NEED TO CLEAN THIS UP AND ADD ERROR CHECKING
247
+ # @todo Need to update for having more than one of same test name inside testplan
248
+ def add_test_case_to_test_plan_by_name(project_name, plan_name, test_case_id,
249
+ test_case_version)
250
+ test_project_id = test_project_id(project_name)
251
+ test_plan_id = test_plan_id(project_name, plan_name)
252
+
253
+ result = add_test_case_to_test_plan(test_project_id, test_plan_id,
254
+ test_case_id, test_case_version)
255
+
256
+ if result.any?
257
+ #Only way to tell if success if with the key "feature_id"
258
+ return result.has_key?("feature_id") ? true : false
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,4 @@
1
+ class TestLinker
2
+ # test_linker version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,687 @@
1
+ require_relative 'error'
2
+
3
+ class TestLinker
4
+
5
+ # This module contains all methods that directly wrap TestLink's XMLRPC
6
+ # functions.
7
+ module Wrapper
8
+
9
+ # Gets a test case by it's internal or external ID.
10
+ #
11
+ # @since TestLink API version 1.0
12
+ # @param [Hash] options
13
+ # @option options [Fixnum,String] testcaseid
14
+ # @option options [Fixnum,String] testcaseexternalid
15
+ # @option options [Fixnum,String] version The test case version. Default is most recent.
16
+ # @return
17
+ def test_case(options)
18
+ args = { "devKey" => @dev_key }
19
+ args.merge! options
20
+ make_call("tl.getTestCase", args, "1.0")
21
+ end
22
+ alias_method :getTestCase, :test_case
23
+
24
+ # Gets full path from the given node till the top using nodes_hierarchy_table.
25
+ #
26
+ # @since TestLink API version 1.0
27
+ # @param [Fixnum,String] node_id
28
+ # @return
29
+ def full_path node_id
30
+ args = { "devKey" => @dev_key, "nodeID" => node_id }
31
+ make_call("tl.getFullPath", args, "1.0")
32
+ end
33
+ alias_method :getFullPath, :full_path
34
+
35
+ # Gets a test suite by the given ID.
36
+ #
37
+ # @since TestLink API version 1.0
38
+ # @param [Fixnum,String] suite_id
39
+ # @return
40
+ def test_suite_by_id suite_id
41
+ args = { "devKey" => @dev_key, "testsuiteid" => suite_id }
42
+ make_call("tl.getTestSuiteByID", args, "1.0")
43
+ end
44
+ alias_method :getTestSuiteByID, :test_suite_by_id
45
+
46
+ # @since TestLink API version 1.0
47
+ # @param [Fixnum,String] execution_id
48
+ # @return [Hash] "status", "id", "message"
49
+ def delete_execution execution_id
50
+ args = { "devKey" => @dev_key, "executionid" => execution_id }
51
+ make_call("tl.deleteExecution", args, "1.0")
52
+ end
53
+ alias_method :deleteExecution, :delete_execution
54
+
55
+ # @since TestLink API version 1.0
56
+ # @param [String] user_name
57
+ # @return [Boolean,Hash] true if user exists, otherwise an error structure.
58
+ def does_user_exist user_name
59
+ args = { "devKey" => @dev_key, "user" => user_name }
60
+ make_call("tl.doesUserExist", args, "1.0")
61
+ end
62
+ alias_method :doesUserExist, :does_user_exist
63
+
64
+ # Checks if the given Developer Key exist.
65
+ #
66
+ # @since TestLink API version 1.0
67
+ # @param [String] dev_key
68
+ # @return [Hash] "true" if it exists, otherwise error structure.
69
+ def check_dev_key dev_key
70
+ args = { "devKey" => dev_key }
71
+ make_call("tl.checkDevKey", args, "1.0")
72
+ end
73
+ alias_method :checkDevKey, :check_dev_key
74
+
75
+ # Uploads an attachment for a test case execution.
76
+ #
77
+ # @since TestLink API version 1.0
78
+ # @param [String] file_name
79
+ # @param [String] mime_type
80
+ # @param [String] content The Base64 encoded content of the attachment.
81
+ # @param [Fixnum,String] execution_id
82
+ # @param [Hash] options
83
+ # @option options [String] title
84
+ # @option options [String] description
85
+ # @return
86
+ def upload_execution_attachment(file_name, mime_type, content, execution_id,
87
+ options={})
88
+ args = { "devKey" => @dev_key, "executionid" => execution_id,
89
+ "filename" => file_name, "filetype" => mime_type, "content" => content }
90
+ args.merge! options
91
+ make_call("tl.uploadExecutionAttachment", args, "1.0")
92
+ end
93
+ alias_method :uploadExecutionAttachment, :upload_execution_attachment
94
+
95
+ # Uploads an attachment for a Requirement. The attachment content must be
96
+ # Base64 encoded by the client before sending it.
97
+ #
98
+ # @since TestLink API version 1.0
99
+ # @param [Fixnum,String] requirement_id
100
+ # @param [String] file_name
101
+ # @param [String] mime_type
102
+ # @param [String] content The Base64 encoded content of the attachment.
103
+ # @param [Hash] options
104
+ # @option options [String] title
105
+ # @option options [String] description
106
+ # @return
107
+ def upload_requirement_attachment(file_name, mime_type, content,
108
+ requirement_id, options={})
109
+ args = { "devKey" => @dev_key, "requirementid" => requirement_id,
110
+ "filename" => file_name, "filetype" => mime_type, "content" => content }
111
+ args.merge! options
112
+ make_call("tl.uploadRequirementAttachment", args, "1.0")
113
+ end
114
+ alias_method :uploadRequirementAttachment, :upload_requirement_attachment
115
+
116
+ # Uploads an attachment for a Requirement Specification. The attachment
117
+ # content must be Base64 encoded by the client before sending it.
118
+ #
119
+ # @since TestLink API version 1.0
120
+ # @param [String] file_name
121
+ # @param [String] mime_type
122
+ # @param [String] content The Base64 encoded content of the attachment.
123
+ # @param [Fixnum,String] requirement_id
124
+ # @param [Hash] options
125
+ # @option options [String] title
126
+ # @option options [String] description
127
+ # @return
128
+ def upload_requirement_specification_attachment(file_name, mime_type, content,
129
+ requirement_specification_id, options={})
130
+ args = { "devKey" => @dev_key, "reqspecid" => requirement_specification_id,
131
+ "filename" => file_name, "filetype" => mime_type, "content" => content }
132
+ args.merge! options
133
+ make_call("tl.uploadRequirementSpecificationAttachment", args, "1.0")
134
+ end
135
+ alias_method :uploadRequirementSpecificationAttachment,
136
+ :upload_requirement_specification_attachment
137
+
138
+ # Assign Requirements to a test case. Capable of assigning multiple
139
+ # requirements. Requirements can belong to different Requirement Specs.
140
+ #
141
+ # @param [String] requirements
142
+ # @param [Fixnum,String] test_case_external_id
143
+ # @param [Fixnum,String] project_id
144
+ # @return
145
+ def assign_requirements(requirements, test_case_external_id, project_id)
146
+ args = { "devKey" => @dev_key, "testcaseexternalid" => test_case_external_id,
147
+ "testprojectid" => project_id, "requirements" => requirements }
148
+ make_call("tl.assignRequirements", args, "1.0b5")
149
+ end
150
+ alias_method :assignRequirements, :assign_requirements
151
+
152
+ # Uploads an attachment for a Test Project. The attachment must be Base64
153
+ # encoded by the client before sending it.
154
+ #
155
+ # @since TestLink API version 1.0
156
+ # @param [String] file_name
157
+ # @param [String] mime_type
158
+ # @param [String] content The Base64 encoded content of the attachment.
159
+ # @param [Fixnum,String] project_id
160
+ # @param [Hash] options
161
+ # @option options [String] title
162
+ # @option options [String] description
163
+ # @return
164
+ def upload_test_project_attachment(file_name, mime_type, content, project_id,
165
+ options={})
166
+ args = { "devKey" => @dev_key, "testprojectid" => project_id,
167
+ "filename" => file_name, "filetype" => mime_type, "content" => content }
168
+ args.merge! options
169
+ make_call("tl.uploadTestProjectAttachment", args, "1.0")
170
+ end
171
+ alias_method :uploadTestProjectAttachment, :upload_test_project_attachment
172
+
173
+ # Uploads an attachment for a Test Suite. The attachment must be Base64
174
+ # encoded by the client before sending it.
175
+ #
176
+ # @since TestLink API version 1.0
177
+ # @param [String] file_name
178
+ # @param [String] mime_type
179
+ # @param [String] content The Base64 encoded content of the attachment.
180
+ # @param [Fixnum,String] suite_id
181
+ # @param [Hash] options
182
+ # @option options [String] title
183
+ # @option options [String] description
184
+ # @return
185
+ def upload_test_suite_attachment(file_name, mime_type, content, suite_id,
186
+ options={})
187
+ args = { "devKey" => @dev_key, "testsuiteid" => suite_id,
188
+ "filename" => file_name, "filetype" => mime_type, "content" => content }
189
+ args.merge! options
190
+ make_call("tl.uploadTestSuiteAttachment", args, "1.0")
191
+ end
192
+ alias_method :uploadTestSuiteAttachment, :upload_test_suite_attachment
193
+
194
+ # Uploads an attachment for a Test Case. The attachment must be Base64
195
+ # encoded by the client before sending it.
196
+ #
197
+ # @since TestLink API version 1.0
198
+ # @param [String] file_name
199
+ # @param [String] mime_type
200
+ # @param [String] content The Base64 encoded content of the attachment.
201
+ # @param [Fixnum,String] test_case_id
202
+ # @param [Hash] options
203
+ # @option options [String] title
204
+ # @option options [String] description
205
+ # @return
206
+ def upload_test_case_attachment(file_name, mime_type, content, test_case_id,
207
+ options={})
208
+ args = { "devKey" => @dev_key, "testcaseid" => test_case_id,
209
+ "filename" => file_name, "filetype" => mime_type, "content" => content }
210
+ args.merge! options
211
+ make_call("tl.uploadTestCaseAttachment", args, "1.0")
212
+ end
213
+ alias_method :uploadTestCaseAttachment, :upload_test_case_attachment
214
+
215
+ # Uploads an attachment for specified table. You must specify the table that
216
+ # the attachment is connected (nodes_hierarchy, builds, etc) and the foreign
217
+ # key id in this table The attachment must be Base64 encoded by the client
218
+ # before sending it.
219
+ #
220
+ # @since TestLink API version 1.0
221
+ # @param [String] file_name
222
+ # @param [String] mime_type
223
+ # @param [String] content The Base64 encoded content of the attachment.
224
+ # @param [Fixnum,String] foreign_key_id
225
+ # @param [String] foreign_key_table
226
+ # @param [Hash] options
227
+ # @option options [String] title
228
+ # @option options [String] description
229
+ # @return
230
+ def upload_attachment(file_name, mime_type, content, foreign_key_id,
231
+ foreign_key_table, options={})
232
+ args = { "devKey" => @dev_key, "fkid" => foreign_key_id,
233
+ "fktable" => foreign_key_table, "filename" => file_name,
234
+ "filetype" => mime_type, "content" => content }
235
+ args.merge! options
236
+ make_call("tl.uploadAttachment", args, "1.0")
237
+ end
238
+ alias_method :uploadAttachment, :upload_attachment
239
+
240
+ # Basic connectivity test.
241
+ #
242
+ # @return [String] "Hello!"
243
+ def say_hello
244
+ make_call("tl.sayHello", "", "1.0b5")
245
+ end
246
+ alias_method :sayHello, :say_hello
247
+ alias_method :ping, :say_hello
248
+
249
+ # Sends a message to the server to have it repeated back.
250
+ #
251
+ # @param [String] message The message to get the server to repeat back.
252
+ # @return [String] The message sent to the server.
253
+ def repeat message
254
+ make_call("tl.repeat", { str: message }, "1.0b5")
255
+ end
256
+
257
+ # Returns info about the server's TestLink API.
258
+ #
259
+ # @return [String] Info about TestLink API version
260
+ def about
261
+ make_call("tl.about", "", "1.0b5")
262
+ end
263
+
264
+ # Gets a list of all projects.
265
+ #
266
+ # @return [Array<Hash>] List of all projects in TestLink and
267
+ # their associated info.
268
+ def projects
269
+ make_call("tl.getProjects", { devKey: @dev_key }, "1.0b5" )
270
+ end
271
+ alias_method :getProjects, :projects
272
+
273
+ # Gets a list of test plans within a project.
274
+ #
275
+ # @param [Fixnum,String] project_id ID of the project to retrieve plans.
276
+ # @return [Array<Hash>] Array of all plans in a project and their associated
277
+ # info.
278
+ # @raise [TestLinker::Error] If a project by the given ID doesn't exist.
279
+ def project_test_plans project_id
280
+ args = { devKey: @dev_key, testprojectid: project_id }
281
+ response = make_call("tl.getProjectTestPlans", args, "1.0b5")
282
+ response == "" ? [{}] : response
283
+ end
284
+ alias_method :getProjectTestPlans, :project_test_plans
285
+
286
+ # Info about a test project with a given name.
287
+ #
288
+ # @since TestLink API version 1.0
289
+ # @param [String] project_name Name of the project to search for.
290
+ # @return [Array<Hash>] Info on matching project.
291
+ def test_project_by_name project_name
292
+ args = { devKey: @dev_key, testprojectname: project_name }
293
+ make_call('tl.getTestProjectByName', args, "1.0")
294
+ end
295
+ alias_method :getTestProjectByName, :test_project_by_name
296
+
297
+ # Gets the test plan with the given name.
298
+ #
299
+ # @since TestLink API version 1.0
300
+ # @param [String] plan_name Name of the plan to search for.
301
+ # @param [String] project_name Name of the project the plan is in.
302
+ # @return [Array<Hash>] Info on matching plan.
303
+ def test_plan_by_name(plan_name, project_name)
304
+ args = { devKey: @dev_key, testplanname: plan_name,
305
+ testprojectname: project_name }
306
+ make_call('tl.getTestPlanByName', args, "1.0")
307
+ end
308
+ alias_method :getTestPlanByName, :test_plan_by_name
309
+
310
+ # List test suites within a test plan alphabetically.
311
+ #
312
+ # @param [Fixnum,String] plan_id ID of the plan to get suites for.
313
+ # @return [Array<Hash>] List of all suites in plan and their associated info.
314
+ def test_suites_for_test_plan plan_id
315
+ args = { devKey: @dev_key, testplanid: plan_id }
316
+ make_call("tl.getTestSuitesForTestPlan", args, "1.0b5")
317
+ end
318
+ alias_method :getTestSuitesForTestPlan, :test_suites_for_test_plan
319
+
320
+ # List test suites within a test plan alphabetically.
321
+ #
322
+ # @since API version 1.0
323
+ # @param [Fixnum,String] plan_id ID of the plan to get suites for.
324
+ # @return [Array<Hash>] List of all suites in plan and their associated info.
325
+ def test_plan_platforms plan_id
326
+ args = { devKey: @dev_key, testplanid: plan_id }
327
+ make_call("tl.getTestPlanPlatforms", args, "1.0")
328
+ end
329
+ alias_method :getTestPlanPlatforms, :test_plan_platforms
330
+
331
+ # Gets a list of test suites that are direct children of the given test suite.
332
+ #
333
+ # @since API version 1.0
334
+ # @param [Fixnum,String] suite_id ID of the suite to get suites for.
335
+ # @return [Array<Hash>] List of all suites in plan and their associated info.
336
+ def test_suites_for_test_suite suite_id
337
+ args = { devKey: @dev_key, testsuiteid: suite_id }
338
+ make_call("tl.getTestSuitesForTestSuite", args, "1.0")
339
+ end
340
+ alias_method :getTestSuitesForTestSuite, :test_suites_for_test_suite
341
+
342
+ # Gets the set of test suites from the top level of the test project tree.
343
+ #
344
+ # @param [Fixnum,String] project_id ID of the project to get suites for.
345
+ # @return [Array<Hash>] List of first level suites in project and their
346
+ # associated info.
347
+ def first_level_test_suites_for_test_project project_id
348
+ args = { devKey: @dev_key, testprojectid: project_id }
349
+ make_call("tl.getFirstLevelTestSuitesForTestProject", args, "1.0b5")
350
+ end
351
+ alias_method :getFirstLevelTestSuitesForTestProject,
352
+ :first_level_test_suites_for_test_project
353
+
354
+ # Info about test cases within a test plan.
355
+ #
356
+ # @param [Fixnum,String] plan_id ID of the plan to get test cases for.
357
+ # @param [Hash] options
358
+ # @option options [Fixnum,String] testcaseid
359
+ # @option options [Fixnum,String] buildid
360
+ # @option options [Fixnum,String] keywordid (mutually exclusive with keywords)
361
+ # @option options [Fixnum] keywords (mutually exclusive with keywordid)
362
+ # (TestLink API >=1.0)
363
+ # @option options [String] executed
364
+ # @option options [String] assignedto
365
+ # @option options [String] executestatus
366
+ # @option options [String] executiontype
367
+ # @option options [String] getstepinfo Defaults to false
368
+ # @return [Hash] List of all test cases in the plan and their
369
+ # associated info.
370
+ def test_cases_for_test_plan(plan_id, options={})
371
+ args = { devKey: @dev_key, testplanid: plan_id }
372
+ args.merge! options
373
+ make_call("tl.getTestCasesForTestPlan", args, "1.0b5")
374
+ end
375
+ alias_method :getTestCasesForTestPlan, :test_cases_for_test_plan
376
+
377
+ # @param [Fixnum,String] suite_id ID of the suite to retrieve test cases for.
378
+ # @param [Fixnum,String] project_id
379
+ # @param [Hash] options
380
+ # @option options [Boolean] deep
381
+ # @option options [String] details Default is "simple"; use "full" to get
382
+ # summary, steps & expected results.
383
+ # @return [Array<Hash>] List of test cases in the given suite and their
384
+ # associated info.
385
+ def test_cases_for_test_suite(suite_id, project_id, deep=true, details="")
386
+ args = { devKey: @dev_key, testsuiteid: suite_id,
387
+ projectid: project_id, deep: deep, details: details }
388
+ make_call("tl.getTestCasesForTestSuite", args, "1.0b5")
389
+ end
390
+ alias_method :getTestCasesForTestSuite, :test_cases_for_test_suite
391
+
392
+ # Gets the summarized results grouped by platform.
393
+ #
394
+ # @since TestLink API version 1.0
395
+ # @param [Fixnum,String] plan_id
396
+ # @return [Hash] Contains "type" => platform, "total_tc" => X, "details =>
397
+ # Array of counts.
398
+ def totals_for_test_plan plan_id
399
+ args = { devKey: @dev_key, testplanid: plan_id }
400
+ make_call("tl.getTotalsForTestPlan", args, "1.0")
401
+ end
402
+ alias_method :getTotalsForTestPlan, :totals_for_test_plan
403
+
404
+ # Gets attachments for specified test case.
405
+ #
406
+ # @param [Hash] options
407
+ # @param [Fixnum,String] testcaseid If not present, testcaseexternalid must be called.
408
+ # @param [Fixnum,String] testcaseexternalid If not present, testcaseid must be called.
409
+ # @return [String]
410
+ def test_case_attachments options
411
+ args = { devKey: @dev_key }
412
+ args.merge! options
413
+ make_call("tl.getTestCaseAttachments", args, "1.0b5")
414
+ end
415
+ alias_method :getTestCaseAttachments, :test_case_attachments
416
+
417
+ # @param [Fixnum,String] test_case_external_id
418
+ # @param [Fixnum,String] project_id
419
+ # @param [Fixnum] custom_field_name
420
+ # @param [Hash] options
421
+ # @option options [String] details Changes output information. If null or 'value',
422
+ # returns just a value; if 'full', returns a hash with all custom field definition,
423
+ # plus value and internal test case id; if 'simple', returns value plus custom
424
+ # field name, label, and type (as code).
425
+ # @return [Array<Hash>]
426
+ def test_case_custom_field_design_value(custom_field_name,
427
+ test_case_external_id, project_id, options={})
428
+ args = { devKey: @dev_key, testprojectid: project_id,
429
+ testcaseexternalid: test_case_external_id,
430
+ customfieldname: custom_field_name }
431
+ args.merge! options
432
+ make_call("tl.getTestCaseCustomFieldDesignValue", args, "1.0b5")
433
+ end
434
+ alias_method :getTestCaseCustomFieldDesignValue, :test_case_custom_field_design_value
435
+
436
+ # Info about test case by name.
437
+ # CAUTION: returns multiple values if test case is used more than once.
438
+ #
439
+ # @param [String] test_case_name Name to search across TL DB.
440
+ # @param [Hash] options
441
+ # @option options [String] testprojectname
442
+ # @option options [String] testsuitename
443
+ # @option options [String] testcasepathname
444
+ # @raise [TestLinker::Error] When test case name doesn't exist.
445
+ # @return [Array<Hash>] List of all test cases in the DB matching
446
+ # test_case_name and their associated info.
447
+ def test_case_id_by_name(test_case_name, options={})
448
+ args = { devKey: @dev_key, testcasename: test_case_name }
449
+ args.merge! options
450
+ make_call("tl.getTestCaseIDByName", args, "1.0b5")
451
+ end
452
+ alias_method :getTestCaseIDByName, :test_case_id_by_name
453
+
454
+ # @param [Fixnum,String] test_case_id
455
+ # @param [Fixnum,String] build_id
456
+ # @param [Fixnum,String] plan_id
457
+ # @return [Array<Hash>] Single element Array containing the result Hash.
458
+ def last_execution_result(test_case_id, build_id, plan_id)
459
+ args = { devKey: @dev_key, testplanid: plan_id,
460
+ testcaseid: test_case_id, buildid: build_id }
461
+ make_call("tl.getLastExecutionResult", args, "1.0b5")
462
+ end
463
+ alias_method :getLastExecutionResult, :last_execution_result
464
+
465
+ # Gets a list of builds within a test plan.
466
+ #
467
+ # @param [Fixnum,String] plan_id ID of the plan to get builds for.
468
+ # @return [Array<Hash>] List of all builds for the plan and their associated
469
+ # info.
470
+ def builds_for_test_plan plan_id
471
+ args = { devKey: @dev_key, testplanid: plan_id }
472
+ make_call("tl.getBuildsForTestPlan", args, "1.0b5")
473
+ end
474
+ alias_method :getBuildsForTestPlan, :builds_for_test_plan
475
+
476
+ # @param [Fixnum,String] plan_id ID of the plan to get build for.
477
+ # @return [Hash] Info for the latest build for the given test plan.
478
+ def latest_build_for_test_plan plan_id
479
+ args = { devKey: @dev_key, testplanid: plan_id }
480
+ make_call("tl.getLatestBuildForTestPlan", args, "1.0b5")
481
+ end
482
+ alias_method :getLatestBuildForTestPlan, :latest_build_for_test_plan
483
+
484
+ # @param [String] project_name
485
+ # @param [String] test_case_prefix
486
+ # @param [Hash] options
487
+ # @option options [String] notes
488
+ # @option options [Hash] options ALL int treated as boolean:
489
+ # requirementsEnabled, testPriorityEnabled, automationEnabled,
490
+ # inventoryEnabled
491
+ # @option options [Fixnum] active
492
+ # @option options [Fixnum] public
493
+ # @return
494
+ def create_test_project(project_name, test_case_prefix, options={})
495
+ args = { devKey: @dev_key, testprojectname: project_name,
496
+ testcaseprefix: test_case_prefix }
497
+ args.merge! options
498
+ make_call("tl.createTestProject", args, "1.0b5")
499
+ end
500
+ alias_method :createTestProject, :create_test_project
501
+
502
+ # @since TestLink API version 1.0
503
+ # @param [String] plan_name
504
+ # @param [String] project_name
505
+ # @param [Hash] options
506
+ # @option options [String] notes
507
+ # @option options [String] active Defaults to 1.
508
+ # @option options [String] public Defaults to 1.
509
+ # @return
510
+ def create_test_plan(plan_name, project_name, options={})
511
+ args = { devKey: @dev_key, testplanname: plan_name,
512
+ testprojectname: project_name }
513
+ args.merge! options
514
+ make_call('tl.createTestPlan', args, "1.0")
515
+ end
516
+ alias_method :createTestPlan, :create_test_plan
517
+
518
+ # @param [String] suite_name
519
+ # @param [String] details
520
+ # @param [Fixnum,String] project_id
521
+ # @param [Hash] options
522
+ # @option options [Fixnum,String] parentid Defaults to top level.
523
+ # @option options [Fixnum] order Order inside parent container.
524
+ # @option options [Boolean] checkduplicatedname Check if there siblings with
525
+ # the same name. Defaults to true.
526
+ # @option options [Boolean] actiononduplicatedname Applicable only if
527
+ # checkduplicatedname = true.
528
+ # @return [Array<Hash>] Info about results of test suite creation.
529
+ def create_test_suite(suite_name, details, project_id, options={})
530
+ args = { devKey: @dev_key, testprojectid: project_id,
531
+ testsuitename: suite_name, details: details }
532
+ args.merge! options
533
+ make_call('tl.createTestSuite', args, "1.0b5")
534
+ end
535
+ alias_method :createTestSuite, :create_test_suite
536
+
537
+ # Creates a new build for a specific test plan.
538
+ #
539
+ # @param [String] build_name
540
+ # @param [String] build_notes
541
+ # @param [Fixnum,String] plan_id
542
+ # @return
543
+ def create_build(build_name, build_notes, plan_id)
544
+ args = { devKey: @dev_key, testplanid: plan_id,
545
+ buildname: build_name, buildnotes: build_notes }
546
+ make_call("tl.createBuild", args, "1.0b5")
547
+ end
548
+ alias_method :createBuild, :create_build
549
+
550
+ # @param [String] test_case_name
551
+ # @param [String] test_case_summary
552
+ # @param [String] test_case_steps
553
+ # @param [String] test_case_expected_results
554
+ # @param [Fixnum,String] suite_id
555
+ # @param [Fixnum,String] project_id
556
+ # @param [String] login
557
+ # @param [Hash] options
558
+ # @option options [String] preconditions
559
+ # @option options [String] execution
560
+ # @option options [Fixnum] order
561
+ # @option options [Fixnum,String] internalid
562
+ # @option options [Boolean] checkduplicatedname
563
+ # @option options [String] actiononduplicatedname
564
+ # @option options [String] executiontype
565
+ # @return
566
+ def create_test_case(test_case_name, test_case_summary, test_case_steps,
567
+ test_case_expected_results, suite_id, project_id, login, options={})
568
+ args = { devKey: @dev_key,
569
+ testcasename: test_case_name,
570
+ testsuiteid: suite_id,
571
+ testprojectid: project_id,
572
+ authorlogin: login,
573
+ summary: test_case_summary,
574
+ steps: test_case_steps,
575
+ expectedresults: test_case_expected_results }
576
+ args.merge! options
577
+ make_call("tl.createTestCase", args, "1.0b5")
578
+ end
579
+ alias_method :createTestCase, :create_test_case
580
+
581
+ # Adds a test case version to a test plan.
582
+ #
583
+ # @param [Fixnum,String] test_case_external_id
584
+ # @param [Fixnum,String] test_case_version
585
+ # @param [Fixnum,String] plan_id
586
+ # @param [Fixnum,String] project_id
587
+ # @param [Hash] options Optional parameters for the method.
588
+ # @option options [String] urgency
589
+ # @option options [Fixnum] executionorder
590
+ # @option options [Fixnum] platformid Only if test plan has no platforms.
591
+ # (TestLink API >=1.0)
592
+ # @return
593
+ def add_test_case_to_test_plan(test_case_external_id, test_case_version,
594
+ plan_id, project_id, options={})
595
+ args = { devKey: @dev_key, testprojectid: project_id,
596
+ testplanid: plan_id, testcaseexternalid: test_case_external_id,
597
+ version: test_case_version }
598
+ args.merge! options
599
+ make_call("tl.addTestCaseToTestPlan", args, "1.0b5")
600
+ end
601
+ alias_method :addTestCaseToTestPlan, :add_test_case_to_test_plan
602
+
603
+ # Sets result in TestLink by test case ID and test plan ID.
604
+ # NOTE: will guess at last build, needs to be set to guarantee accuracy.
605
+ # NOTE: Renamed to setTestCaseExecutionResult in version 1.0.
606
+ #
607
+ # @see #test_case_execution_result=
608
+ # @version TestLink API version 1.0 Beta 5
609
+ # @param [Fixnum,String] test_case_id ID of the test case to post results to.
610
+ # @param [String] status 'p', 'f', 's', or 'b' for Pass/Fail/Skip/Block
611
+ # @param [Fixnum,String] plan_id ID of the test plan to post results to.
612
+ # @param [Hash] options
613
+ # @option options [Fixnum,String] buildid ID of the build to post results to.
614
+ # @option options [Fixnum,String] buildname Name of the build to post results to.
615
+ # @option options [Fixnum,String] bugid ID of the bug to link results to.
616
+ # @option options [Boolean] guess Defines whether to guess optional params
617
+ # or require them explicitly. Defaults to true.
618
+ # @option options [Fixnum,String] platformid ID of the platform to associate with the
619
+ # result. (TestLink API >=1.0)
620
+ # @option options [String] customfields i.e. "NAME: Steve Loveless\n"
621
+ # (TestLink API >=1.0)
622
+ # @option options [String] notes ?
623
+ # @return [Hash] "status" of posting, "id" of the execution, "message"
624
+ # giving success or failure info.
625
+ # @raise [TestLinker::Error] If result fails to be posted for any reason.
626
+ def report_test_case_result(test_case_id, status, plan_id, options={})
627
+ if @version >= "1.0"
628
+ message = "Method not supported in version #{@version}. "
629
+ message << "Use #test_case_execution_result="
630
+ raise TestLinker::Error, message
631
+ end
632
+
633
+ args = { devKey: @dev_key, testcaseid: test_case_id,
634
+ testplanid: plan_id, status: status, guess: true }
635
+ args.merge! options
636
+ result = @server.call("tl.reportTCResult", args).first
637
+
638
+ unless result['message'] == 'Success!'
639
+ raise TestLinker::Error, "#{result['code']}: #{result['message']}"
640
+ end
641
+
642
+ result
643
+ end
644
+ alias_method :reportTCResult, :report_test_case_result
645
+
646
+ # Sets result in TestLink by test case ID and test plan ID.
647
+ # NOTE: will guess at last build, needs to be set to guarantee accuracy.
648
+ #
649
+ # @see #report_test_case_result
650
+ # @since TestLink API version 1.0
651
+ # @param [String] test_case_id ID of the test case to post results to.
652
+ # @param [String] status 'p', 'f', 's', or 'b' for Pass/Fail/Skip/Block
653
+ # @param [String] plan_id ID of the test plan to post results to.
654
+ # @param [Hash] options
655
+ # @option options [Fixnum] buildid ID of the build to post results to.
656
+ # @option options [String] buildname Name of the build to post results to.
657
+ # @option options [Fixnum] bugid ID of the bug to link results to.
658
+ # @option options [Boolean] guess Defines whether to guess optinal params or require them.
659
+ # @option options [String] notes ?
660
+ # @option options [String] platformid (version 1.0)
661
+ # @option options [String] platformid (version 1.0)
662
+ # @option options [String] customfields (version 1.0)
663
+ # @option options [String] overwrite (version 1.0)
664
+ # @return [Hash] "status" of posting, "id" of the execution, "message"
665
+ # giving success or failure info.
666
+ # @raise [TestLinker::Error] If result fails to be posted for any reason.
667
+ def test_case_execution_result=(test_case_id, status, plan_id, options={})
668
+ if @version < "1.0"
669
+ message = "Method not supported in version #{@version}. "
670
+ message << "Use #report_test_case_result"
671
+ raise TestLinker::Error, message
672
+ end
673
+
674
+ args = { devKey: @dev_key, testcaseid: test_case_id,
675
+ testplanid: plan_id, status: status, guess: true }
676
+ args.merge! options
677
+ result = @server.call("tl.setTestCaseExecutionResult", args).first
678
+
679
+ unless result['message'] == 'Success!'
680
+ raise TestLinker::Error, "#{result['code']}: #{result['message']}"
681
+ end
682
+
683
+ result
684
+ end
685
+ alias_method :setTestCaseExecutionResult, :test_case_execution_result=
686
+ end
687
+ end