소스 검색

Fix #148, add case field methods

George S. Baugh 7 년 전
부모
커밋
8258d3532d
5개의 변경된 파일71개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 0
      Changes
  2. 1 1
      dist.ini
  3. 34 0
      lib/TestRail/API.pm
  4. 31 0
      t/TestRail-API-casefields.t
  5. 2 0
      t/TestRail-API-mockOnly.t

+ 3 - 0
Changes

@@ -1,5 +1,8 @@
 Revision history for Perl module TestRail::API
 
+0.044 2018-10-9 TEODESIAN
+    - Add getCaseFields and addCaseField methods to TestRail::API
+
 0.043 2018-6-16 TEODESIAN
     - Better error messaging when bad custom result fields are configured in Test::Rail::Parser
 

+ 1 - 1
dist.ini

@@ -1,6 +1,6 @@
 name = TestRail-API
 main_module = lib/TestRail/API.pm
-version = 0.043
+version = 0.044
 author = George S. Baugh <teodesian@cpan.org>
 license = Perl_5
 copyright_holder = George S. Baugh

+ 34 - 0
lib/TestRail/API.pm

@@ -1158,6 +1158,40 @@ sub getCaseByID {
     return $self->_doRequest("index.php?/api/v2/get_case/$case_id");
 }
 
+=head2 getCaseFields
+
+Returns ARRAYREF of available test case custom fields.
+
+    $tr->getCaseFields();
+
+Output is cached in the case_fields parameter.  Cache is invalidated when addCaseField is called.
+
+=cut
+
+sub getCaseFields {
+    state $check = compile(Object);
+    my ($self) = $check->(@_);
+    return $self->{case_fields} if $self->{case_fields};
+
+    $self->{case_fields} = $self->_doRequest("index.php?/api/v2/get_case_fields");
+    return $self->{case_fields};
+}
+
+=head2 addCaseField(%options)
+
+Returns HASHREF describing the case field you just added.
+
+    $tr->addCaseField(%options)
+
+=cut
+
+sub addCaseField {
+    state $check = compile(Object,slurpy HashRef);
+    my ($self,$options) = $check->(@_);
+    $self->{case_fields} = undef;
+    return $self->_doRequest("index.php?/api/v2/add_case_field", 'POST', $options);
+}
+
 =head1 RUN METHODS
 
 =head2 B<createRun (project_id,suite_id,name,description,milestone_id,assigned_to_id,case_ids)>

+ 31 - 0
t/TestRail-API-casefields.t

@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use Test::Deep;
+
+use TestRail::API;
+
+{
+    my $this = { this => 'thing' };
+    my $that = { that => 'thing' };
+    my $theOther = { other => 'thing'};
+
+    no warnings qw{redefine once};
+    local *TestRail::API::_doRequest= sub { return $this };
+    use warnings;
+
+    my $tr = bless({},'TestRail::API');
+
+    is_deeply($tr->getCaseFields(),$this, "getCaseFields appears to operate correctly on initial hit");
+
+    no warnings qw{redefine once};
+    local *TestRail::API::_doRequest= sub { my ($self,$url, $method, $input) = @_; return $that unless $method; return $input };
+    use warnings;
+
+    is_deeply($tr->getCaseFields(),$this, "getCaseFields caches correctly");
+    is_deeply($tr->addCaseField(%$theOther),$theOther,"addCaseField appears to grab and pass options correctly");
+
+    is_deeply($tr->getCaseFields(),$that, "getCaseFields invalidates cache correctly");
+
+}

+ 2 - 0
t/TestRail-API-mockOnly.t

@@ -75,3 +75,5 @@ my $rc;
 my $oot = capture_stderr { $rc = $tr->getUsers() };
 like ($oot,qr/re-trying request/i, "Tried twice to make the call work");
 is($rc,-500,"Right code returned when re-tries run out");
+
+