Explorar el Código

Work on #118: paginate getRunResults

George S. Baugh hace 8 años
padre
commit
52c014ce16
Se han modificado 3 ficheros con 29 adiciones y 4 borrados
  1. 1 1
      Changes
  2. 27 1
      lib/TestRail/API.pm
  3. 1 2
      t/lib/Test/LWP/UserAgent/TestRailMock.pm

+ 1 - 1
Changes

@@ -2,7 +2,7 @@ Revision history for Perl module TestRail::API
 
 0.039 2017-02-20 TEODESIAN
     - Fix issue where follow_post_redirect could not be passed to constructor
-    - Add getRunResults Method in TestRail::API
+    - Add getRunResults, getRunResultsPaginated Methods in TestRail::API
 
 0.038 2017-01-23 TEODESIAN
     - Optimize TestRail::Utils::Find::getResults and testrail-results

+ 27 - 1
lib/TestRail/API.pm

@@ -1389,7 +1389,33 @@ you will need to use getTestResults.
 sub getRunResults {
     state $check = compile(Object, Int);
     my ($self,$run_id) = $check->(@_);
-    return $self->_doRequest("index.php?/api/v2/get_results_for_run/$run_id",'GET');
+
+    my $initial_results = $self->getRunResultsPaginated($run_id,$self->{'global_limit'},undef);
+    return $initial_results unless (reftype($initial_results) || 'undef') eq 'ARRAY';
+    my $results = [];
+    push(@$results,@$initial_results);
+    my $offset = 1;
+    while (scalar(@$initial_results) == $self->{'global_limit'}) {
+        $initial_results = $self->getPlansPaginated($run_id,$self->{'global_limit'},($self->{'global_limit'} * $offset));
+        push(@$results,@$initial_results);
+        $offset++;
+    }
+    return $results;
+}
+
+=head2 B<getRunResultsPaginated(run_id,limit,offset)
+
+=cut
+
+sub getRunResultsPaginated {
+    state $check = compile(Object, Int, Optional[Maybe[Int]], Optional[Maybe[Int]]);
+    my ($self,$run_id,$limit,$offset) = $check->(@_);
+
+    confess("Limit greater than ".$self->{'global_limit'}) if $limit > $self->{'global_limit'};
+    my $apiurl = "index.php?/api/v2/get_results_for_run/$run_id";
+    $apiurl .= "&offset=$offset" if defined($offset);
+    $apiurl .= "&limit=$limit" if $limit; #You have problems if you want 0 results
+    return $self->_doRequest($apiurl);
 }
 
 =head1 RUN AS CHILD OF PLAN METHODS

+ 1 - 2
t/lib/Test/LWP/UserAgent/TestRailMock.pm

@@ -3305,7 +3305,7 @@ $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4,
 
 {
 
-$VAR1 = 'index.php?/api/v2/get_results_for_run/22';
+$VAR1 = 'index.php?/api/v2/get_results_for_run/22&limit=250';
 $VAR2 = '200';
 $VAR3 = 'OK';
 $VAR4 = bless( {
@@ -3380,7 +3380,6 @@ $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4,
 
 }
 
-
 ###########
 #Lock mocks
 ###########