TestRail-API-mockOnly.t 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib "$FindBin::Bin/lib";
  5. #Test things we can only mock, because the API doesn't support them.
  6. use Test::More 'tests' => 14;
  7. use TestRail::API;
  8. use Test::LWP::UserAgent::TestRailMock;
  9. use Scalar::Util qw{reftype};
  10. use Capture::Tiny qw{capture};
  11. my $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  12. my $tr = TestRail::API->new('http://hokum.bogus','fake','fake',undef,1);
  13. $tr->{'browser'} = $browser;
  14. $tr->{'debug'} = 0;
  15. #Have to mock anything requiring configs
  16. my $project = $tr->getProjectByName('TestProject');
  17. my $plan = $tr->getPlanByName($project->{'id'},'HooHaaPlan');
  18. my $runs = $tr->getChildRuns($plan);
  19. is(reftype($runs),'ARRAY',"getChildRuns returns array");
  20. is(scalar(@$runs),4,"getChildRuns with multi-configs in the same group returns correct # of runs");
  21. my $summary = $tr->getPlanSummary($plan->{'id'});
  22. is($summary->{'plan'},1094,"Plan ID makes it through in summary method");
  23. is($summary->{'totals'}->{'Untested'},4,"Gets total number of tests correctly");
  24. is($summary->{'percentages'}->{'Untested'},'100.00%',"Gets total percentages correctly");
  25. #Also have to mock anything requiring test result fields (all are custom)
  26. my $projResType = $tr->getTestResultFieldByName('step_results');
  27. is($projResType->{'id'},6,"Can get result field by name");
  28. $projResType = $tr->getTestResultFieldByName('step_results',$project->{'id'});
  29. is($projResType->{'id'},6,"Can get result field by name, AND filter by project ID");
  30. $projResType = $tr->getTestResultFieldByName('moo_results');
  31. is($projResType,0,"Bad name returns no result field");
  32. $projResType = $tr->getTestResultFieldByName('step_results',66669);
  33. is($projResType,-3,"Bad project returns no result field");
  34. # I can't delete closed plans, so...test closePlan et cetera
  35. is(reftype($tr->closeRun(666)),'HASH',"Can close run that exists");
  36. my $res;
  37. capture { $res = $tr->closeRun(90210) };
  38. is($res,-404,"Can't close run that doesn't exist");
  39. is(reftype($tr->closePlan(23)),'HASH',"Can close plan that exists");
  40. capture { $res = $tr->closePlan(75020) };
  41. is($res,-404,"Can't close plan that doesn't exist");
  42. # Test case type method
  43. my $ct = $tr->getCaseTypeByName("Automated");
  44. is($ct->{'id'},1,"Can get case type by name");