Bläddra i källkod

Fixes #15: Add get_configs method.

George S. Baugh 11 år sedan
förälder
incheckning
bce873b5e5
6 ändrade filer med 65 tillägg och 7 borttagningar
  1. 2 1
      Changes
  2. 29 0
      lib/Test/LWP/UserAgent/TestRailMock.pm
  3. 24 0
      lib/TestRail/API.pm
  4. 5 4
      t/TestRail-API.t
  5. 3 1
      t/arg_types.t
  6. 2 1
      t/server_dead.t

+ 2 - 1
Changes

@@ -1,10 +1,11 @@
 Revision history for Perl module TestRail::API
 
-0.014 2015-01-06 TEODESIAN
+0.014 2015-01-?? TEODESIAN
     - Fixed issue where testrail-report would not parse the results of multiple tests in a TAP file or stream.
     - Fixed issue where testrail-report would erroneously attempt to report the results of subtests.
     - Parse TODO/SKIP messages correctly, add todo reason to the test notes
     - Set SKIP_ALL tests status correctly
+    - Add TestRail::API::getConfigurations method
 
 0.013 2015-01-04 TEODESIAN
     - Remove usage of Types::Serialiser, and use JSON::MaybeXS (odd intermittent errors on testers)

+ 29 - 0
lib/Test/LWP/UserAgent/TestRailMock.pm

@@ -1341,4 +1341,33 @@ $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4,
 
 }
 
+
+{
+
+$VAR1 = 'index.php?/api/v2/get_configs/9';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'connection' => 'close',
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.5',
+                 'client-response-num' => 1,
+                 'date' => 'Tue, 23 Dec 2014 20:02:12 GMT',
+                 'client-peer' => '192.168.122.217:80',
+                 'content-length' => '0',
+                 '::std_case' => {
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-response-num' => 'Client-Response-Num',
+                                   'client-peer' => 'Client-Peer'
+                                 },
+                 'client-date' => 'Tue, 23 Dec 2014 20:02:12 GMT',
+                 'content-type' => 'application/json; charset=utf-8',
+                 'server' => 'Apache/2.4.7 (Ubuntu)'
+               }, 'HTTP::Headers' );
+$VAR5 = '[]';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
+
 1;

+ 24 - 0
lib/TestRail/API.pm

@@ -1652,6 +1652,30 @@ sub getTestResults {
     return $self->_doRequest($url);
 }
 
+=head1 CONFIGURATION METHODS
+
+=head2 B<getConfigurations(project_id)>
+
+Gets the available configurations for a project.
+
+=over 4
+
+=item INTEGER C<PROJECT_ID> - ID of relevant project
+
+=back
+
+Returns ARRAYREF of configuration definition HASHREFs.
+
+=cut
+
+sub getConfigurations {
+    my ($self,$project_id) = @_;
+    confess("Object methods must be called by an instance") unless ref($self);
+    confess("Test ID must be positive integer") unless $self->_checkInteger($project_id);
+    my $url = "index.php?/api/v2/get_configs/$project_id";
+    return $self->_doRequest($url);
+}
+
 =head1 STATIC METHODS
 
 =head2 B<buildStepResults(content,expected,actual,status_id)>

+ 5 - 4
t/TestRail-API.t

@@ -4,14 +4,11 @@ use warnings;
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 
-use Test::More tests => 51;
+use Test::More tests => 52;
 use Test::Fatal;
 use Scalar::Util 'reftype';
 use ExtUtils::MakeMaker qw{prompt};
 
-#XXX mock in the future...
-# ->{'browser'} and ->{'default_request'} would be the idea there...
-
 my $apiurl = $ENV{'TESTRAIL_API_URL'};
 my $login  = $ENV{'TESTRAIL_USER'};
 my $pw     = $ENV{'TESTRAIL_PASSWORD'};
@@ -133,6 +130,10 @@ ok(defined($result->{'id'}),"Can add test results");
 my $results = $tr->getTestResults($tests->[0]->{'id'});
 is($results->[0]->{'id'},$result->{'id'},"Can get results for test");
 
+#Test configuration methods
+my $configs = $tr->getConfigurations($new_project->{'id'});
+is(reftype($configs),'ARRAY',"Can get configurations for a project");
+
 #Delete a plan
 ok($tr->deletePlan($new_plan->{'id'}),"Can delete plan");
 

+ 3 - 1
t/arg_types.t

@@ -2,7 +2,7 @@ use strict;
 use warnings;
 
 use TestRail::API;
-use Test::More 'tests' => 113;
+use Test::More 'tests' => 115;
 use Test::Fatal;
 use Class::Inspector;
 use Test::LWP::UserAgent;
@@ -62,6 +62,7 @@ isnt( exception {$tr->getSections() },undef,'getSections returns error when no a
 isnt( exception {$tr->getRuns() },undef,'getRuns returns error when no arguments are passed');
 isnt( exception {$tr->getPlans() },undef,'getPlans returns error when no arguments are passed');
 isnt( exception {$tr->getMilestones() },undef,'getMilestones returns error when no arguments are passed');
+isnt( exception {$tr->getConfigurations() },undef,'getConfigurations returns error when no arguments are passed');
 
 #1-arg functions
 is(exception {$tr->deleteCase(1)},            undef,'deleteCase returns no error when int arg passed');
@@ -91,6 +92,7 @@ is(exception {$tr->getCaseTypeByName('zap')}, undef,'getCaseTypeByName returns n
 is(exception {$tr->createProject('zippy')},   undef,'createProject returns no error when string arg passed');
 is(exception {$tr->getTestResults(1)},        undef,'getTestResults with 1 arg returns no error');
 is(exception {$tr->getMilestoneByID(1)},      undef,'getMilestoneByID with 1 arg returns no error');
+is(exception {$tr->getConfigurations(1)},     undef,'getConfigurations with 1 arg returns no error');
 
 isnt(exception {$tr->createCase(1)}, undef,'createCase with 1 arg returns error');
 isnt(exception {$tr->createMilestone(1)}, undef,'createMilestone with 1 arg returns error');

+ 2 - 1
t/server_dead.t

@@ -5,7 +5,7 @@ use strict;
 use warnings;
 
 use TestRail::API;
-use Test::More 'tests' => 51;
+use Test::More 'tests' => 52;
 use Test::Fatal;
 use Class::Inspector;
 use Test::LWP::UserAgent;
@@ -68,3 +68,4 @@ is($tr->getUserByEmail('tickle'),0,'getUserByEmail returns error');
 is($tr->getUserByID(1),0,'getUserByID returns error');
 is($tr->getUserByName('zap'),0,'getUserByName returns error');
 is($tr->getUsers(),-500,'getUsers returns error');
+is($tr->getConfigurations(1),-500,'getConfigurations returns error');