Sfoglia il codice sorgente

Fix #46 : add plan summarizer, tests

George S. Baugh 10 anni fa
parent
commit
7e049e14f0
2 ha cambiato i file con 50 aggiunte e 2 eliminazioni
  1. 44 1
      lib/TestRail/API.pm
  2. 6 1
      t/TestRail-API-mockOnly.t

+ 44 - 1
lib/TestRail/API.pm

@@ -1255,7 +1255,7 @@ sub getRunSummary {
         $run;
     } @runs;
 
-    return map { {'id' => $_->{'id'}, 'name' => $_->{'name'}, 'run_status' => $_->{'statuses_clean'}} } @runs;
+    return map { {'id' => $_->{'id'}, 'name' => $_->{'name'}, 'run_status' => $_->{'statuses_clean'}, 'config_ids' => $_->{'config_ids'} } } @runs;
 
 }
 
@@ -1545,6 +1545,49 @@ sub getPlanByID {
     return $self->_doRequest("index.php?/api/v2/get_plan/$plan_id");
 }
 
+=head2 B<getPlanSummary(plan_ID)>
+
+Returns hashref describing the various pass, fail, etc. percentages for tests in the plan.
+
+=over 4
+
+=item SCALAR C<plan_ID> - ID of your test plan.
+
+=back
+
+    $tr->getPlanSummary($plan_id);
+
+=cut
+
+sub getPlanSummary {
+    my ($self,$plan_id) = @_;
+    confess("Object methods must be called by an instance") unless ref($self);
+    confess("Plan ID must be integer") unless $self->_checkInteger($plan_id);
+    my $runs = $self->getPlanByID( $plan_id );
+    $runs = $self->getChildRuns( $runs );
+    @$runs = $self->getRunSummary(@{$runs});
+    my $total_sum = 0;
+    my $ret = { plan => $plan_id };
+
+    #Compile totals
+    foreach my $summary ( @$runs ) {
+        my @elems = keys( $summary->{'run_status'} );
+        foreach my $key (@elems) {
+            $ret->{'totals'}->{$key} = 0 if !defined $ret->{'totals'}->{$key};
+            $ret->{'totals'}->{$key} += $summary->{'run_status'}->{$key};
+            $total_sum += $summary->{'run_status'}->{$key};
+        }
+    }
+
+    #Compile percentages
+    foreach my $key (keys(%{$ret->{'totals'}})) {
+        next if grep {$_ eq $key} qw{plan configs percentages};
+        $ret->{"percentages"}->{$key} = sprintf( "%.2f%%", ( $ret->{'totals'}->{$key} / $total_sum ) * 100 );
+    }
+
+    return $ret;
+}
+
 =head2 B<createRunInPlan (plan_id,suite_id,name,description,milestone_id,assigned_to_id,config_ids,case_ids)>
 
 Create a run.

+ 6 - 1
t/TestRail-API-mockOnly.t

@@ -3,7 +3,7 @@ use warnings;
 
 #Test things we can only mock, because the API doesn't support them.
 
-use Test::More 'tests' => 2;
+use Test::More 'tests' => 5;
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 use Scalar::Util qw{reftype};
@@ -18,3 +18,8 @@ my $plan    = $tr->getPlanByName($project->{'id'},'HooHaaPlan');
 my $runs = $tr->getChildRuns($plan);
 is(reftype($runs),'ARRAY',"getChildRuns returns array");
 is(scalar(@$runs),4,"getChildRuns with multi-configs in the same group returns correct # of runs");
+
+my $summary = $tr->getPlanSummary($plan->{'id'});
+is($summary->{'plan'},1094,"Plan ID makes it through in summary method");
+is($summary->{'totals'}->{'untested'},4,"Gets total number of tests correctly");
+is($summary->{'percentages'}->{'untested'},'100.00%',"Gets total percentages correctly");