TestRail-API-mockOnly.t 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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' => 18;
  7. use TestRail::API;
  8. use Test::LWP::UserAgent::TestRailMock;
  9. use Scalar::Util qw{reftype};
  10. use Capture::Tiny qw{capture capture_stderr};
  11. use Test::Fatal;
  12. my $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  13. my $tr = TestRail::API->new('http://hokum.bogus','fake','fake',undef,1);
  14. $tr->{'browser'} = $browser;
  15. $tr->{'debug'} = 0;
  16. #Have to mock anything requiring configs
  17. my $project = $tr->getProjectByName('TestProject');
  18. my $plan = $tr->getPlanByName($project->{'id'},'HooHaaPlan');
  19. my $runs = $tr->getChildRuns($plan);
  20. is(reftype($runs),'ARRAY',"getChildRuns returns array");
  21. is(scalar(@$runs),4,"getChildRuns with multi-configs in the same group returns correct # of runs");
  22. my $summary = $tr->getPlanSummary($plan->{'id'});
  23. is($summary->{'plan'},1094,"Plan ID makes it through in summary method");
  24. is($summary->{'totals'}->{'Untested'},4,"Gets total number of tests correctly");
  25. is($summary->{'percentages'}->{'Untested'},'100.00%',"Gets total percentages correctly");
  26. #Also have to mock anything requiring test result fields (all are custom)
  27. my $projResType = $tr->getTestResultFieldByName('step_results');
  28. is($projResType->{'id'},6,"Can get result field by name");
  29. $projResType = $tr->getTestResultFieldByName('step_results',$project->{'id'});
  30. is($projResType->{'id'},6,"Can get result field by name, AND filter by project ID");
  31. $projResType = $tr->getTestResultFieldByName('moo_results');
  32. is($projResType,0,"Bad name returns no result field");
  33. $projResType = $tr->getTestResultFieldByName('step_results',66669);
  34. is($projResType,-3,"Bad project returns no result field");
  35. # I can't delete closed plans, so...test closePlan et cetera
  36. is(reftype($tr->closeRun(666)),'HASH',"Can close run that exists");
  37. my $res;
  38. capture { $res = $tr->closeRun(90210) };
  39. is($res,-404,"Can't close run that doesn't exist");
  40. is(reftype($tr->closePlan(23)),'HASH',"Can close plan that exists");
  41. capture { $res = $tr->closePlan(75020) };
  42. is($res,-404,"Can't close plan that doesn't exist");
  43. # Test case type method
  44. my $ct = $tr->getCaseTypeByName("Automated");
  45. is($ct->{'id'},1,"Can get case type by name");
  46. #Test #142
  47. $tr = TestRail::API->new('http://locked.out','fake','fake',undef,1);
  48. $tr->{'browser'} = $browser;
  49. $tr->{'debug'} = 0;
  50. like( exception { $tr->getUsers() } , qr/stay out you red menace/i, "API dies on bad auth");
  51. $tr = TestRail::API->new('http://locked.out/worse','fake','fake',undef,1);
  52. $tr->{'browser'} = $browser;
  53. $tr->{'debug'} = 0;
  54. like( exception { $tr->getUsers() } , qr/could not find pants/i, "API dies on no auth or auth backend failure");
  55. $tr = TestRail::API->new('http://bork.bork','fake','fake',undef,1,undef,2);
  56. $tr->{'browser'} = $browser;
  57. $tr->{'debug'} = 0;
  58. $tr->{retry_delay} = 0;
  59. my $rc;
  60. my $oot = capture_stderr { $rc = $tr->getUsers() };
  61. like ($oot,qr/re-trying request/i, "Tried twice to make the call work");
  62. is($rc,-500,"Right code returned when re-tries run out");