浏览代码

Fix #67 by emitting summaries in their labels

George S. Baugh 10 年之前
父节点
当前提交
0dace2c92b
共有 5 个文件被更改,包括 41 次插入10 次删除
  1. 2 0
      Changes
  2. 2 2
      lib/Test/Rail/Parser.pm
  3. 33 4
      lib/TestRail/API.pm
  4. 2 2
      t/TestRail-API-mockOnly.t
  5. 2 2
      t/TestRail-API.t

+ 2 - 0
Changes

@@ -3,6 +3,8 @@ Revision history for Perl module TestRail::API
 0.031 2015-08-14 TEODESIAN
     - Update getCases to use testRail 4.0 filters, change filter args to HASHREF
     - Update TestRail::API::getCaseByName to take filter hashref too
+    - Update getRunSummary and getPlanSummary to use 'labels' rather than system names
+    - Add TestRail::API::statusNamesToLabels to ease interaction with above method updates
 
 0.030 2015-07-31 TEODESIAN
     - Fix testrail-tests, was calling function in incorrect namespace

+ 2 - 2
lib/Test/Rail/Parser.pm

@@ -557,14 +557,14 @@ sub _test_closure {
     if ($is_plan) {
         my $plan_summary = $self->{'tr_opts'}->{'testrail'}->getPlanSummary($id);
 
-        return if ( $plan_summary->{'totals'}->{'untested'} + $plan_summary->{'totals'}->{'retest'} );
+        return if ( $plan_summary->{'totals'}->{'Untested'} + $plan_summary->{'totals'}->{'Retest'} );
         print "# No more outstanding cases detected.  Closing Plan.\n";
         $self->{'plan_closed'} = 1;
         return $self->{'tr_opts'}->{'testrail'}->closePlan($id);
     }
 
     my ($run_summary) = $self->{'tr_opts'}->{'testrail'}->getRunSummary($id);
-    return if ( $run_summary->{'run_status'}->{'untested'} + $run_summary->{'run_status'}->{'retest'} );
+    return if ( $run_summary->{'run_status'}->{'Untested'} + $run_summary->{'run_status'}->{'Retest'} );
     print "# No more outstanding cases detected.  Closing Run.\n";
     $self->{'run_closed'} = 1;
     return $self->{'tr_opts'}->{'testrail'}->closeRun($self->{'tr_opts'}->{'run_id'});

+ 33 - 4
lib/TestRail/API.pm

@@ -1268,6 +1268,7 @@ sub getRunSummary {
     my %shash;
     #XXX so, they do these tricks with the status names, see...so map the counts to their relevant status ids.
     @shash{map { ( $_->{'id'} < 6 ) ? $_->{'name'}."_count" : "custom_status".($_->{'id'} - 5)."_count" } @$statuses } = map { $_->{'id'} } @$statuses;
+
     my @sname;
     #Create listing of keys/values
     @$runs = map {
@@ -1276,7 +1277,7 @@ sub getRunSummary {
         foreach my $status (keys(%{$run->{'statuses'}})) {
             next if !exists($shash{$status});
             @sname = grep {exists($shash{$status}) && $_->{'id'} == $shash{$status}} @$statuses;
-            $run->{'statuses_clean'}->{$sname[0]->{'name'}} = $run->{$status};
+            $run->{'statuses_clean'}->{$sname[0]->{'label'}} = $run->{$status};
         }
         $run;
     } @$runs;
@@ -1990,8 +1991,36 @@ Throws an exception in the case of one (or more) of the names not corresponding
 =cut
 
 sub statusNamesToIds {
-    state $check = compile(Object, slurpy ArrayRef[Str]);
-    my ($self,$names) = $check->(@_);
+    my ($self,@names) = @_;
+    return _statusNamesToX($self,'id',@names);
+};
+
+=head2 statusNamesToLabels(names)
+
+Convenience method to translate a list of statuses to TestRail status labels (the 'nice' form of status names).
+This is useful when interacting with getRunSummary or getPlanSummary, which uses these labels as hash keys.
+
+=over 4
+
+=item ARRAY C<NAMES> - Array of status names to translate to IDs.
+
+=back
+
+Returns ARRAY of status labels in the same order as the status names passed.
+
+Throws an exception in the case of one (or more) of the names not corresponding to a valid test status.
+
+=cut
+
+sub statusNamesToLabels {
+    my ($self,@names) = @_;
+    return _statusNamesToX($self,'label',@names);
+};
+
+#Reduce code duplication
+sub _statusNamesToX {
+    state $check = compile(Object, Str, slurpy ArrayRef[Str]);
+    my ($self,$key,$names) = $check->(@_);
     confess("No status names passed!") unless scalar(@$names);
 
     my $statuses = $self->getPossibleTestStatuses();
@@ -1999,7 +2028,7 @@ sub statusNamesToIds {
     foreach my $name (@$names) {
         foreach my $status (@$statuses) {
             if ($status->{'name'} eq $name) {
-                push @ret, $status->{'id'};
+                push @ret, $status->{$key};
                 last;
             }
         }

+ 2 - 2
t/TestRail-API-mockOnly.t

@@ -25,8 +25,8 @@ is(scalar(@$runs),4,"getChildRuns with multi-configs in the same group returns c
 
 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");
+is($summary->{'totals'}->{'Untested'},4,"Gets total number of tests correctly");
+is($summary->{'percentages'}->{'Untested'},'100.00%',"Gets total percentages correctly");
 
 #Also have to mock anything requiring test result fields (all are custom)
 my $projResType = $tr->getTestResultFieldByName('step_results');

+ 2 - 2
t/TestRail-API.t

@@ -199,8 +199,8 @@ is(scalar(@$filteredTests),0,"Test Filtering works: status id undef, user id neg
 my $runs = $tr->getRuns($new_project->{'id'});
 my ($summary) = $tr->getRunSummary(@$runs); #I only care about the first one
 isnt($summary->{'run_status'},undef,"Can get run statuses correctly");
-is($summary->{'run_status'}->{'passed'},int(!$is_mock),"Gets # of passed cases correctly");
-is($summary->{'run_status'}->{'untested'},int($is_mock),"Gets # of untested cases correctly");
+is($summary->{'run_status'}->{'Passed'},int(!$is_mock),"Gets # of passed cases correctly");
+is($summary->{'run_status'}->{'Untested'},int($is_mock),"Gets # of untested cases correctly");
 
 #Test configuration methods
 my $configs = $tr->getConfigurations($new_project->{'id'});