Explorar o código

Work on #118: add TestRail::API::getRunResults()

George S. Baugh %!s(int64=8) %!d(string=hai) anos
pai
achega
f01947f69e
Modificáronse 4 ficheiros con 105 adicións e 1 borrados
  1. 1 0
      Changes
  2. 22 0
      lib/TestRail/API.pm
  3. 5 1
      t/TestRail-API.t
  4. 77 0
      t/lib/Test/LWP/UserAgent/TestRailMock.pm

+ 1 - 0
Changes

@@ -2,6 +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
 
 0.038 2017-01-23 TEODESIAN
     - Optimize TestRail::Utils::Find::getResults and testrail-results

+ 22 - 0
lib/TestRail/API.pm

@@ -1370,6 +1370,28 @@ sub getRunSummary {
 
 }
 
+=head2 B<getRunResults(run_id)>
+
+Returns array of hashrefs describing the results of the run.
+
+Warning: This only returns the most recent results of a run.
+If you want to know about the tortured journey a test may have taken to get to it's final status,
+you will need to use getTestResults.
+
+=over 4
+
+=item INTEGER C<RUN_ID> - Relevant Run's ID.
+
+=back
+
+=cut
+
+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');
+}
+
 =head1 RUN AS CHILD OF PLAN METHODS
 
 =head2 B<getChildRuns(plan)>

+ 5 - 1
t/TestRail-API.t

@@ -7,7 +7,7 @@ use lib "$FindBin::Bin/lib";
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 
-use Test::More tests => 89;
+use Test::More tests => 90;
 use Test::Fatal;
 use Test::Deep;
 use Scalar::Util ();
@@ -218,6 +218,10 @@ 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");
 
+#Get run results
+my $results = $tr->getRunResults($new_run->{'id'});
+is(scalar(@$results),3,"Correct # of results returned by getRunResults");
+
 #Test configuration methods
 my $configs = $tr->getConfigurations($new_project->{'id'});
 my $is_arr = is(Scalar::Util::reftype($configs),'ARRAY',"Can get configurations for a project");

+ 77 - 0
t/lib/Test/LWP/UserAgent/TestRailMock.pm

@@ -3303,6 +3303,83 @@ $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4,
 
 }
 
+{
+
+$VAR1 = 'index.php?/api/v2/get_results_for_run/22';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'client-ssl-socket-class' => 'IO::Socket::SSL',
+                 'connection' => 'close',
+                 'client-response-num' => 1,
+                 'client-peer' => '192.168.122.217:80',
+                 '::std_case' => {
+                                   'client-peer' => 'Client-Peer',
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-response-num' => 'Client-Response-Num',
+                                   'client-ssl-socket-class' => 'Client-SSL-Socket-Class',
+                                   'client-transfer-encoding' => 'Client-Transfer-Encoding',
+                                   'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',
+                                   'client-ssl-cipher' => 'Client-SSL-Cipher',
+                                   'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',
+                                   'strict-transport-security' => 'Strict-Transport-Security'
+                                 },
+                 'x-powered-by' => 'PHP/5.6.26',
+                 'client-date' => 'Mon, 20 Feb 2017 17:10:10 GMT',
+                 'strict-transport-security' => 'max-age=63072000;',
+                 'date' => 'Mon, 20 Feb 2017 17:07:58 GMT',
+                 'content-type' => 'application/json; charset=utf-8',
+                 'server' => 'Apache/2.2.15 (CentOS)',
+                 'client-ssl-cipher' => 'ECDHE-RSA-AES128-GCM-SHA256',
+                 'client-transfer-encoding' => [
+                                                 'chunked'
+                                               ]
+               }, 'HTTP::Headers' );
+$VAR5 = '[
+          {
+            "assignedto_id":1,
+            "created_by":22,
+            "comment":"Zippy",
+            "test_id":1,
+            "defects":[],
+            "id":12345,
+            "created_on":1480726605,
+            "version":"333",
+            "status_id":2,
+            "custom_step_results":0,
+            "elapsed":123
+          },
+          {
+            "assignedto_id":1,
+            "created_by":22,
+            "comment":"Zippy",
+            "test_id":2,
+            "defects":[],
+            "id":12346,
+            "created_on":1480726605,
+            "version":"333",
+            "status_id":2,
+            "custom_step_results":0,
+            "elapsed":123
+          },
+          {
+            "assignedto_id":1,
+            "created_by":22,
+            "comment":"Zippy",
+            "test_id":3,
+            "defects":[],
+            "id":12347,
+            "created_on":1480726605,
+            "version":"333",
+            "status_id":2,
+            "custom_step_results":0,
+            "elapsed":123
+          }]';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
 
 ###########
 #Lock mocks