Ver código fonte

Fix #156 - implement reports API

George S. Baugh 6 anos atrás
pai
commit
1dc6f62f52
4 arquivos alterados com 65 adições e 1 exclusões
  1. 3 0
      Changes
  2. 3 1
      dist.ini
  3. 44 0
      lib/TestRail/API.pm
  4. 15 0
      t/TestRail-API-57-methods.t

+ 3 - 0
Changes

@@ -1,5 +1,8 @@
 Revision history for Perl module TestRail::API
 
+0.045 2019-05-11 TEODESIAN
+    - Add getReports and runReport methods to TestRail::API
+
 0.044 2018-10-9 TEODESIAN
     - Add getCaseFields and addCaseField methods to TestRail::API
     - Correct argument POD for createRunInPlan

+ 3 - 1
dist.ini

@@ -1,6 +1,6 @@
 name = TestRail-API
 main_module = lib/TestRail/API.pm
-version = 0.044
+version = 0.045
 author = George S. Baugh <teodesian@cpan.org>
 license = Perl_5
 copyright_holder = George S. Baugh
@@ -136,6 +136,8 @@ stopwords = csv
 stopwords = addCaseField
 stopwords = bulkAddResults
 stopwords = getCaseFields
+stopwords = getReports
+stopwords = runReport
 
 [PkgVersion]
 [AutoPrereqs]

+ 44 - 0
lib/TestRail/API.pm

@@ -2675,6 +2675,50 @@ sub translateConfigNamesToIds {
     return _X_in_my_Y($self,$configs,'id',@names);
 }
 
+=head1 REPORT METHODS
+
+=head2 getReports
+
+Return the ARRAYREF of reports available for the provided project.
+
+Requires you to mark a particular report as accessible in the API via the TestRail report interface.
+
+=over 4
+
+=item INTEGER C<PROJECT_ID> - Relevant project ID.
+
+=back
+
+=cut
+
+sub getReports {
+    state $check = compile(Object, Int);
+    my ($self,$project_id) = $check->(@_);
+    my $url = "index.php?/api/v2/get_reports/$project_id";
+    return $self->_doRequest($url,'GET');
+}
+
+=head2 runReport
+
+Compute the provided report using currently available data.
+
+Returns HASHREF describing URLs to access completed reports.
+
+=over 4
+
+=item INTEGER C<REPORT_ID> - Relevant report ID.
+
+=back
+
+=cut
+
+sub runReport {
+    state $check = compile(Object, Int);
+    my ($self,$report_id) = $check->(@_);
+    my $url = "index.php?/api/v2/run_report/$report_id";
+    return $self->_doRequest($url,'GET');
+}
+
 =head1 STATIC METHODS
 
 =head2 B<buildStepResults(content,expected,actual,status_id)>

+ 15 - 0
t/TestRail-API-57-methods.t

@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Test::MockModule;
+
+use TestRail::API;
+
+my $mock = Test::MockModule->new('TestRail::API');
+$mock->redefine('_doRequest', sub { shift; return shift; } );
+
+my $obj = bless ({},'TestRail::API');
+
+like($obj->getReports(666),qr{get_reports/666$}, "Correct endpoint called for getReports");
+like($obj->runReport(22), qr{run_report/22$}, "Correct endpoitn called for runReport");