blib/lib/Tapper/Reports/Web/Controller/Tapper/Testplan.pm

filter: Statementstmt 31.8% 42 / 132 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 59.0% 13 / 22 Podpod 25.0% 2 / 8 totaltotal 24.1% 57 / 236 CC 29 SCAR 50.2
CC
29
Cov
22%
get_testrun_details
380.0
index
42.0
delete
12.0
CRAP 151.2
« blib/lib/Tapper/Reports/Web/Util/Testrun.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/Reports/Id.pm »
1 package Tapper::Reports::Web::Controller::Tapper::Testplan;
2 13 our $AUTHORITY = 'cpan:TAPPER';
3 13 $Tapper::Reports::Web::Controller::Tapper::Testplan::VERSION = '5.0.17';
4 13 ▶use parent 'Tapper::Reports::Web::Controller::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 ## no critic (RequireUseStrict)
7  
8 13 ▶use DateTime::Format::Natural;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Tapper::Reports::Web::Util::Filter::Testplan;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Tapper::Cmd::Testplan;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub auto :Private
Subroutine auto: not called CC=1 SCAR=6.9
14 {
15 0 my ( $self, $c ) = @_;
16  
17 0 $c->forward('/tapper/testplan/prepare_navi');
18 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 13 ▶sub base : Chained PathPrefix CaptureArgs(0) { }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine base: not called CC=1 SCAR=0.0
Pod undocumented
22  
23 0 ▶sub id : Chained('base') PathPart('') CaptureArgs(1)
Subroutine id: not called CC=2 SCAR=17.9
Pod undocumented
24 {
25 0 my ( $self, $c, $id ) = @_;
26 0 $c->stash(testplan => $c->model('TestrunDB')->resultset('TestplanInstance')->find($id));
27 0 ▶ if (not $c->stash->{testplan}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $c->stash->{"testplan"}) 0 0 0
28 0 $c->response->body(qq(No testplan instance with id "$id" found in the database!));
29 0 return;
30 }
31  
32 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 0 ▶sub rerun : Chained('id') PathPart('rerun') Args(0)
Subroutine rerun: not called CC=2 SCAR=17.9
Pod undocumented
35 {
36 0 my ( $self, $c ) = @_;
37  
38 0 my $cmd = Tapper::Cmd::Testplan->new();
39 0 my $retval = $cmd->rerun($c->stash->{testplan}->id)->{testplan_id};
40 0 ▶ if (not $retval) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retval) 0 0 0
41 0 $c->response->body(qq(Can not rerun testplan));
42 0 return;
43 }
44 0 $c->stash(testplan => $c->model('TestrunDB')->resultset('TestplanInstance')->find($retval));
45 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 0 ▶sub delete : Chained('id') PathPart('delete')
Subroutine delete: not called CC=3 SCAR=24.8
Pod undocumented
49 {
50 0 my ( $self, $c, $force) = @_;
51  
52 0 my $cmd = Tapper::Cmd::Testplan->new();
53 0 ▶ if ($force) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force) 0 0 0
54 0 $c->stash->{force} = 1;
55 0 my $retval = $cmd->del($c->stash->{testplan}->id);
56 0 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) 0 0 0
57 0 $c->response->body(qq(Can not delete testplan: $retval));
58 0 return;
59 }
60 }
61 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 0 ▶sub cancel : Chained('id') PathPart('cancel')
Subroutine cancel: not called CC=2 SCAR=17.9
Pod undocumented
64 {
65 0 my ($self, $c) = @_;
66  
67 0 my $cmd = Tapper::Cmd::Testplan->new;
68 0 my $testplan_id = $c->stash->{testplan}->id;
69 0 my $retval = $cmd->cancel($testplan_id, "Cancelled testplan in WebGUI");
70 0 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) 0 0 0
71 0 $c->response->body(qq(Can not cancel testplan: $retval));
72 0 return;
73 }
74 0 $c->flash->{msg} = "<strong>Cancelling this testplan is in progress...</strong><br/><br/>";
75 0 $c->res->redirect("/tapper/testplan/id/$testplan_id");
76 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78  
79  
80 0 ▶sub index :Path :Args()
Subroutine index: not called CC=6 SCAR=37.4
Pod documented
81 {
82 0 my ( $self, $c, @args ) = @_;
83  
84 0 my $filter = Tapper::Reports::Web::Util::Filter::Testplan->new(context => $c);
85 0 my $filter_condition = $filter->parse_filters(\@args, ['days', 'date', 'path', 'name']);
86 0 $c->stash->{title} = "Testplan list";
87 0 $c->stash->{testplan_id} = undef;
88  
89 0 ▶ if ($filter_condition->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter_condition->{"error"}) 0 0 0
90 0 $c->flash->{error_msg} = join("; ", @{$filter_condition->{error}});
91 0 $c->res->redirect("/tapper/testplan/days/2");
92 }
93  
94 0 ▶ my $days = $filter_condition->{days} || 6;
Condition0%0/2
$filter_condition->{'days'} || 6
l!l
00
MC/DC0%0/1
$filter_condition->{'days'} || 6
$filter_condition->{'days'}
Truth table0%0/2
A
A= $filter_condition->{'days'}
Aresult
11
00
95 0 $c->stash->{days} = $days;
96  
97 0 $c->stash->{testplan_days} = [];
98 0 my $today = DateTime::Format::Natural->new->parse_datetime("today at midnight");
99 0 my $dtf = $c->model("TestrunDB")->storage->datetime_parser;
100  
101 # testplans after "today at midnight"
102 # handling them special makes later code more readable
103 {
104 0 my $todays_instances = model('TestrunDB')->resultset('TestplanInstance')->search
105 (
106 $filter_condition->{early},
107 0 { order_by => 'me.id desc' }
108 );
109 0 $todays_instances = $todays_instances->search({created_at => { '>' => $dtf->format_datetime($today) }});
110  
111 0 my @details = $self->get_testrun_details($todays_instances);
112 0 ▶ if (@details) {
Branch: 1 branch
BranchTrueFalseTotal
if (@details) 0 0 0
113 0 push @{$c->stash->{testplan_days}}, { date => $today,
114 testplan_instances => \@details,
115 };
116 }
117 }
118  
119 0 for my $date (1..($days-1)) {
120 0 my $yesterday = $today->clone->subtract( days => 1 );
121  
122 my $todays_instances = model('TestrunDB')->resultset('TestplanInstance')->search
123 ($filter_condition->{early},
124 0 { order_by => 'me.id desc' }
125 );
126 0 $todays_instances = $todays_instances->search({'-and' => [{created_at => { '>' => $dtf->format_datetime($yesterday) }},
127 {created_at => {'<=' => $dtf->format_datetime($today) }},
128 ]});
129 0 my @details = $self->get_testrun_details($todays_instances);
130 0 ▶ if (@details) {
Branch: 1 branch
BranchTrueFalseTotal
if (@details) 0 0 0
131 0 push @{$c->stash->{testplan_days}}, { date => $yesterday,
132 testplan_instances => \@details,
133 };
134 }
135 0 $today = $yesterday;
136 }
137 0 return;
138 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
139  
140  
141  
142 sub get_testrun_details
143 0 ▶{
Subroutine get_testrun_details: not called CC=19 SCAR=59.4
Pod documented
144 0 my ($self, $todays_instances) = @_;
145 0 ▶ return unless $todays_instances and $todays_instances->can('next');
Branch: 1 branch
BranchTrueFalseTotal
unless $todays_instances and $todays_instances->can("next") 0 0 0
Condition0%0/3
$todays_instances and $todays_instances->can("next")
!ll&&!rl&&r
000
MC/DC0%0/2
$todays_instances and $todays_instances->can("next")
$todays_instances $todays_instances->can("next")
Truth table0%0/3
A and B
A= $todays_instancesB= $todays_instances->can("next")
ABresult
0X0
100
111
146  
147 0 my @testplan_instances;
148  
149 0 ▶ while ( my $instance = $todays_instances->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $instance = $todays_instances->next) 0 0 0
150  
151 0 my $details = {};
152 0 foreach my $col ($instance->columns) {
153 0 $details->{$col} = $instance->$col;
154 }
155  
156 0 my $testruns = $instance->testruns;
157 TESTRUN:
158 0 ▶ while (my $testrun = $testruns->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $testrun = $testruns->next) 0 0 0
159 {
160 0 my $job = $testrun->testrun_scheduling;
161 0 ▶ $details->{count_unfinished}++ if $job and $job->status ne 'finished';
Branch: 1 branch
BranchTrueFalseTotal
if $job and $job->status ne "finished" 0 0 0
Condition0%0/3
$job and $job->status ne "finished"
!ll&&!rl&&r
000
MC/DC0%0/2
$job and $job->status ne "finished"
$job $job->status ne "finished"
Truth table0%0/3
A and B
A= $jobB= $job->status ne "finished"
ABresult
0X0
100
111
162 0 ▶ $details->{count_running}++ if $job and $job->status eq 'running';
Branch: 1 branch
BranchTrueFalseTotal
if $job and $job->status eq "running" 0 0 0
Condition0%0/3
$job and $job->status eq "running"
!ll&&!rl&&r
000
MC/DC0%0/2
$job and $job->status eq "running"
$job $job->status eq "running"
Truth table0%0/3
A and B
A= $jobB= $job->status eq "running"
ABresult
0X0
100
111
163 0 ▶ $details->{count_schedule}++ if $job and $job->status eq 'schedule';
Branch: 1 branch
BranchTrueFalseTotal
if $job and $job->status eq "schedule" 0 0 0
Condition0%0/3
$job and $job->status eq "schedule"
!ll&&!rl&&r
000
MC/DC0%0/2
$job and $job->status eq "schedule"
$job $job->status eq "schedule"
Truth table0%0/3
A and B
A= $jobB= $job->status eq "schedule"
ABresult
0X0
100
111
164 0 ▶ $details->{count_prepare}++ if $job and $job->status eq 'prepare';
Branch: 1 branch
BranchTrueFalseTotal
if $job and $job->status eq "prepare" 0 0 0
Condition0%0/3
$job and $job->status eq "prepare"
!ll&&!rl&&r
000
MC/DC0%0/2
$job and $job->status eq "prepare"
$job $job->status eq "prepare"
Truth table0%0/3
A and B
A= $jobB= $job->status eq "prepare"
ABresult
0X0
100
111
165  
166 0 ▶ next TESTRUN if $job->status ne 'finished';
Branch: 1 branch
BranchTrueFalseTotal
if $job->status ne "finished" 0 0 0
167 0 my $stats = model('TestrunDB')->resultset('ReportgroupTestrunStats')->search({testrun_id => $testrun->id}, {rows => 1})->first;
168  
169 0 ▶ $details->{count_fail}++ if $stats and $stats->success_ratio < 100;
Branch: 1 branch
BranchTrueFalseTotal
if $stats and $stats->success_ratio < 100 0 0 0
Condition0%0/3
$stats and $stats->success_ratio < 100
!ll&&!rl&&r
000
MC/DC0%0/2
$stats and $stats->success_ratio < 100
$stats $stats->success_ratio < 100
Truth table0%0/3
A and B
A= $statsB= $stats->success_ratio < 100
ABresult
0X0
100
111
170 0 ▶ $details->{count_pass}++ if $stats and $stats->success_ratio == 100;
Branch: 1 branch
BranchTrueFalseTotal
if $stats and $stats->success_ratio == 100 0 0 0
Condition0%0/3
$stats and $stats->success_ratio == 100
!ll&&!rl&&r
000
MC/DC0%0/2
$stats and $stats->success_ratio == 100
$stats $stats->success_ratio == 100
Truth table0%0/3
A and B
A= $statsB= $stats->success_ratio == 100
ABresult
0X0
100
111
171 }
172 0 push @testplan_instances, $details;
173 }
174 0 return @testplan_instances;
175 }
176  
177 0 ▶sub prepare_navi : Private
Subroutine prepare_navi: not called CC=1 SCAR=6.9
Pod undocumented
178 {
179 0 my ( $self, $c ) = @_;
180 0 $c->stash->{navi} = [];
181  
182 0 my %args = @{$c->req->arguments};
183  
184 $c->stash->{navi} = [
185 {
186 0 title => "Matrix Overview",
187 href => "/tapper/testplan/taskjuggler/",
188 },
189 {
190 title => "Testplan by date",
191 href => "",
192 subnavi => [
193 {
194 title => "today",
195 href => "/tapper/testplan/".$self->prepare_filter_path($c, 1),
196 },
197 {
198 title => "2 days",
199 href => "/tapper/testplan/".$self->prepare_filter_path($c, 2),
200 },
201 {
202 title => "1 week",
203 href => "/tapper/testplan/".$self->prepare_filter_path($c, 7),
204 },
205 {
206 title => "2 weeks",
207 href => "/tapper/testplan/".$self->prepare_filter_path($c, 14),
208 },
209 {
210 title => "3 weeks",
211 href => "/tapper/testplan/".$self->prepare_filter_path($c, 21),
212 },
213 {
214 title => "1 month",
215 href => "/tapper/testplan/".$self->prepare_filter_path($c, 31),
216 },
217 {
218 title => "2 months",
219 href => "/tapper/testplan/".$self->prepare_filter_path($c, 62),
220 },
221 {
222 title => "4 months",
223 href => "/tapper/testplan/".$self->prepare_filter_path($c, 124),
224 },
225 {
226 title => "6 months",
227 href => "/tapper/testplan/".$self->prepare_filter_path($c, 182),
228 },
229 {
230 title => "12 months",
231 href => "/tapper/testplan/".$self->prepare_filter_path($c, 365),
232 },
233  
234 ],
235 },
236 ];
237  
238 0 push @{$c->stash->{navi}}, {title => 'Active Filters',
239 subnavi => [
240 map {
241 0 {
242 0 title => "$_: ".$args{$_},
243 href => "/tapper/reports/".$self->reduced_filter_path(\%args, $_),
244 image => "/tapper/static/images/minus.png",
245 }
246 } keys %args ]};
247 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
248  
249  
250  
251 13 1;
252  
253 __END__
« blib/lib/Tapper/Reports/Web/Util/Testrun.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/Reports/Id.pm »