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

filter: Statementstmt 30.6% 49 / 160 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 80.0% 16 / 20 Podpod n/a totaltotal 25.9% 65 / 251 CC 29 SCAR 46.8
CC
29
Cov
22%
index
272.0
get_ostore_attachments
72.0
generate_metareport_link
33.7
CRAP 108.0
« blib/lib/Tapper/Reports/Web/Controller/Tapper/Testplan.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/ReportFile/Id.pm »
1 package Tapper::Reports::Web::Controller::Tapper::Reports::Id;
2 13 our $AUTHORITY = 'cpan:TAPPER';
3 13 $Tapper::Reports::Web::Controller::Tapper::Reports::Id::VERSION = '5.0.17';
4 13 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use Tapper::Reports::Web::Util::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use parent 'Tapper::Reports::Web::Controller::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use JSON::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use Data::DPath 'dpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 sub younger
19 0 ▶{
Subroutine younger: not called CC=1 SCAR=6.9
20 0 my $astat = stat($a);
21 0 my $bstat = stat($b);
22 0 return $bstat->mtime() <=> $astat->mtime();
23 }
24  
25  
26  
27 sub generate_metareport_link
28 0 ▶{
Subroutine generate_metareport_link: not called CC=7 SCAR=35.2
29 0 my ( $self, $report ) = @_;
30 0 my %metareport;
31 0 my $path = Tapper::Config->subconfig->{paths}{config_path};
32 0 $path .= "/web/metareport_associate.yml";
33  
34 0 ▶ return if not -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 0 0
35  
36 0 my $config;
37 0 eval {
38 0 $config = YAML::LoadFile($path);
39 };
40 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
41 # TODO: Enable Log4perl
42 # $self->log->error("Can not open association config for metareports: $@");
43 0 say STDERR "Can not open association config for metareports: $@";
44 0 return ();
45 }
46 13 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 0 my $suite;
48 0 ▶ { no warnings 'uninitialized'; $suite = $config->{suite}->{$report->{suite}} || $config->{suite}->{$report->{group_suite}};}
Subroutine BEGIN: called CC=1 SCAR=2.2
Condition0%0/3
$config->{'suite'}{$report->{'suite'}} || $config->{'suite'}{$report->{'group_suite'}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{'suite'}{$report->{'suite'}} || $config->{'suite'}{$report->{'group_suite'}}
$config->{'suite'}{$report->{'suite'}} $config->{'suite'}{$report->{'group_suite'}}
Truth table0%0/3
A || B
A= $config->{'suite'}{$report->{'suite'}}B= $config->{'suite'}{$report->{'group_suite'}}
ABresult
1X1
011
000
49 0 ▶ if ($suite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suite) 0 0 0
50 0 my $category = $suite->{category};
51 0 my $subcategory = $suite->{subcategory};
52 0 my $time_frame = $suite->{time_frame};
53  
54 0 $path = Tapper::Config->subconfig->{paths}{metareport_path};
55 0 ▶ my ($filename) = sort younger <$path/$category/$subcategory/teaser/*.png>;
Subroutine BEGIN: called CC=1 SCAR=0.2
56 0 ▶ if (not $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $filename) { } 0 0 0
57 0 ($filename) = sort younger <$path/$category/$subcategory/$time_frame/*.png>;
58 0 $filename = "/tapper/static/metareports/$category/$subcategory/$time_frame/".basename($filename);
59 } else {
60 0 $filename = "/tapper/static/metareports/$category/$subcategory/teaser/".basename($filename);
61 }
62 0 ▶ return () if not $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
63  
64 %metareport = (url => "/tapper/metareports/$category/$subcategory/$time_frame/",
65 img => $filename,
66 alt => $suite->{alt},
67 headline => $suite->{headline},
68 0 );
69 }
70 0 return %metareport;
71 }
72  
73  
74 0 ▶sub get_ostore_attachments {
Subroutine get_ostore_attachments: not called CC=8 SCAR=42.8
75  
76 0 my ($self, $report_id) = @_;
77  
78 0 my $endpoint = Tapper::Config->subconfig->{ostore}{endpoint};
79  
80 0 ▶ return [] unless defined $endpoint;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endpoint 0 0 0
81  
82 0 $endpoint =~ s,/$,,;
83  
84 0 my $api = JSON::API->new($endpoint);
85  
86 0 my $result = $api->get('/search.json', {
87 "q:report" => $report_id,
88 });
89  
90 0 ▶ return [] unless defined($result) && ref($result) eq "HASH" && defined($result->{success}) && $result->{success} && defined($result->{objects});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result and ref $result eq "HASH" and defined $result->{"success"} and $result->{"success"} and defined $result->{"objects"} 0 0 0
Condition0%0/12
defined $result and ref $result eq "HASH" and defined $result->{"success"} and $result->{"success"} and defined $result->{"objects"}
!ll&&!rl&&r
000
defined $result and ref $result eq "HASH" and defined $result->{"success"} and $result->{"success"}
!ll&&!rl&&r
000
defined $result and ref $result eq "HASH" and defined $result->{"success"}
!ll&&!rl&&r
000
defined $result and ref $result eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/5
defined $result and ref $result eq "HASH" and defined $result->{"success"} and $result->{"success"} and defined $result->{"objects"}
defined $result ref $result eq "HASH" defined $result->{"success"} $result->{"success"} defined $result->{"objects"}
Truth table0%0/6
A and B and C and D and E
A= defined $resultB= ref $result eq "HASH"C= defined $result->{"success"}D= $result->{"success"}E= defined $result->{"objects"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
91  
92 0 my @attachments;
93 0 foreach my $obj (@{$result->{objects}}) {
94 push @attachments, {
95 filename => $obj->{meta}->{filename},
96 view_url => $endpoint . $obj->{urls}->{view},
97 info_url => $endpoint . $obj->{urls}->{meta_html},
98 size => $obj->{size},
99 0 };
100 }
101  
102 0 return \@attachments;
103 }
104  
105 # get array of not_ok sub tests
106  
107 sub get_report_failures
108 1 ▶{
Subroutine get_report_failures: called CC=1 SCAR=0.0
109 1 my ($self, $report) = @_;
110  
111 1 return [ dpath('//tap//lines//is_ok[value eq 0]/..')->match($report->get_cached_tapdom) ];
112 }
113  
114 0 ▶sub index :Path :Args(1)
Subroutine index: not called CC=16 SCAR=56.1
115 {
116 0 my ( $self, $c, $report_id ) = @_;
117  
118 0 $c->stash->{failures} = {};
119 0 $c->stash->{reportlist_rga} = {};
120 0 $c->stash->{reportlist_rgt} = {};
121 0 $c->stash->{overview} = undef;
122 0 $c->stash->{report} = $c->model('TestrunDB')->resultset('Report')->find($report_id);
123  
124 0 ▶ if (not $c->stash->{report}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->stash->{"report"}) 0 0 0
125 0 $c->response->body("No such report");
126 0 $c->stash->{title} = "No such report";
127 0 return;
128 }
129  
130 0 ▶ if (not $c->stash->{report}->suite) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->stash->{"report"}->suite) 0 0 0
131 0 ▶ $c->response->body("No such testsuite with id: ". ($c->stash->{report}->suite_id // ""));
Condition0%0/2
$c->stash->{"report"}->suite_id // ""
l!l
00
MC/DC0%0/1
$c->stash->{"report"}->suite_id // ""
$c->stash->{"report"}->suite_id
Truth table0%0/2
A
A= $c->stash->{"report"}->suite_id
Aresult
11
00
132 0 $c->stash->{title} = "No such testsuite";
133 0 return;
134 }
135  
136 0 my $suite_name = $c->stash->{report}->suite->name;
137 0 my $machine_name = $c->stash->{report}->machine_name;
138 0 $c->stash->{title} = "Report $report_id: $suite_name @ $machine_name";
139  
140 0 $c->stash->{external_attachments} = $self->get_ostore_attachments($report_id);
141  
142 0 my $util_report = Tapper::Reports::Web::Util::Report->new();
143  
144 0 ▶ if (my $rga = $c->stash->{report}->reportgrouparbitrary) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rga = $c->stash->{"report"}->reportgrouparbitrary) 0 0 0
145 #my $rga_reports = $c->model('TestrunDB')->resultset('ReportgroupArbitrary')->search ({ arbitrary_id => $rga->arbitrary_id });
146 0 my $rga_reports = $c->model('TestrunDB')->resultset('Report')->search
147 (
148 {
149 "reportgrouparbitrary.arbitrary_id" => $rga->arbitrary_id
150 },
151 { order_by => 'me.id desc',
152 join => [ 'reportgrouparbitrary', 'reportgrouptestrun', 'suite'],
153 '+select' => [ 'reportgrouparbitrary.arbitrary_id', 'reportgrouparbitrary.primaryreport', 'reportgrouptestrun.testrun_id', 'reportgrouptestrun.primaryreport', 'suite.id', 'suite.name', 'suite.type', 'suite.description' ],
154 '+as' => [ 'rga_id', 'rga_primary', 'rgt_id', 'rgt_primary', 'suite_id', 'suite_name', 'suite_type', 'suite_description' ],
155 }
156 );
157 0 $c->stash->{reportlist_rga} = $util_report->prepare_simple_reportlist($c, $rga_reports);
158  
159 0 $rga_reports->reset;
160 0 ▶ while (my $r = $rga_reports->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $rga_reports->next) 0 0 0
161 0 ▶ if (my @report_failures = @{ $self->get_report_failures($r) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@report_failures) = @{$self->get_report_failures($r);}) 0 0 0
162 0 $c->stash->{failures}->{$r->id}{name} = $r->suite->name;
163 0 $c->stash->{failures}->{$r->id}{machine_name} = $r->machine_name;
164 0 my @descriptions = ();
165 0 my $sections = $r->reportsections;
166 0 ▶ while (my $section = $sections->next) { my %col = $section->get_columns; push @descriptions, $col{description} if $col{description} };
Branch: 2 branches
BranchTrueFalseTotal
if (my $section = $sections->next) 0 0 0
if $col{"description"} 0 0 0
167 0 $c->stash->{failures}->{$r->id}{report_description} = join(",", @descriptions);
168 0 push @{$c->stash->{failures}->{$r->id}{failures}}, @report_failures;
169 }
170 }
171 }
172  
173 0 ▶ if (my $rgt = $c->stash->{report}->reportgrouptestrun) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rgt = $c->stash->{"report"}->reportgrouptestrun) 0 0 0
174  
175 0 my @resource_requests = $c->model('TestrunDB')->resultset('TestrunRequestedResource')->search(
176 { testrun_id => $rgt->testrun_id, 'selected_resource_id' => { '!=', undef } },
177 { prefetch => 'selected_resource' }
178 )->all();
179 0 my @resources = map { $_->selected_resource } @resource_requests;
180 0 $c->stash->{resources} = \@resources;
181  
182 #my $rgt_reports = $c->model('TestrunDB')->resultset('ReportgroupTestrun')->search ({ testrun_id => $rgt->testrun_id });
183 0 my $rgt_reports = $c->model('TestrunDB')->resultset('Report')->search
184 (
185 {
186 "reportgrouptestrun.testrun_id" => $rgt->testrun_id
187 },
188 { order_by => 'me.id desc',
189 join => [ 'reportgrouparbitrary', 'reportgrouptestrun', 'suite'],
190 '+select' => [ 'reportgrouparbitrary.arbitrary_id', 'reportgrouparbitrary.primaryreport', 'reportgrouptestrun.testrun_id', 'reportgrouptestrun.primaryreport', 'suite.name', 'suite.type', 'suite.description' ],
191 '+as' => [ 'rga_id', 'rga_primary', 'rgt_id', 'rgt_primary', 'suite_name', 'suite_type', 'suite_description' ],
192 }
193 );
194 0 $c->stash->{reportlist_rgt} = $util_report->prepare_simple_reportlist($c, $rgt_reports);
195  
196 0 $rgt_reports->reset;
197 0 ▶ while (my $r = $rgt_reports->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $rgt_reports->next) 0 0 0
198 0 ▶ if (my @report_failures = @{ $self->get_report_failures($r) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@report_failures) = @{$self->get_report_failures($r);}) 0 0 0
199 0 $c->stash->{failures}->{$r->id}{name} = $r->suite->name;
200 0 $c->stash->{failures}->{$r->id}{machine_name} = $r->machine_name;
201 0 push @{$c->stash->{failures}->{$r->id}{failures}}, @report_failures;
202 }
203 }
204  
205 0 my %cols = $rgt_reports->search({}, {rows => 1})->first->get_columns;
206 0 my $testrun_id = $cols{rgt_id};
207 0 my $testrun;
208 0 eval {
209 0 $testrun = $c->model('TestrunDB')->resultset('Testrun')->find($testrun_id);
210 };
211 0 $c->stash->{overview} = $c->forward('/tapper/testruns/get_testrun_overview', [ $testrun ]);
212 }
213  
214 0 ▶ my $tmp = [ grep {defined($_->{rgt_primary}) and $_->{rgt_primary} == 1} @{$c->stash->{reportlist_rgt}->{all_reports}} ]->[0]->{suite_name};
Condition0%0/3
defined $_->{'rgt_primary'} && $_->{'rgt_primary'} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->{'rgt_primary'} && $_->{'rgt_primary'} == 1
defined $_->{'rgt_primary'} $_->{'rgt_primary'} == 1
Truth table0%0/3
A && B
A= defined $_->{'rgt_primary'}B= $_->{'rgt_primary'} == 1
ABresult
0X0
100
111
215 0 ▶ my $report_data = {suite => $c->stash->{report}->suite ? $c->stash->{report}->suite->name : 'unknownsuite' ,
Branch: 1 branch
BranchTrueFalseTotal
$c->stash->{'report'}->suite ? : 0 0 0
216 group_suite => $tmp};
217  
218 0 ▶ unless (my @report_failures = @{$c->stash->{failures}->{$c->stash->{report}->id}{failures} || []}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (my(@report_failures) = @{$c->stash->{"failures"}{$c->stash->{"report"}->id}{"failures"} or [];}) 0 0 0
Condition0%0/2
$c->stash->{'failures'}{$c->stash->{'report'}->id}{'failures'} || []
l!l
00
MC/DC0%0/1
$c->stash->{'failures'}{$c->stash->{'report'}->id}{'failures'} || []
$c->stash->{'failures'}{$c->stash->{'report'}->id}{'failures'}
Truth table0%0/2
A
A= $c->stash->{'failures'}{$c->stash->{'report'}->id}{'failures'}
Aresult
11
00
219 0 $c->stash->{failures}->{$c->stash->{report}->id}{name} = $c->stash->{report}->suite->name;
220 0 $c->stash->{failures}->{$c->stash->{report}->id}{machine_name} = $c->stash->{report}->machine_name;
221 0 push @{$c->stash->{failures}->{$c->stash->{report}->id}{failures}}, @report_failures;
222 }
223 0 %{$c->stash->{metareport}} = $self->generate_metareport_link($report_data);
224  
225 13 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
226  
227 13 1;
228  
229 __END__
« blib/lib/Tapper/Reports/Web/Controller/Tapper/Testplan.pm ↑ Summary blib/lib/Tapper/Reports/Web/Controller/Tapper/ReportFile/Id.pm »