line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TestLink::API; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$TestLink::API::VERSION = '0.009'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
TestLink::API - Provides an interface to TestLink's XMLRPC api via HTTP |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use TestLink::API; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $tl = TestLink::API->new('http://tl.test/testlink/lib/api/xmlrpc/v1/xmlrpc.php', 'gobbledygook123'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#Look up test definitions |
18
|
|
|
|
|
|
|
my $projects = $tl->getProjects(); |
19
|
|
|
|
|
|
|
my $suites = $tl->getTLDTestSuitesForProject($projects->[0]->{'id'}); |
20
|
|
|
|
|
|
|
my $childsuites = $tl->getTestSuitesForTestSuite($suites->[0]->{'id'}); |
21
|
|
|
|
|
|
|
my $tests = $tl->getTestCasesForTestSuite($childsuites->[0]->{'id'}); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#Look up test plans/builds |
24
|
|
|
|
|
|
|
my $plans = $tl->getTestPlansForProject($projects->[0]->{'id'}); |
25
|
|
|
|
|
|
|
my $tests2 = $tl->getTestCasesForTestPlan($plans->[0]->{'id'}); |
26
|
|
|
|
|
|
|
my $builds = $tl->getBuildsForTestPlan($plans->[0]->{'id'}); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#Set results |
29
|
|
|
|
|
|
|
my $testResults = doSomethingReturningBoolean(); |
30
|
|
|
|
|
|
|
my $results = $tl->reportTCResult($tests2->[0]->{'id'},$plans->[0]->{'id'},$builds->[0]->{'id'}, $testResults ? 'p' : 'f'); |
31
|
|
|
|
|
|
|
$tl->uploadExecutionAttachment($results->{'id'},'test.txt','text/plain',encode_base64('MOO MOO MOOOOOO'),'bovine emissions','whee') |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
C provides methods to access an existing TestLink account. You can then do things like look up tests, set statuses and create builds from lists of tests. |
36
|
|
|
|
|
|
|
The getter methods cache the test tree up to whatever depth is required by your getter calls. This is to speed up automated creation/reading/setting of the test db based on existing automated tests. |
37
|
|
|
|
|
|
|
Cache expires at the end of script execution. (TODO memcache controlled by constructor, with create methods invalidating cache?) |
38
|
|
|
|
|
|
|
Getter/setter methods that take args assume that the relevant project/testsuite/test/plan/build provided exists (TODO: use cache to check exists, provide more verbose error reason...), and returns false if not. |
39
|
|
|
|
|
|
|
Create methods assume desired entry provided is not already in the DB (TODO (again): use cache to check exists, provide more verbose error reason...), and returns false if not. |
40
|
|
|
|
|
|
|
It is by no means exhaustively implementing every TestLink API function. Designed with TestLink 1.9.9, but will likely work on (some) other versions. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
2
|
|
75395
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
85
|
|
46
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
47
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
172
|
|
48
|
2
|
|
|
2
|
|
12
|
use Scalar::Util qw{reftype looks_like_number}; #boo, some functions return hashes and arrays depending on # of results (1 or many) |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
225
|
|
49
|
2
|
|
|
2
|
|
1416
|
use Data::Validate::URI 'is_uri'; |
|
2
|
|
|
|
|
100600
|
|
|
2
|
|
|
|
|
123
|
|
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
2
|
|
944
|
use Clone 'clone'; |
|
2
|
|
|
|
|
1046
|
|
|
2
|
|
|
|
|
96
|
|
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
2
|
|
1769
|
use XMLRPC::Lite; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 B |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Creates new C object. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item C - URL to your testlink API endpoint. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item C - TestLink API key. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Returns C object if login is successful. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $tl = TestLink::API->new('http://tl.test/testlink/lib/api/xmlrpc/v1/xmlrpc.php', 'gobbledygook123'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
76
|
|
|
|
|
|
|
my ($class,$apiurl,$apikey) = @_; |
77
|
|
|
|
|
|
|
confess("Constructor must be called statically, not by an instance") if ref($class); |
78
|
|
|
|
|
|
|
$apiurl ||= $ENV{'TESTLINK_SERVER_ADDR'}; |
79
|
|
|
|
|
|
|
$apikey ||= $ENV{'TESTLINK_API_KEY'}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
confess("No API key provided.") if !$apiurl; |
82
|
|
|
|
|
|
|
confess("No API URL provided.") if !$apikey; |
83
|
|
|
|
|
|
|
confess("API URL provided not valid.") unless is_uri($apiurl); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $self = { |
86
|
|
|
|
|
|
|
apiurl => $apiurl, |
87
|
|
|
|
|
|
|
apikey => $apikey, |
88
|
|
|
|
|
|
|
testtree => [], |
89
|
|
|
|
|
|
|
flattree => [], |
90
|
|
|
|
|
|
|
invalidate_cache => 1 #since we don't have a cache right now... #TODO this should be granular down to project rather than global |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
bless $self, $class; |
94
|
|
|
|
|
|
|
return $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 PROPERTIES |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
apiurl and apikey can be accessed/set: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$url = $tl->apiurl; |
104
|
|
|
|
|
|
|
$tl = $tl->apiurl('http//some.new.url/foo.php'); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#EZ get/set of obj vars |
111
|
|
|
|
|
|
|
sub AUTOLOAD { |
112
|
|
|
|
|
|
|
my %public_elements = map {$_,1} qw{apiurl apikey}; #Public element access |
113
|
|
|
|
|
|
|
our $AUTOLOAD; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
if ($AUTOLOAD =~ /::(\w+)$/ and exists $public_elements{$1} ) { |
116
|
|
|
|
|
|
|
my $field = $1; |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
no strict 'refs'; |
119
|
|
|
|
|
|
|
*{$AUTOLOAD} = sub { |
120
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($_[0]); |
121
|
|
|
|
|
|
|
return $_[0]->{$field} unless defined $_[1]; |
122
|
|
|
|
|
|
|
$_[0]->{$field} = $_[1]; |
123
|
|
|
|
|
|
|
return $_[0]; |
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
goto &{$AUTOLOAD}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
confess("$AUTOLOAD not accessible property") unless $AUTOLOAD =~ /DESTROY$/; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 CREATE METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 B |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Creates new Test plan with given name in the given project. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item STRING C - Desired test plan name. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item STRING C - The name of some project existing in TestLink. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item STRING C (optional) - Additional description of test plan. Default value is 'res ipsa loquiter' |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - Whether or not the test plan is active. Default value is true. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - Whether or not the test plan is public. Default is true. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Returns (integer) test plan ID if creation is successful. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $tpid = $tl->createTestPlan('shock&awe', 'enduringfreedom'); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub createTestPlan { |
158
|
|
|
|
|
|
|
my ($self,$name,$project,$notes,$active,$public) = @_; |
159
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
confess("Desired Test Plan Name is a required argument (0th).") if !$name; |
162
|
|
|
|
|
|
|
confess("Parent Project Name is a required argument (1st).") if !$project; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$notes ||= 'res ipsa loquiter'; |
165
|
|
|
|
|
|
|
$active ||= 1; |
166
|
|
|
|
|
|
|
$public ||= 1; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $input = { |
169
|
|
|
|
|
|
|
devKey => $self->apikey, |
170
|
|
|
|
|
|
|
testplanname => $name, |
171
|
|
|
|
|
|
|
testprojectname => $project, |
172
|
|
|
|
|
|
|
notes => $notes, |
173
|
|
|
|
|
|
|
active => $active, |
174
|
|
|
|
|
|
|
public => $public |
175
|
|
|
|
|
|
|
}; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
178
|
|
|
|
|
|
|
my $result = $rpc->call('tl.createTestPlan',$input); |
179
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
180
|
|
|
|
|
|
|
return $result->result->[0]->{'id'} if $result->result->[0]->{'id'}; |
181
|
|
|
|
|
|
|
return 0; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 B |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Creates new 'Build' (test run in common parlance) from given test plan having given name and notes. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=over 4 |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item INTEGER C - ID of test plan to base test run on. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item STRING C - Desired name for test run. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item STRING C (optional) - Additional description of run. Default value is 'res ipsa loquiter'. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=back |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Returns true if case addition is successful, false otherwise. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$tl->createBuild(1234, "Bossin' up", 'Crushing our enemies, seeing them driven before us and hearing the lamentations of their support engineers.'); |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub createBuild { |
205
|
|
|
|
|
|
|
my ($self,$plan_id,$name,$notes) = @_; |
206
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
207
|
|
|
|
|
|
|
confess("Plan ID must be integer") unless looks_like_number($plan_id); |
208
|
|
|
|
|
|
|
confess("Build name is a required argument (1st)") if !$name; |
209
|
|
|
|
|
|
|
$notes ||= 'res ipsa loquiter'; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
my $input = { |
212
|
|
|
|
|
|
|
devKey => $self->apikey, |
213
|
|
|
|
|
|
|
testplanid => $plan_id, |
214
|
|
|
|
|
|
|
buildname => $name, |
215
|
|
|
|
|
|
|
buildnotes => $notes |
216
|
|
|
|
|
|
|
}; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
219
|
|
|
|
|
|
|
my $result = $rpc->call('tl.createBuild',$input); |
220
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
221
|
|
|
|
|
|
|
return $result->result->[0]->{'id'} if $result->result->[0]->{'id'}; |
222
|
|
|
|
|
|
|
return 0; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 B |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Creates new TestSuite (folder of tests) in the database of test specifications under given project id having given name and details. |
228
|
|
|
|
|
|
|
Optionally, can have a parent test suite (this is an analog to a hierarchical file tree after all) and what order to have this suite be amongst it's peers. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over 4 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item INTEGER C - ID of project this test suite should be under. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item STRING C - Desired name of test suite. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item STRING C (optional) - Description of test suite. Default value is 'res ipsa loquiter'. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item INTEGER C (optional) - Parent test suite ID. Defaults to top level of project. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item INTEGER C (optional) - Desired order amongst peer testsuites. Defaults to last in list. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=back |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Returns (integer) build ID on success, false otherwise. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
$tl->createTestSuite(1, 'broken tests', 'Tests that should be reviewed', 2345, -1); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub createTestSuite { |
251
|
|
|
|
|
|
|
my ($self,$project_id,$name,$details,$parent_id,$order) = @_; |
252
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
253
|
|
|
|
|
|
|
confess("Parent Project ID (arg 0) must be an integer") unless looks_like_number($project_id); |
254
|
|
|
|
|
|
|
confess("Name (arg 1) cannot be undefined") unless $name; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
$details ||= 'res ipsa loquiter'; |
257
|
|
|
|
|
|
|
$order ||= -1; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
my $input = { |
260
|
|
|
|
|
|
|
devKey => $self->apikey, |
261
|
|
|
|
|
|
|
testprojectid => $project_id, |
262
|
|
|
|
|
|
|
testsuitename => $name, |
263
|
|
|
|
|
|
|
details => $details, |
264
|
|
|
|
|
|
|
parentid => $parent_id, |
265
|
|
|
|
|
|
|
order => $order |
266
|
|
|
|
|
|
|
}; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
269
|
|
|
|
|
|
|
my $result = $rpc->call('tl.createTestSuite',$input); |
270
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
271
|
|
|
|
|
|
|
$self->{'invalidate_cache'} = 1 if $result->result->[0]->{'id'}; |
272
|
|
|
|
|
|
|
return $result->result->[0]->{'id'} if $result->result->[0]->{'id'}; |
273
|
|
|
|
|
|
|
return 0; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 B |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Creates new Project (Database of testsuites/tests) with given name and case prefix. |
279
|
|
|
|
|
|
|
Optionally, can have notes, options, set the project as active/inactive and public/private. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=over 4 |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item STRING C - Desired name of project. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item STRING C - Desired prefix of project's external test case IDs. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item STRING C (optional) - Description of project. Default value is 'res ipsa loquiter'. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item HASHREF{BOOLEAN} C (optional) - Hash with keys: requirementsEnabled,testPriorityEnabled,automationEnabled,inventoryEnabled. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - Whether to mark the project active or not. Default True. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - Whether the project is public or not. Default true. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=back |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Returns (integer) project ID on success, false otherwise. |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
$tl->createTestProject('Widgetronic 4000', 'Tests for the whiz-bang new product', {'inventoryEnabled=>true}, true, true); |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=cut |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
#XXX probably should not use |
304
|
|
|
|
|
|
|
sub createTestProject { |
305
|
|
|
|
|
|
|
my ($self,$name,$case_prefix,$notes,$options,$active,$public) = @_; |
306
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
307
|
|
|
|
|
|
|
$notes //= 'res ipsa loquiter'; |
308
|
|
|
|
|
|
|
$options //= {}; |
309
|
|
|
|
|
|
|
$public //= 1; |
310
|
|
|
|
|
|
|
$active //= 1; |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
my $input = { |
313
|
|
|
|
|
|
|
devKey => $self->apikey, |
314
|
|
|
|
|
|
|
testprojectname => $name, |
315
|
|
|
|
|
|
|
testcaseprefix => $case_prefix, |
316
|
|
|
|
|
|
|
notes => $notes, |
317
|
|
|
|
|
|
|
options => $options, |
318
|
|
|
|
|
|
|
active => $active, |
319
|
|
|
|
|
|
|
public => $public |
320
|
|
|
|
|
|
|
}; |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
323
|
|
|
|
|
|
|
my $result = $rpc->call('tl.createTestProject',$input); |
324
|
|
|
|
|
|
|
#XXX i'm being very safe (haha), there's probably a better check |
325
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
326
|
|
|
|
|
|
|
$self->{'invalidate_cache'} = 1 if $result->result->[0]->{'id'}; |
327
|
|
|
|
|
|
|
return $result->result->[0]->{'id'} if $result->result->[0]->{'id'}; |
328
|
|
|
|
|
|
|
return 0; |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head2 B |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
Creates new test case with given test suite id and project id. |
335
|
|
|
|
|
|
|
Author, Summary and Steps are mandatory for reasons that should be obvious to any experienced QA professional. |
336
|
|
|
|
|
|
|
Execution type and Test order is optional. |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=over 4 |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=item STRING C - Desired name of test case. |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=item INTEGER C - ID of parent test suite. |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=item INTEGER C - ID of parent project |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=item STRING C - Author of test case. |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=item STRING C - Summary of test case. |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=item STRING C - Test steps. |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=item STRING C - Prereqs for running the test, if any. |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=item STRING C (optional) - Execution type. Defaults to 'manual'. |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=item INTEGER C (optional) - Order of test amongst peers. |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
=back |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
Returns (HASHREF) with Test Case ID and Test Case External ID on success, false otherwise. |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
$tl->createTestCase('Verify Whatsit Throbs at correct frequency', 123, 456, 'Gnaeus Pompieus Maximus', 'Make sure throbber on Whatsit doesn't work out of harmony with other throbbers', '1. Connect measurement harness. 2. ??? 3. PROFIT!', 'automated', 2); |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=cut |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
sub createTestCase { |
367
|
|
|
|
|
|
|
my ($self,$test_name,$test_suite_id,$test_project_id,$author_name,$summary,$steps,$preconditions,$execution,$order) = @_; |
368
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
my $input = { |
371
|
|
|
|
|
|
|
devKey => $self->apikey, |
372
|
|
|
|
|
|
|
testcasename => $test_name, |
373
|
|
|
|
|
|
|
testsuiteid => $test_suite_id, |
374
|
|
|
|
|
|
|
testprojectid => $test_project_id, |
375
|
|
|
|
|
|
|
authorlogin => $author_name, |
376
|
|
|
|
|
|
|
summary => $summary, |
377
|
|
|
|
|
|
|
steps => $steps, |
378
|
|
|
|
|
|
|
preconditions => $preconditions, |
379
|
|
|
|
|
|
|
execution => $execution, |
380
|
|
|
|
|
|
|
order => $order |
381
|
|
|
|
|
|
|
}; |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
384
|
|
|
|
|
|
|
my $result = $rpc->call('tl.createTestCase',$input); |
385
|
|
|
|
|
|
|
#XXX i'm being very safe (haha), there's probably a better check |
386
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
387
|
|
|
|
|
|
|
return $result->result->[0] if $result->result->[0]->{'id'}; |
388
|
|
|
|
|
|
|
return 0; |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
=head1 SETTER METHODS |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=head2 B |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
Report results of a test case with a given ID, plan and build ID. Set case results to status given. |
397
|
|
|
|
|
|
|
Platform is mandatory if available, otherwise optional. |
398
|
|
|
|
|
|
|
Notes and Bug Ids for whatever tracker you use are optional. |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=over 4 |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=item INTEGER C - Desired test case. |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=item INTEGER C - ID of relevant test plan. |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=item INTEGER C - ID of relevant build. |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
=item STRING C - Desired Test Status Code. Codes not documented anywhere but in your cfg/const.inc.php of the TestLink Install. |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
=item STRING C (semi-optional) - Relevant platform tested on. Accepts both platform name and ID, if it looks_like_number, uses platform_id |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=item STRING C (optional) - Relevant information gleaned during testing process. |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=item STRING C (optional) - Relevant bug ID for regression tests, or if you auto-open bugs based on failures. |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=back |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
Returns project ID on success, false otherwise. |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
$tl->reportTCResult('T-1000', 7779311, 8675309, 'Tool Failure', 'Skynet Infiltration Model 1000', 'Catastrophic systems failure due to falling into vat of molten metal' 'TERMINATOR-2'); |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=cut |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub reportTCResult { |
425
|
|
|
|
|
|
|
my ($self,$case_id,$plan_id,$build_id,$status,$platform,$notes,$bugid) = @_; |
426
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
my $input = { |
429
|
|
|
|
|
|
|
devKey => $self->apikey, |
430
|
|
|
|
|
|
|
testcaseid => $case_id, |
431
|
|
|
|
|
|
|
testplanid => $plan_id, |
432
|
|
|
|
|
|
|
buildid => $build_id, |
433
|
|
|
|
|
|
|
status => $status, |
434
|
|
|
|
|
|
|
notes => $notes, |
435
|
|
|
|
|
|
|
bugid => $bugid |
436
|
|
|
|
|
|
|
}; |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
if (defined($platform) && !ref $platform) { |
439
|
|
|
|
|
|
|
if (looks_like_number($platform)) { |
440
|
|
|
|
|
|
|
$input->{'platformid'} = $platform; |
441
|
|
|
|
|
|
|
} else { |
442
|
|
|
|
|
|
|
$input->{'platformname'} = $platform; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
447
|
|
|
|
|
|
|
my $result = $rpc->call('tl.reportTCResult',$input); |
448
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
449
|
|
|
|
|
|
|
return $result->result->[0] unless $result->result->[0]->{'code'}; |
450
|
|
|
|
|
|
|
return 0; |
451
|
|
|
|
|
|
|
} |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=head2 B |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
Creates new Test plan with given name in the given project. |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
=over 4 |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=item INTEGER C - Desired test plan. |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=item STRING C - The 'external' name of some existing test in TestLink, e.g. TP-12. |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
=item INTEGER C - The ID of some project in testlink |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
=item INTEGER C - The desired version of the test to add. |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=item STRING C (semi-optional) - The name of the desired platform to run on for this test (if any). |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
=item INTEGER C (optional) - The order in which to execute this test amongst it's peers. |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
=item INTEGER C (optional) - The priority of the case in the plan. |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=back |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
Returns true if case addition is successful. |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
$tl->addTestCaseToTestPlan(666, 'cp-90210', 121, '3.11', 'OS2/WARP', 3, 1); |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
=cut |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
#XXX this should be able to be done in batch |
482
|
|
|
|
|
|
|
sub addTestCaseToTestPlan { |
483
|
|
|
|
|
|
|
my ($self,$plan_id,$case_id,$project_id,$version,$platform,$order,$urgency) = @_; |
484
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
my $input = { |
487
|
|
|
|
|
|
|
devKey => $self->apikey, |
488
|
|
|
|
|
|
|
testplanid => $plan_id, |
489
|
|
|
|
|
|
|
testcaseexternalid => $case_id, |
490
|
|
|
|
|
|
|
testprojectid => $project_id, |
491
|
|
|
|
|
|
|
version => $version, |
492
|
|
|
|
|
|
|
platformid => $platform, |
493
|
|
|
|
|
|
|
executionorder => $order, |
494
|
|
|
|
|
|
|
urgency => $urgency |
495
|
|
|
|
|
|
|
}; |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
498
|
|
|
|
|
|
|
my $result = $rpc->call('tl.addTestCaseToTestPlan',$input); |
499
|
|
|
|
|
|
|
warn $result->result->{'message'} if $result->result->{'code'}; |
500
|
|
|
|
|
|
|
return 1 unless $result->result->{'code'}; |
501
|
|
|
|
|
|
|
return 0; |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=head2 B |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
Uploads the provided file and associates it with the given execution. |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=over 4 |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=item INTEGER C - ID of a successful execution, such as the id key from the hash that is returned by reportTCResult. |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=item STRING C - The name you want this file to appear as. |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=item INTEGER C - The mimetype of the file uploaded, so we can tell the browser what to do with it when downloaded |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=item INTEGER C - The base64 encoded content of the file you want to upload. |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=item STRING C (optional) - A title for this attachment. |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=item INTEGER C (optional) - A short description of who/what/why this was attached. |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=back |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
Returns true if attachment addition is successful. |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
$tl->uploadExecutionAttachment(1234, 'moo.txt', 'text/cow', APR::Base64::encode('MOO MOO MOOOOOO'), 'MOO', 'Test observed deranged bleatings of domestic ungulates, please investigate.'); |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
=cut |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
sub uploadExecutionAttachment { |
531
|
|
|
|
|
|
|
my ($self,$execution_id,$filename,$filetype,$content,$title,$description) = @_; |
532
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
my $input = { |
535
|
|
|
|
|
|
|
devKey => $self->apikey, |
536
|
|
|
|
|
|
|
executionid => $execution_id, |
537
|
|
|
|
|
|
|
title => $title, |
538
|
|
|
|
|
|
|
description => $description, |
539
|
|
|
|
|
|
|
filename => $filename, |
540
|
|
|
|
|
|
|
filetype => $filetype, |
541
|
|
|
|
|
|
|
content => $content |
542
|
|
|
|
|
|
|
}; |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
545
|
|
|
|
|
|
|
my $result = $rpc->call('tl.uploadExecutionAttachment',$input); |
546
|
|
|
|
|
|
|
warn $result->result->{'message'} if $result->result->{'code'}; |
547
|
|
|
|
|
|
|
return 1 unless $result->result->{'code'}; |
548
|
|
|
|
|
|
|
return 0; |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=head2 B |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
Uploads the provided file and associates it with the given execution. |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
=over 4 |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
=item INTEGER C - ID of desired test case |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
=item STRING C - The name you want this file to appear as. |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
=item INTEGER C - The mimetype of the file uploaded, so we can tell the browser what to do with it when downloaded |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
=item INTEGER C - The base64 encoded content of the file you want to upload. |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
=item STRING C (optional) - A title for this attachment. |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
=item INTEGER C (optional) - A short description of who/what/why this was attached. |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
=back |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
Returns true if attachment addition is successful. |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
$tl->uploadTestCaseAttachment(1234, 'doStuff.t', 'text/perl', APR::Base64::encode($slurped_file_content), 'doStuff.t', 'Test File.'); |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
=cut |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
sub uploadTestCaseAttachment { |
578
|
|
|
|
|
|
|
my ($self,$case_id,$filename,$filetype,$content,$title,$description) = @_; |
579
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
my $input = { |
582
|
|
|
|
|
|
|
devKey => $self->apikey, |
583
|
|
|
|
|
|
|
testcaseid => $case_id, |
584
|
|
|
|
|
|
|
title => $title, |
585
|
|
|
|
|
|
|
description => $description, |
586
|
|
|
|
|
|
|
filename => $filename, |
587
|
|
|
|
|
|
|
filetype => $filetype, |
588
|
|
|
|
|
|
|
content => $content |
589
|
|
|
|
|
|
|
}; |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
592
|
|
|
|
|
|
|
my $result = $rpc->call('tl.uploadTestCaseAttachment',$input); |
593
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
594
|
|
|
|
|
|
|
return 1 unless $result->result->[0]->{'code'}; |
595
|
|
|
|
|
|
|
return 0; |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
=head1 GETTER METHODS |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=head2 B |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
Get all available projects |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
Returns array of project definition hashes, false otherwise. |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
$projects = $tl->getProjects; |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=cut |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
sub getProjects { |
612
|
|
|
|
|
|
|
my $self = shift; |
613
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
my $input = { |
616
|
|
|
|
|
|
|
devKey => $self->apikey |
617
|
|
|
|
|
|
|
}; |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
620
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getProjects',$input); |
621
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
#Save state for future use, if needed |
624
|
|
|
|
|
|
|
if (!scalar(@{$self->{'testtree'}})) { |
625
|
|
|
|
|
|
|
$self->{'testtree'} = $result->result unless $result->result->[0]->{'code'}; |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
if (!exists($result->result->[0]->{'code'})) { |
629
|
|
|
|
|
|
|
#Note that it's a project for future reference by recursive tree search |
630
|
|
|
|
|
|
|
for my $pj (@{$result->result}) { |
631
|
|
|
|
|
|
|
$pj->{'type'} = 'project'; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
return $result->result; |
634
|
|
|
|
|
|
|
} |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
return 0; |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
=head2 B |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
Gets some project definition hash by it's name |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
=over 4 |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=item STRING C - desired project |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=back |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
Returns desired project def hash, false otherwise. |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
$projects = $tl->getProjectByName('FunProject'); |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
=cut |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
sub getProjectByName { |
656
|
|
|
|
|
|
|
my ($self,$project) = @_; |
657
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
658
|
|
|
|
|
|
|
confess "No project provided." unless $project; |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
#See if we already have the project list... |
661
|
|
|
|
|
|
|
my $projects = $self->{'testtree'}; |
662
|
|
|
|
|
|
|
$projects = $self->getProjects() unless scalar(@$projects); |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
#Search project list for project |
665
|
|
|
|
|
|
|
for my $candidate (@$projects) { |
666
|
|
|
|
|
|
|
return $candidate if ($candidate->{'name'} eq $project); |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
return 0; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
=head2 B |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
Gets some project definition hash by it's ID |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
=over 4 |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=item INTEGER C - desired project |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
=back |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
Returns desired project def hash, false otherwise. |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
$projects = $tl->getProjectByID(222); |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
=cut |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
sub getProjectByID { |
689
|
|
|
|
|
|
|
my ($self,$project) = @_; |
690
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
691
|
|
|
|
|
|
|
confess "No project provided." unless $project; |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
#See if we already have the project list... |
694
|
|
|
|
|
|
|
my $projects = $self->{'testtree'}; |
695
|
|
|
|
|
|
|
$projects = $self->getProjects() unless scalar(@$projects); |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
#Search project list for project |
698
|
|
|
|
|
|
|
for my $candidate (@$projects) { |
699
|
|
|
|
|
|
|
return $candidate if ($candidate->{'id'} eq $project); |
700
|
|
|
|
|
|
|
} |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
return 0; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=head2 B |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
Gets the testsuites in the top level of a project |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
=over 4 |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=item STRING C - desired project's ID |
713
|
|
|
|
|
|
|
=item BOOLEAN C - Get tests for suites returned, set them as 'tests' key in hash |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
=back |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
Returns desired testsuites' definition hashes, 0 on error and -1 when there is no such project. |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
$projects = $tl->getTLDTestSuitesForProject(123); |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
=cut |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
sub getTLDTestSuitesForProject { |
724
|
|
|
|
|
|
|
my ($self,$project,$get_tests) = @_; |
725
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
726
|
|
|
|
|
|
|
confess "No project ID provided." unless $project; |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
my $input = { |
729
|
|
|
|
|
|
|
devKey => $self->apikey, |
730
|
|
|
|
|
|
|
testprojectid => $project |
731
|
|
|
|
|
|
|
}; |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
734
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getFirstLevelTestSuitesForTestProject',$input); |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
#Error condition, return right away |
737
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
738
|
|
|
|
|
|
|
return [] if $result->result->[0]->{'code'}; |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
#Handle bizarre output |
741
|
|
|
|
|
|
|
if ($result->result && !(reftype($result->result) eq 'HASH' || reftype($result->result) eq 'ARRAY')) { |
742
|
|
|
|
|
|
|
return []; |
743
|
|
|
|
|
|
|
} |
744
|
|
|
|
|
|
|
return [] if !$result->result; |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
#Handle mixed return type for this function -- this POS will return arrayrefs, and 2 types of hashrefs. |
747
|
|
|
|
|
|
|
my $res = []; |
748
|
|
|
|
|
|
|
$res = $result->result if reftype($result->result) eq 'ARRAY'; |
749
|
|
|
|
|
|
|
@$res = values(%{$result->result}) if reftype($result->result) eq 'HASH' && !defined($result->result->{'id'}); |
750
|
|
|
|
|
|
|
$res = [$result->result] if reftype($result->result) eq 'HASH' && defined($result->result->{'id'}); |
751
|
|
|
|
|
|
|
return [] if (!scalar(keys(%{$res->[0]}))); #Catch bizarre edge case of blank hash being only thing there |
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
if ($get_tests) { |
754
|
|
|
|
|
|
|
for (my $i=0; $i < scalar(@{$result->result}); $i++) { |
755
|
|
|
|
|
|
|
$result->result->[$i]->{'tests'} = $self->getTestCasesForTestSuite($result->result->[$i]->{'id'},0,1); |
756
|
|
|
|
|
|
|
} |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
return $result->result; |
760
|
|
|
|
|
|
|
} |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
=head2 B |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
Gets the testsuites that are children of the provided testsuite. |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
=over 4 |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=item STRING C - desired parent testsuite ID |
769
|
|
|
|
|
|
|
=item STRING C - whether to get child tests as well |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
=back |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
Returns desired testsuites' definition hashes, false otherwise. |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
$suites = $tl->getTestSuitesForTestSuite(123); |
776
|
|
|
|
|
|
|
$suitesWithCases = $tl->getTestSuitesForTestSuite(123,1); |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
=cut |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
sub getTestSuitesForTestSuite { |
781
|
|
|
|
|
|
|
my ($self,$tsid,$get_tests) = @_; |
782
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
783
|
|
|
|
|
|
|
confess "No TestSuite ID provided." unless $tsid; |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
my $input = { |
786
|
|
|
|
|
|
|
devKey => $self->apikey, |
787
|
|
|
|
|
|
|
testsuiteid => $tsid |
788
|
|
|
|
|
|
|
}; |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
791
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestSuitesForTestSuite',$input); |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
#Handle bizarre output |
794
|
|
|
|
|
|
|
if ($result->result && !(reftype($result->result) eq 'HASH' || reftype($result->result) eq 'ARRAY')) { |
795
|
|
|
|
|
|
|
return []; |
796
|
|
|
|
|
|
|
} |
797
|
|
|
|
|
|
|
return [] if !$result->result; |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
#Handle mixed return type for this function -- this POS will return arrayrefs, and 2 types of hashrefs. |
800
|
|
|
|
|
|
|
my $res = []; |
801
|
|
|
|
|
|
|
$res = $result->result if reftype($result->result) eq 'ARRAY'; |
802
|
|
|
|
|
|
|
@$res = values(%{$result->result}) if reftype($result->result) eq 'HASH' && !defined($result->result->{'id'}); |
803
|
|
|
|
|
|
|
$res = [$result->result] if reftype($result->result) eq 'HASH' && defined($result->result->{'id'}); |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
if ($get_tests) { |
806
|
|
|
|
|
|
|
foreach my $row (@$res) { |
807
|
|
|
|
|
|
|
$row->{'tests'} = $self->getTestCasesForTestSuite($row->{'id'},0,1); |
808
|
|
|
|
|
|
|
} |
809
|
|
|
|
|
|
|
} |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
#Error condition, return false and don't bother searching arrays |
812
|
|
|
|
|
|
|
warn $res->{'message'} if $res->[0]->{'code'}; |
813
|
|
|
|
|
|
|
return [] if $res->[0]->{'code'}; |
814
|
|
|
|
|
|
|
return $res; |
815
|
|
|
|
|
|
|
} |
816
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
=head2 B |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
Gets the testsuite(s) that match given name inside of given project name. |
821
|
|
|
|
|
|
|
WARNING: this will slurp the enitre testsuite tree. This can take a while on large projects, but the results are cached so that subsequent calls are not as onerous. |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
=over 4 |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
=item STRING C - ID of project holding this testsuite |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
=item STRING C - desired parent testsuite name |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - whether or not PROJECT NAME is a regex (default false, uses 'eq' to compare). |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
=back |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
Returns desired testsuites' definition hashes, false otherwise. |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
$suites = $tl->getTestSuitesByName(321, 'hugSuite'); |
836
|
|
|
|
|
|
|
$suitesr = $tl->getTestSuitesByName(123, qr/^hug/, 1); |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
=cut |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
sub getTestSuitesByName { |
841
|
|
|
|
|
|
|
my ($self,$project_id,$testsuite_name,$do_regex) = @_; |
842
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
843
|
|
|
|
|
|
|
return 0 if (!$project_id || !$testsuite_name); #GIGO |
844
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
#use caching methods here to speed up subsequent calls |
846
|
|
|
|
|
|
|
$self->_cacheProjectTree($project_id,1,1,0) if $self->{'invalidate_cache'}; |
847
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
#my $tld = $self->getTLDTestSuitesForProject($project_id); |
849
|
|
|
|
|
|
|
my $candidates = []; |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
#Walk the whole tree. No other way to be sure. |
852
|
|
|
|
|
|
|
foreach my $ts (@{$self->{'flattree'}}) { |
853
|
|
|
|
|
|
|
if ($do_regex) { |
854
|
|
|
|
|
|
|
push(@$candidates,$ts) if $ts->{'name'} =~ $testsuite_name; |
855
|
|
|
|
|
|
|
} else { |
856
|
|
|
|
|
|
|
push(@$candidates,$ts) if $ts->{'name'} eq $testsuite_name; |
857
|
|
|
|
|
|
|
} |
858
|
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
|
return $candidates; |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
} |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
=head2 B |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
Gets the testsuite with the given ID. |
866
|
|
|
|
|
|
|
|
867
|
|
|
|
|
|
|
=over 4 |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
=item STRING C - Testsuite ID. |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
=back |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
Returns desired testsuite definition hash, false otherwise. |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
$tests = $tl->getTestSuiteByID(123); |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
=cut |
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
sub getTestSuiteByID { |
880
|
|
|
|
|
|
|
my ($self,$testsuite_id) = @_; |
881
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
my $input = { |
884
|
|
|
|
|
|
|
devKey => $self->apikey, |
885
|
|
|
|
|
|
|
testsuiteid => $testsuite_id |
886
|
|
|
|
|
|
|
}; |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
889
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestSuiteByID',$input); |
890
|
|
|
|
|
|
|
warn $result->result->{'message'} if $result->result->{'code'}; |
891
|
|
|
|
|
|
|
return $result->result unless $result->result->{'code'}; |
892
|
|
|
|
|
|
|
return 0; |
893
|
|
|
|
|
|
|
} |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
=head2 B |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
Gets the testsuites that match given name inside of given project name. |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
=over 4 |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
=item STRING C - Testsuite ID. |
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
=item BOOLEAN C - Search testsuite tree recursively for tests below the provided testsuite |
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - whether or not to return more detailed test info (steps,summary,expected results). Defaults to false. |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
=back |
908
|
|
|
|
|
|
|
|
909
|
|
|
|
|
|
|
Returns desired case definition hashes, false otherwise. |
910
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
$tests = $tl->getTestCasesForTestSuite(123,1,1); |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
=cut |
914
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
sub getTestCasesForTestSuite { |
916
|
|
|
|
|
|
|
my ($self,$testsuite_id,$deep,$details) = @_; |
917
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
918
|
|
|
|
|
|
|
|
919
|
|
|
|
|
|
|
$details = 'full' if $details; |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
my $input = { |
922
|
|
|
|
|
|
|
devKey => $self->apikey, |
923
|
|
|
|
|
|
|
testsuiteid => $testsuite_id, |
924
|
|
|
|
|
|
|
deep => $deep, |
925
|
|
|
|
|
|
|
details => $details |
926
|
|
|
|
|
|
|
}; |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
929
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestCasesForTestSuite',$input); |
930
|
|
|
|
|
|
|
return [] if !$result->result; |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
return [] if !scalar(keys(%{$result->result->[0]})); # No tests |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
935
|
|
|
|
|
|
|
return $result->result unless $result->result->[0]->{'code'}; |
936
|
|
|
|
|
|
|
return []; |
937
|
|
|
|
|
|
|
} |
938
|
|
|
|
|
|
|
|
939
|
|
|
|
|
|
|
=head2 B |
940
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
Gets the test case with the given external ID (e.g. projprefix-123) at provided version. |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
=over 4 |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
=item STRING C - desired external case ID |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
=item STRING C - desired test case version. Defaults to most recent version. |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
=back |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
Returns desired case definition hash, false otherwise. |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
$case = $tl->getTestCaseByExternalId('eee-123'); |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
=cut |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
sub getTestCaseByExternalId { |
958
|
|
|
|
|
|
|
my ($self,$case_id,$version) = @_; |
959
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
960
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
my $input = { |
962
|
|
|
|
|
|
|
devKey => $self->apikey, |
963
|
|
|
|
|
|
|
testcaseexternalid => $case_id, |
964
|
|
|
|
|
|
|
version => $version |
965
|
|
|
|
|
|
|
}; |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
968
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestCase',$input); |
969
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
970
|
|
|
|
|
|
|
return $result->result->[0] unless $result->result->[0]->{'code'}; |
971
|
|
|
|
|
|
|
return 0; |
972
|
|
|
|
|
|
|
} |
973
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
=head2 B |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
Gets the test case with the given internal ID at provided version. |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
=over 4 |
979
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
=item STRING C - desired internal case ID |
981
|
|
|
|
|
|
|
|
982
|
|
|
|
|
|
|
=item STRING C - desired test case version. Defaults to most recent version. |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
=back |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
Returns desired case definition hash, false otherwise. |
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
$case = $tl->getTestCaseById(28474,5); |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
=cut |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
sub getTestCaseById { |
993
|
|
|
|
|
|
|
my ($self,$case_id,$version) = @_; |
994
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
995
|
|
|
|
|
|
|
|
996
|
|
|
|
|
|
|
my $input = { |
997
|
|
|
|
|
|
|
devKey => $self->apikey, |
998
|
|
|
|
|
|
|
testcaseid => $case_id, |
999
|
|
|
|
|
|
|
version => $version |
1000
|
|
|
|
|
|
|
}; |
1001
|
|
|
|
|
|
|
|
1002
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1003
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestCase',$input); |
1004
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
1005
|
|
|
|
|
|
|
return $result->result->[0] unless $result->result->[0]->{'code'}; |
1006
|
|
|
|
|
|
|
return 0; |
1007
|
|
|
|
|
|
|
} |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
=head2 B |
1010
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
Gets the test case with the given internal ID at provided version. |
1012
|
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
|
=over 4 |
1014
|
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
|
=item STRING C - desired internal case ID |
1016
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
=item STRING C - parent suite's name |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
=item STRING C - parent project's name |
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
=item STRING C (optional)- Full path to TC. Please see documentation for more info: http://jetmore.org/john/misc/phpdoc-testlink193-api/TestlinkAPI/TestlinkXMLRPCServer.html#getTestCaseIDByName |
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
=item STRING C (optional)- desired test case version. Defaults to most recent version. |
1024
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
=back |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
Returns desired case definition hash, false otherwise. |
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
$case = $tl->getTestCaseByName('nugCase','gravySuite','chickenProject'); |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
=cut |
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
sub getTestCaseByName { |
1034
|
|
|
|
|
|
|
my ($self, $casename, $suitename, $projectname, $testcasepathname, $version) = @_; |
1035
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
my $input = { |
1038
|
|
|
|
|
|
|
devKey => $self->apikey, |
1039
|
|
|
|
|
|
|
testcasename => $casename, |
1040
|
|
|
|
|
|
|
testsuitename => $suitename, |
1041
|
|
|
|
|
|
|
testprojectname => $projectname, |
1042
|
|
|
|
|
|
|
testcasepathname => $testcasepathname |
1043
|
|
|
|
|
|
|
}; |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1046
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestCaseIDByName',$input); |
1047
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
1048
|
|
|
|
|
|
|
return $result->result->[0] unless $result->result->[0]->{'code'}; |
1049
|
|
|
|
|
|
|
return 0; |
1050
|
|
|
|
|
|
|
} |
1051
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
=head2 B |
1053
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
Gets the attachments for some case. |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
=over 4 |
1057
|
|
|
|
|
|
|
|
1058
|
|
|
|
|
|
|
=item STRING C - desired external case ID |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
=back |
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
Returns desired attachment definition hash, false otherwise. Content key is the file base64 encoded. |
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
$att = $tl->getTestCaseAttachments('CP-222'); |
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
=cut |
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
sub getTestCaseAttachments { |
1069
|
|
|
|
|
|
|
my ($self, $case_ext_id) = @_; |
1070
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
my $input = { |
1073
|
|
|
|
|
|
|
devKey => $self->apikey, |
1074
|
|
|
|
|
|
|
testcaseexternalid => $case_ext_id, |
1075
|
|
|
|
|
|
|
}; |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1078
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestCaseAttachments',$input); |
1079
|
|
|
|
|
|
|
return 0 if (!$result->result); |
1080
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
1081
|
|
|
|
|
|
|
return $result->result->[0] unless $result->result->[0]->{'code'}; |
1082
|
|
|
|
|
|
|
return 0; |
1083
|
|
|
|
|
|
|
} |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
=head2 B |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
Gets the test plans within given project id |
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
=over 4 |
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
=item STRING C - project ID |
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
=back |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
Returns desired test plan definition hashes, false otherwise. |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
$plans = $tl->getTestPlansForProject(23); |
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
=cut |
1100
|
|
|
|
|
|
|
|
1101
|
|
|
|
|
|
|
sub getTestPlansForProject { |
1102
|
|
|
|
|
|
|
my ($self,$project_id) = @_; |
1103
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
my $input = { |
1106
|
|
|
|
|
|
|
devKey => $self->apikey, |
1107
|
|
|
|
|
|
|
testprojectid => $project_id |
1108
|
|
|
|
|
|
|
}; |
1109
|
|
|
|
|
|
|
|
1110
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1111
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getProjectTestPlans',$input); |
1112
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
1113
|
|
|
|
|
|
|
return $result->result unless $result->result->[0]->{'code'}; |
1114
|
|
|
|
|
|
|
return 0; |
1115
|
|
|
|
|
|
|
} |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
=head2 B |
1118
|
|
|
|
|
|
|
|
1119
|
|
|
|
|
|
|
Gets the test plan within given project name |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
=over 4 |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
=item STRING C - desired test plan name |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
=item STRING C - project name |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
=back |
1128
|
|
|
|
|
|
|
|
1129
|
|
|
|
|
|
|
Returns desired test plan definition hash, false otherwise. |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
$suites = $tl->getTestPlanByName('nugs','gravy'); |
1132
|
|
|
|
|
|
|
|
1133
|
|
|
|
|
|
|
=cut |
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
# I find it highly bizarre that the only 'by name' method exists for test plans, and it's the only test plan getter. |
1136
|
|
|
|
|
|
|
sub getTestPlanByName { |
1137
|
|
|
|
|
|
|
my ($self,$plan_name,$project_name) = @_; |
1138
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
my $input = { |
1141
|
|
|
|
|
|
|
devKey => $self->apikey, |
1142
|
|
|
|
|
|
|
testplanname => $plan_name, |
1143
|
|
|
|
|
|
|
testprojectname => $project_name |
1144
|
|
|
|
|
|
|
}; |
1145
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1147
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestPlanByName',$input); |
1148
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
1149
|
|
|
|
|
|
|
return $result->result->[0] unless $result->result->[0]->{'code'}; |
1150
|
|
|
|
|
|
|
return 0; |
1151
|
|
|
|
|
|
|
} |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
=head2 B |
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
Gets the builds for given test plan |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
=over 4 |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
=item STRING C - desired test plan ID |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
=back |
1162
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
Returns desired builds' definition hashes, false otherwise. |
1164
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
$builds = $tl->getBuildsForTestPlan(1234); |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
=cut |
1168
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
sub getBuildsForTestPlan { |
1170
|
|
|
|
|
|
|
my ($self,$plan_id) = @_; |
1171
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1172
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
my $input = { |
1174
|
|
|
|
|
|
|
devKey => $self->apikey, |
1175
|
|
|
|
|
|
|
testplanid => $plan_id |
1176
|
|
|
|
|
|
|
}; |
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1179
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getBuildsForTestPlan',$input); |
1180
|
|
|
|
|
|
|
warn $result->result->[0]->{'message'} if $result->result->[0]->{'code'}; |
1181
|
|
|
|
|
|
|
return $result->result unless $result->result->[0]->{'code'}; |
1182
|
|
|
|
|
|
|
return 0; |
1183
|
|
|
|
|
|
|
} |
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
=head2 B |
1186
|
|
|
|
|
|
|
|
1187
|
|
|
|
|
|
|
Gets the cases in provided test plan |
1188
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
=over 4 |
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
=item STRING C - desired test plan ID |
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
=back |
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
Returns desired tests' definition hashes sorted by parent test plan ID, false otherwise. |
1196
|
|
|
|
|
|
|
|
1197
|
|
|
|
|
|
|
Example output: |
1198
|
|
|
|
|
|
|
{ 1234 => [{case1},{case2},...], 33212 => [cases...]} |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
Example usage: |
1201
|
|
|
|
|
|
|
$builds = $tl->getTestCasesForTestPlan(1234); |
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
=cut |
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
sub getTestCasesForTestPlan { |
1206
|
|
|
|
|
|
|
my ($self,$plan_id) = @_; |
1207
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
my $input = { |
1210
|
|
|
|
|
|
|
devKey => $self->apikey, |
1211
|
|
|
|
|
|
|
testplanid => $plan_id |
1212
|
|
|
|
|
|
|
}; |
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1215
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTestCasesForTestPlan',$input); |
1216
|
|
|
|
|
|
|
warn $result->result->{'message'} if $result->result->{'code'}; |
1217
|
|
|
|
|
|
|
return $result->result unless $result->result->{'code'}; |
1218
|
|
|
|
|
|
|
return 0; |
1219
|
|
|
|
|
|
|
} |
1220
|
|
|
|
|
|
|
|
1221
|
|
|
|
|
|
|
=head2 B |
1222
|
|
|
|
|
|
|
|
1223
|
|
|
|
|
|
|
Gets the latest build for the provided test plan |
1224
|
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
|
=over 4 |
1226
|
|
|
|
|
|
|
|
1227
|
|
|
|
|
|
|
=item STRING C - desired test plan ID |
1228
|
|
|
|
|
|
|
|
1229
|
|
|
|
|
|
|
=back |
1230
|
|
|
|
|
|
|
|
1231
|
|
|
|
|
|
|
Returns desired build definition hash, false otherwise. |
1232
|
|
|
|
|
|
|
|
1233
|
|
|
|
|
|
|
$build = $tl->getLatestBuildForTestPlan(1234); |
1234
|
|
|
|
|
|
|
|
1235
|
|
|
|
|
|
|
=cut |
1236
|
|
|
|
|
|
|
|
1237
|
|
|
|
|
|
|
sub getLatestBuildForTestPlan { |
1238
|
|
|
|
|
|
|
my ($self,$plan_id) = @_; |
1239
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1240
|
|
|
|
|
|
|
|
1241
|
|
|
|
|
|
|
my $input = { |
1242
|
|
|
|
|
|
|
devKey => $self->apikey, |
1243
|
|
|
|
|
|
|
tplanid => $plan_id, #documented arg, but that's LIES, apparently it wants the next one |
1244
|
|
|
|
|
|
|
testplanid => $plan_id |
1245
|
|
|
|
|
|
|
}; |
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1248
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getLatestBuildForTestPlan',$input); |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
#Handle mixed return type |
1251
|
|
|
|
|
|
|
my $res = $result->result; |
1252
|
|
|
|
|
|
|
$res = [$res] if reftype($res) eq 'HASH'; |
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
warn $res->[0]->{'message'} if $res->[0]->{'code'}; |
1255
|
|
|
|
|
|
|
return $res->[0] unless $res->[0]->{'code'}; |
1256
|
|
|
|
|
|
|
return 0; |
1257
|
|
|
|
|
|
|
} |
1258
|
|
|
|
|
|
|
|
1259
|
|
|
|
|
|
|
=head2 B |
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
Gets the desired build in project id by name |
1262
|
|
|
|
|
|
|
|
1263
|
|
|
|
|
|
|
=over 4 |
1264
|
|
|
|
|
|
|
|
1265
|
|
|
|
|
|
|
=item STRING C - desired build's name |
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
=item INTEGER C - desired test project ID |
1268
|
|
|
|
|
|
|
|
1269
|
|
|
|
|
|
|
=back |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
Returns desired build definition hash, false otherwise. |
1272
|
|
|
|
|
|
|
|
1273
|
|
|
|
|
|
|
$build = $tl->getBuildByName('foo',1234); |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
=cut |
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
#TODO cache stuff, don't require proj id? |
1278
|
|
|
|
|
|
|
sub getBuildByName { |
1279
|
|
|
|
|
|
|
my ($self,$build_name,$project_id) = @_; |
1280
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1281
|
|
|
|
|
|
|
|
1282
|
|
|
|
|
|
|
my $plans = $self->getTestPlansForProject($project_id); |
1283
|
|
|
|
|
|
|
for my $plan (@$plans) { |
1284
|
|
|
|
|
|
|
my $builds = $self->getBuildsForTestPlan($plan->{'id'}); |
1285
|
|
|
|
|
|
|
for my $build (@$builds) { |
1286
|
|
|
|
|
|
|
return $build if $build->{'name'} eq $build_name; |
1287
|
|
|
|
|
|
|
} |
1288
|
|
|
|
|
|
|
} |
1289
|
|
|
|
|
|
|
return 0; |
1290
|
|
|
|
|
|
|
} |
1291
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
=head1 REPORTING METHODS |
1293
|
|
|
|
|
|
|
|
1294
|
|
|
|
|
|
|
=head2 B |
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
Gets the results summary for a test plan, even though what you really want is results by build/platform |
1297
|
|
|
|
|
|
|
|
1298
|
|
|
|
|
|
|
=over 4 |
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
=item INTEGER C - desired test plan |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
=back |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
Returns Hash describing test results. |
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
$res = $tl->getTotalsForTestPlan(2322); |
1307
|
|
|
|
|
|
|
|
1308
|
|
|
|
|
|
|
=cut |
1309
|
|
|
|
|
|
|
|
1310
|
|
|
|
|
|
|
sub getTotalsForTestPlan { |
1311
|
|
|
|
|
|
|
my ($self,$plan_id) = @_; |
1312
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1313
|
|
|
|
|
|
|
|
1314
|
|
|
|
|
|
|
my $input = { |
1315
|
|
|
|
|
|
|
devKey => $self->apikey, |
1316
|
|
|
|
|
|
|
tplanid => $plan_id, #documented arg, but that's LIES, apparently it wants the next one |
1317
|
|
|
|
|
|
|
testplanid => $plan_id |
1318
|
|
|
|
|
|
|
}; |
1319
|
|
|
|
|
|
|
|
1320
|
|
|
|
|
|
|
my $rpc = XMLRPC::Lite->proxy($self->apiurl); |
1321
|
|
|
|
|
|
|
my $result = $rpc->call('tl.getTotalsForTestPlan',$input); |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
warn $result->result->{'message'} if $result->result->{'code'}; |
1324
|
|
|
|
|
|
|
return $result->result unless $result->result->{'code'}; |
1325
|
|
|
|
|
|
|
return 0; |
1326
|
|
|
|
|
|
|
} |
1327
|
|
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
=head1 EXPORT/IMPORT METHODS |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
=head2 B |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
Return all info for all (or only the specified) projects. |
1333
|
|
|
|
|
|
|
It will have the entire testsuite hierarchy and it's tests/attachments in an array of HASHREFs. |
1334
|
|
|
|
|
|
|
The idea would be that you then could encode as JSON/XML as a backup, or to facilitate migration to other systems. |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
The project hashes will be what you would expect from getProjectByName calls. |
1337
|
|
|
|
|
|
|
Those will have a key 'testsuites' with a list of it's child testsuites. |
1338
|
|
|
|
|
|
|
These testsuites will themselves have 'testsuites' and 'test' keys describing their children. |
1339
|
|
|
|
|
|
|
Both the test and testsuite hashes will have an 'attachment' parameter with the base64 encoded attachment as a string if the get_attachments option is passed. |
1340
|
|
|
|
|
|
|
|
1341
|
|
|
|
|
|
|
WARNING: I have observed some locking related issues with cases/suites etc. |
1342
|
|
|
|
|
|
|
Sometimes calls to get tests/suites during dumps fails, sometimes subsequent calls to getTestSuites/getTestCasesForTestSuite fail. |
1343
|
|
|
|
|
|
|
If you are experiencing issues, try to put some wait() in there until it starts behaving right. |
1344
|
|
|
|
|
|
|
Alternatively, just XML dump the whole project and use XML::Simple or somesuch to get the project tree. |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
ALSO: Attachment getting is not enabled due to the underlying XMLRPC calls appearing not to work. This option will be ignored until a workaround can be found. |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
=over 4 |
1349
|
|
|
|
|
|
|
|
1350
|
|
|
|
|
|
|
=item INTEGER C (optional) - desired project |
1351
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - whether or not to get attachments. Default false. |
1352
|
|
|
|
|
|
|
=item BOOLEAN C (optional) - Whether to return a flattened structure (you will need to corellate parent to child yourself, but this is faster due to not walking the tree). Preferred output for those not comfortable with doing tail recursion. |
1353
|
|
|
|
|
|
|
|
1354
|
|
|
|
|
|
|
=back |
1355
|
|
|
|
|
|
|
|
1356
|
|
|
|
|
|
|
Returns ARRAYREF describing everything. |
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
$ultradump = $tl->dump(); |
1359
|
|
|
|
|
|
|
$dumpWithAtts = $tl->dump('TestProject',1); |
1360
|
|
|
|
|
|
|
$flatDump = $tl->dump('testProj',0,1); |
1361
|
|
|
|
|
|
|
|
1362
|
|
|
|
|
|
|
=cut |
1363
|
|
|
|
|
|
|
|
1364
|
|
|
|
|
|
|
sub dump { |
1365
|
|
|
|
|
|
|
my ($self,$project,$attachment,$flat) = @_; |
1366
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1367
|
|
|
|
|
|
|
|
1368
|
|
|
|
|
|
|
my $res = $self->_cacheProjectTree($project,$flat); |
1369
|
|
|
|
|
|
|
return [] if !$res; |
1370
|
|
|
|
|
|
|
|
1371
|
|
|
|
|
|
|
return $res if !$project || $flat; |
1372
|
|
|
|
|
|
|
foreach my $pj (@{$res}) { |
1373
|
|
|
|
|
|
|
return $pj if $pj->{'name'} eq $project; |
1374
|
|
|
|
|
|
|
} |
1375
|
|
|
|
|
|
|
croak "COULD NOT DUMP, SOMETHING HORRIBLY WRONG"; |
1376
|
|
|
|
|
|
|
} |
1377
|
|
|
|
|
|
|
|
1378
|
|
|
|
|
|
|
sub _cacheProjectTree { |
1379
|
|
|
|
|
|
|
my ($self,$project,$flat,$use_project_id,$get_tests) = @_; |
1380
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
$flat //= 0; |
1383
|
|
|
|
|
|
|
$use_project_id //= 0; |
1384
|
|
|
|
|
|
|
$get_tests //= 1; |
1385
|
|
|
|
|
|
|
|
1386
|
|
|
|
|
|
|
#Cache Projects |
1387
|
|
|
|
|
|
|
if (!scalar(@{$self->{'testtree'}})) { |
1388
|
|
|
|
|
|
|
$self->getProjects(); |
1389
|
|
|
|
|
|
|
} |
1390
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
my @flattener = @{$self->{'testtree'}}; |
1392
|
|
|
|
|
|
|
|
1393
|
|
|
|
|
|
|
for my $projhash (@flattener) { |
1394
|
|
|
|
|
|
|
if ($use_project_id) { |
1395
|
|
|
|
|
|
|
next if $project && $project ne $projhash->{'id'} && (defined($projhash->{'type'}) && $projhash->{'type'} eq 'project'); |
1396
|
|
|
|
|
|
|
} else { |
1397
|
|
|
|
|
|
|
next if $project && $project ne $projhash->{'name'} && (defined($projhash->{'type'}) && $projhash->{'type'} eq 'project'); |
1398
|
|
|
|
|
|
|
} |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
#If Testsuites are not defined, this must be a TS which we have not traversed yet, so go and get it |
1401
|
|
|
|
|
|
|
if (exists($projhash->{'type'}) && $projhash->{'type'} eq 'project') { |
1402
|
|
|
|
|
|
|
$projhash->{'testsuites'} = $self->getTLDTestSuitesForProject($projhash->{'id'},$get_tests); |
1403
|
|
|
|
|
|
|
} else { |
1404
|
|
|
|
|
|
|
$projhash->{'testsuites'} = $self->getTestSuitesForTestSuite($projhash->{'id'},$get_tests); |
1405
|
|
|
|
|
|
|
} |
1406
|
|
|
|
|
|
|
|
1407
|
|
|
|
|
|
|
$projhash->{'testsuites'} = [] if !$projhash->{'testsuites'}; |
1408
|
|
|
|
|
|
|
for my $tshash (@{$projhash->{'testsuites'}}) { |
1409
|
|
|
|
|
|
|
#Otherwise, push it's children to the end of our array so we can recurse as needed. |
1410
|
|
|
|
|
|
|
#I hope the designers of TL's schema were smart enough to not allow self-referential or circular suites.. |
1411
|
|
|
|
|
|
|
push(@flattener,clone $tshash); |
1412
|
|
|
|
|
|
|
} |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
} |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
#Keep this for simple searches in the future. |
1417
|
|
|
|
|
|
|
$self->{'flattree'} = clone \@flattener; |
1418
|
|
|
|
|
|
|
my @debuglist = map {$_->{'tests'}} @flattener; |
1419
|
|
|
|
|
|
|
return $self->{'flattree'} if $flat; |
1420
|
|
|
|
|
|
|
return $self->_expandTree($project,@flattener); |
1421
|
|
|
|
|
|
|
} |
1422
|
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
sub _expandTree { |
1424
|
|
|
|
|
|
|
my $self = shift; |
1425
|
|
|
|
|
|
|
confess("Object parameters must be called by an instance") unless ref($self); |
1426
|
|
|
|
|
|
|
my $project = shift; |
1427
|
|
|
|
|
|
|
my @flattener = @_; |
1428
|
|
|
|
|
|
|
#The following algorithm relies implicitly on pass-by-reference. |
1429
|
|
|
|
|
|
|
#So we have a flat array of testsuites we want to map into parent-child relationships. |
1430
|
|
|
|
|
|
|
my ($i,$j); |
1431
|
|
|
|
|
|
|
foreach my $suite (@flattener) { |
1432
|
|
|
|
|
|
|
if (defined($suite->{'type'}) && $suite->{'type'} eq 'project') { |
1433
|
|
|
|
|
|
|
#Then skip it, since it's not a suite. |
1434
|
|
|
|
|
|
|
shift @flattener; |
1435
|
|
|
|
|
|
|
next; |
1436
|
|
|
|
|
|
|
} |
1437
|
|
|
|
|
|
|
|
1438
|
|
|
|
|
|
|
#This means we need to walk the hierarchy of every project, or just the one we passed |
1439
|
|
|
|
|
|
|
for ($j=0; $j < scalar(@{$self->{'testtree'}}); $j++) { |
1440
|
|
|
|
|
|
|
#If we have a project, skip the other ones |
1441
|
|
|
|
|
|
|
next unless $project && $self->{'testtree'}->[$j]->{'name'} eq $project; |
1442
|
|
|
|
|
|
|
|
1443
|
|
|
|
|
|
|
#Get the ball rolling if we have to |
1444
|
|
|
|
|
|
|
$self->{'testtree'}->[$j]->{'testsuites'} = $self->getTLDTestSuitesForProject($self->{'testtree'}->[$j]->{'id'},1) if !defined($self->{'testtree'}->[$j]->{'testsuites'}); |
1445
|
|
|
|
|
|
|
|
1446
|
|
|
|
|
|
|
#So, let's tail recurse over the testsuites. |
1447
|
|
|
|
|
|
|
for ($i=0; $i < scalar(@{$self->{'testtree'}->[$j]->{'testsuites'}}); $i++) { |
1448
|
|
|
|
|
|
|
my $tailRecurseTSWalker = sub { |
1449
|
|
|
|
|
|
|
my ($ts,$desired_ts) = @_; |
1450
|
|
|
|
|
|
|
|
1451
|
|
|
|
|
|
|
#Mark it down if we found it |
1452
|
|
|
|
|
|
|
if ($ts->{'id'} eq $desired_ts->{'parent_id'}) { |
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
#Set the REF's 'testsuites' param, and quit searching |
1455
|
|
|
|
|
|
|
$ts->{'testsuites'} = [] if !defined($ts->{'testsuites'}); |
1456
|
|
|
|
|
|
|
push(@{$ts->{'testsuites'}},$desired_ts); |
1457
|
|
|
|
|
|
|
$desired_ts->{'found'} = 1; |
1458
|
|
|
|
|
|
|
return; |
1459
|
|
|
|
|
|
|
} |
1460
|
|
|
|
|
|
|
|
1461
|
|
|
|
|
|
|
#If there's already (nonblank) hierarchy in the passed TS, then WE HAVE TO GO DEEPER |
1462
|
|
|
|
|
|
|
if (defined($ts->{'testsuites'}) && scalar(@{$desired_ts->{'testsuites'}})) { |
1463
|
|
|
|
|
|
|
for (my $i=0; $i < scalar(@{$ts->{'testsuites'}}); $i++) { |
1464
|
|
|
|
|
|
|
_tailRecurseTSWalker($ts->{'testsuites'}->[$i],$desired_ts); |
1465
|
|
|
|
|
|
|
} |
1466
|
|
|
|
|
|
|
} |
1467
|
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
|
return; |
1469
|
|
|
|
|
|
|
}; |
1470
|
|
|
|
|
|
|
|
1471
|
|
|
|
|
|
|
&$tailRecurseTSWalker($self->{'testtree'}->[$j]->{'testsuites'}->[$i],$suite); |
1472
|
|
|
|
|
|
|
#OPTIMIZE: break out if we found it already |
1473
|
|
|
|
|
|
|
last if $suite->{'found'}; |
1474
|
|
|
|
|
|
|
} |
1475
|
|
|
|
|
|
|
last if $suite->{'found'}; |
1476
|
|
|
|
|
|
|
} |
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
#If we didn't find this one yet, as the hierarchy build is progressive, add it to the end until it gets picked up. |
1479
|
|
|
|
|
|
|
if (!$suite->{'found'}) { |
1480
|
|
|
|
|
|
|
push(@flattener,shift @flattener); # If it wasn't found, push it on to the end of the array so the walk might find it next time. |
1481
|
|
|
|
|
|
|
} else { |
1482
|
|
|
|
|
|
|
shift @flattener; |
1483
|
|
|
|
|
|
|
} |
1484
|
|
|
|
|
|
|
} |
1485
|
|
|
|
|
|
|
return $self->{'testtree'}; |
1486
|
|
|
|
|
|
|
} |
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
1; |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
__END__ |