Przeglądaj źródła

Fix #88 by adding configuration methods

George S. Baugh 9 lat temu
rodzic
commit
0b9276538f

+ 5 - 0
lib/App/Prove/Plugin/TestRail.pm

@@ -48,6 +48,11 @@ If your system has no concept of user homes, it will look in the current directo
 
 See the documentation for the constructor of L<Test::Rail::Parser> as to why you might want to pass the aforementioned options.
 
+=head1 CAVEATS
+
+When running prove in multiple job mode (-j), or when breaking out test jobs into multiple prove processes, auto-spawn of plans & runs can race.
+Be sure to extend your harness to make sure these things are already created if you do either of these things.
+
 =head1 OVERRIDDEN METHODS
 
 =head2 load(parser)

+ 161 - 11
lib/TestRail/API.pm

@@ -173,13 +173,13 @@ sub _doRequest {
     my $response = $self->{'browser'}->request($req);
 
     #Uncomment to generate mocks
-    #use Data::Dumper;
-    #open(my $fh, '>>', 'mock.out');
-    #print $fh "{\n\n";
-    #print $fh Dumper($path,'200','OK',$response->headers,$response->content);
-    #print $fh '$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));';
-    #print $fh "\n\n}\n\n";
-    #close $fh;
+    use Data::Dumper;
+    open(my $fh, '>>', 'mock.out');
+    print $fh "{\n\n";
+    print $fh Dumper($path,'200','OK',$response->headers,$response->content);
+    print $fh '$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));';
+    print $fh "\n\n}\n\n";
+    close $fh;
 
     return $response if !defined($response); #worst case
     if ($response->code == 403) {
@@ -2189,7 +2189,6 @@ sub getTestResults {
 =head2 B<getConfigurationGroups(project_id)>
 
 Gets the available configuration groups for a project, with their configurations as children.
-Basically a direct wrapper of The 'get_configs' api call, with caching tacked on.
 
 =over 4
 
@@ -2206,9 +2205,84 @@ sub getConfigurationGroups {
     my ($self,$project_id) = $check->(@_);
 
     my $url = "index.php?/api/v2/get_configs/$project_id";
-    return $self->{'configurations'}->{$project_id} if $self->{'configurations'}->{$project_id}; #cache this since we can't change it with the API
-    $self->{'configurations'}->{$project_id} = $self->_doRequest($url);
-    return $self->{'configurations'}->{$project_id};
+    return $self->_doRequest($url);
+}
+
+=head2 B<addConfigurationGroup(project_id,name)>
+
+New in TestRail 5.2.
+
+Add a configuration group to the specified project.
+
+=over 4
+
+=item INTEGER C<PROJECT_ID> - ID of relevant project
+
+=item STRING C<NAME> - Name for new configuration Group.
+
+=back
+
+Returns HASHREF with new configuration group.
+
+=cut
+
+sub addConfigurationGroup {
+    state $check = compile(Object, Int, Str);
+    my ($self,$project_id,$name) = $check->(@_);
+
+    my $url = "index.php?/api/v2/add_config_group/$project_id";
+    return $self->_doRequest($url,'POST',{'name' => $name});
+}
+
+=head2 B<editConfigurationGroup(config_group_id,name)>
+
+New in TestRail 5.2.
+
+Change the name of a configuration group.
+
+=over 4
+
+=item INTEGER C<CONFIG_GROUP_ID> - ID of relevant configuration group
+
+=item STRING C<NAME> - Name for new configuration Group.
+
+=back
+
+Returns HASHREF with new configuration group.
+
+=cut
+
+sub editConfigurationGroup {
+    state $check = compile(Object, Int, Str);
+    my ($self,$config_group_id,$name) = $check->(@_);
+
+    my $url = "index.php?/api/v2/update_config_group/$config_group_id";
+    return $self->_doRequest($url,'POST',{'name' => $name});
+}
+
+=head2 B<deleteConfigurationGroup(config_group_id)>
+
+New in TestRail 5.2.
+
+Delete a configuration group.
+
+=over 4
+
+=item INTEGER C<CONFIG_GROUP_ID> - ID of relevant configuration group
+
+
+=back
+
+Returns BOOL.
+
+=cut
+
+sub deleteConfigurationGroup {
+    state $check = compile(Object, Int);
+    my ($self,$config_group_id) = $check->(@_);
+
+    my $url = "index.php?/api/v2/delete_config_group/$config_group_id";
+    return $self->_doRequest($url,'POST');
 }
 
 =head2 B<getConfigurations(project_id)>
@@ -2240,6 +2314,82 @@ sub getConfigurations {
     return $configs;
 }
 
+=head2 B<addConfiguration(configuration_group_id,name)>
+
+New in TestRail 5.2.
+
+Add a configuration to the specified configuration group.
+
+=over 4
+
+=item INTEGER C<CONFIGURATION_GROUP_ID> - ID of relevant configuration group
+
+=item STRING C<NAME> - Name for new configuration.
+
+=back
+
+Returns HASHREF with new configuration.
+
+=cut
+
+sub addConfiguration {
+    state $check = compile(Object, Int, Str);
+    my ($self,$configuration_group_id,$name) = $check->(@_);
+
+    my $url = "index.php?/api/v2/add_config/$configuration_group_id";
+    return $self->_doRequest($url,'POST',{'name' => $name});
+}
+
+=head2 B<editConfiguration(config_id,name)>
+
+New in TestRail 5.2.
+
+Change the name of a configuration.
+
+=over 4
+
+=item INTEGER C<CONFIG_ID> - ID of relevant configuration.
+
+=item STRING C<NAME> - New name for configuration.
+
+=back
+
+Returns HASHREF with new configuration group.
+
+=cut
+
+sub editConfiguration {
+    state $check = compile(Object, Int, Str);
+    my ($self,$config_id,$name) = $check->(@_);
+
+    my $url = "index.php?/api/v2/update_config/$config_id";
+    return $self->_doRequest($url,'POST',{'name' => $name});
+}
+
+=head2 B<deleteConfiguration(config_id)>
+
+New in TestRail 5.2.
+
+Delete a configuration.
+
+=over 4
+
+=item INTEGER C<CONFIG_ID> - ID of relevant configuration
+
+=back
+
+Returns BOOL.
+
+=cut
+
+sub deleteConfiguration {
+    state $check = compile(Object, Int);
+    my ($self,$config_id) = $check->(@_);
+
+    my $url = "index.php?/api/v2/delete_config/$config_id";
+    return $self->_doRequest($url,'POST');
+}
+
 =head2 B<translateConfigNamesToIds(project_id,configs)>
 
 Transforms a list of configuration names into a list of config IDs.

+ 16 - 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 => 81;
+use Test::More tests => 87;
 use Test::Fatal;
 use Test::Deep;
 use Scalar::Util ();
@@ -225,6 +225,21 @@ if ($is_arr) {
 my @t_config_ids = $tr->translateConfigNamesToIds($new_project->{'id'},@config_names);
 is_deeply(\@config_ids,\@t_config_ids, "Can correctly translate Project names to IDs, and they are correctly sorted");
 
+my $grp = $tr->addConfigurationGroup($new_project->{'id'},"zippy");
+is($grp->{'name'},'zippy',"Can add configuration group successfully");
+
+my $newgrp = $tr->editConfigurationGroup($grp->{'id'},"doodah");
+is($newgrp->{'name'},'doodah',"Can edit configuration group successfully");
+
+my $config = $tr->addConfiguration($grp->{'id'},"potzrebie");
+is($config->{'name'},"potzrebie","Can add configuration successfully");
+
+my $newconfig = $tr->editConfiguration($config->{'id'},"poyiut");
+is($newconfig->{'name'},"poyiut","Can edit configuration successfully");
+
+ok($tr->deleteConfiguration($config->{'id'}),"Can delete configuration successfully");
+ok($tr->deleteConfigurationGroup($grp->{'id'}),"Can delete group successfully");
+
 ############################################################
 # TestRail arbitrarily limits many calls to 250 result sets.
 # Let's make sure our getters actually get everything.

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

@@ -2745,6 +2745,169 @@ $mockObject->map_response(qr/\Q$VAR1\E$/,HTTP::Response->new($VAR2, $VAR3, $VAR4
 
 }
 
+#Configuration goodies
+{
+
+$VAR1 = 'index.php?/api/v2/add_config_group/9';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'connection' => 'close',
+                 'client-peer' => '192.168.122.217:80',
+                 'server' => 'Apache/2.4.7 (Ubuntu)',
+                 'content-length' => '51',
+                 '::std_case' => {
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-peer' => 'Client-Peer',
+                                   'client-response-num' => 'Client-Response-Num'
+                                 },
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.14',
+                 'client-date' => 'Thu, 18 Feb 2016 02:57:34 GMT',
+                 'client-response-num' => 1,
+                 'date' => 'Thu, 18 Feb 2016 02:57:34 GMT',
+                 'content-type' => 'application/json; charset=utf-8'
+               }, 'HTTP::Headers' );
+$VAR5 = '{"id":3,"name":"zippy","project_id":9,"configs":[]}';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
+{
+
+$VAR1 = 'index.php?/api/v2/update_config_group/3';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 '::std_case' => {
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-date' => 'Client-Date',
+                                   'client-peer' => 'Client-Peer',
+                                   'client-response-num' => 'Client-Response-Num'
+                                 },
+                 'client-peer' => '192.168.122.217:80',
+                 'connection' => 'close',
+                 'content-length' => '52',
+                 'server' => 'Apache/2.4.7 (Ubuntu)',
+                 'client-response-num' => 1,
+                 'content-type' => 'application/json; charset=utf-8',
+                 'date' => 'Thu, 18 Feb 2016 02:57:34 GMT',
+                 'client-date' => 'Thu, 18 Feb 2016 02:57:34 GMT',
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.14'
+               }, 'HTTP::Headers' );
+$VAR5 = '{"id":3,"name":"doodah","project_id":3,"configs":[]}';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
+{
+
+$VAR1 = 'index.php?/api/v2/add_config/3';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 '::std_case' => {
+                                   'client-peer' => 'Client-Peer',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-date' => 'Client-Date',
+                                   'client-response-num' => 'Client-Response-Num'
+                                 },
+                 'connection' => 'close',
+                 'client-peer' => '192.168.122.217:80',
+                 'content-length' => '40',
+                 'server' => 'Apache/2.4.7 (Ubuntu)',
+                 'client-response-num' => 1,
+                 'date' => 'Thu, 18 Feb 2016 02:57:34 GMT',
+                 'content-type' => 'application/json; charset=utf-8',
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.14',
+                 'client-date' => 'Thu, 18 Feb 2016 02:57:35 GMT'
+               }, 'HTTP::Headers' );
+$VAR5 = '{"id":2,"name":"potzrebie","group_id":3}';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
+{
+
+$VAR1 = 'index.php?/api/v2/update_config/2';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.14',
+                 'client-date' => 'Thu, 18 Feb 2016 02:57:35 GMT',
+                 'client-response-num' => 1,
+                 'content-type' => 'application/json; charset=utf-8',
+                 'date' => 'Thu, 18 Feb 2016 02:57:35 GMT',
+                 'connection' => 'close',
+                 'client-peer' => '192.168.122.217:80',
+                 'content-length' => '37',
+                 'server' => 'Apache/2.4.7 (Ubuntu)',
+                 '::std_case' => {
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-peer' => 'Client-Peer',
+                                   'client-response-num' => 'Client-Response-Num'
+                                 }
+               }, 'HTTP::Headers' );
+$VAR5 = '{"id":2,"name":"poyiut","group_id":3}';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
+{
+
+$VAR1 = 'index.php?/api/v2/delete_config/2';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'date' => 'Thu, 18 Feb 2016 02:57:35 GMT',
+                 'content-type' => 'application/json; charset=utf-8',
+                 'client-response-num' => 1,
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.14',
+                 'client-date' => 'Thu, 18 Feb 2016 02:57:35 GMT',
+                 '::std_case' => {
+                                   'client-response-num' => 'Client-Response-Num',
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-peer' => 'Client-Peer'
+                                 },
+                 'content-length' => '0',
+                 'server' => 'Apache/2.4.7 (Ubuntu)',
+                 'connection' => 'close',
+                 'client-peer' => '192.168.122.217:80'
+               }, 'HTTP::Headers' );
+$VAR5 = '';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
+{
+
+$VAR1 = 'index.php?/api/v2/delete_config_group/3';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'client-date' => 'Thu, 18 Feb 2016 02:57:35 GMT',
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.14',
+                 'content-type' => 'application/json; charset=utf-8',
+                 'date' => 'Thu, 18 Feb 2016 02:57:35 GMT',
+                 'client-response-num' => 1,
+                 'server' => 'Apache/2.4.7 (Ubuntu)',
+                 'content-length' => '0',
+                 'client-peer' => '192.168.122.217:80',
+                 'connection' => 'close',
+                 '::std_case' => {
+                                   'client-peer' => 'Client-Peer',
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-response-num' => 'Client-Response-Num'
+                                 }
+               }, 'HTTP::Headers' );
+$VAR5 = '';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
 sub lockMockStep0 {
 
 $VAR1 = 'index.php?/api/v2/get_tests/1099';