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