PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/extensions/testopia/t/API_TestRun.pm

https://code.google.com/p/bugzilla4intranet/
Perl | 424 lines | 269 code | 120 blank | 35 comment | 23 complexity | da89800ad82f2be7299d21c0696f0cdc MD5 | raw file
  1. # -*- Mode: perl; indent-tabs-mode: nil -*-
  2. #
  3. # The contents of this file are subject to the Mozilla Public
  4. # License Version 1.1 (the "License"); you may not use this file
  5. # except in compliance with the License. You may obtain a copy of
  6. # the License at http://www.mozilla.org/MPL/
  7. #
  8. # Software distributed under the License is distributed on an "AS
  9. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. # implied. See the License for the specific language governing
  11. # rights and limitations under the License.
  12. #
  13. # The Original Code is the Bugzilla Testopia System.
  14. #
  15. # The Initial Developer of the Original Code is Greg Hendricks.
  16. # Portions created by Greg Hendricks are Copyright (C) 2006
  17. # Novell. All Rights Reserved.
  18. #
  19. # Contributor(s): Greg Hendricks <ghendricks@novell.com>
  20. # Jeff Dayley <jedayley@novell.com>
  21. package API_TestRun;
  22. use strict;
  23. use base qw(Test::Unit::TestCase);
  24. use lib ".";
  25. use lib "../..";
  26. use Bugzilla;
  27. use Testopia::TestRun;
  28. use Testopia::Search;
  29. use Testopia::Table;
  30. use Testopia::Test::Constants;
  31. use Testopia::Test::API::Util;
  32. use Testopia::Test::Util;
  33. use Test::More;
  34. use Test::Deep;
  35. # The the XMLRPC::Lite proxy handle
  36. our $proxy = proxy( LOGIN_CREDENTIALS->{'admin'} );
  37. sub new {
  38. my $self = shift()->SUPER::new(@_);
  39. return $self;
  40. }
  41. sub set_up {
  42. my $self = shift;
  43. }
  44. sub tear_down {
  45. my $self = shift;
  46. }
  47. sub test_create_by_id {
  48. my $self = shift;
  49. my $plan = Testopia::TestPlan->new( get_rep('test_plans')->{'plan_id'} );
  50. while (scalar @{ $plan->test_cases } == 0
  51. || scalar @{ $plan->product->environments } == 0
  52. || scalar @{ $plan->product->builds } == 0 )
  53. {
  54. $plan = Testopia::TestPlan->new( get_rep('test_plans')->{'plan_id'} );
  55. }
  56. my @cases = @{ $plan->test_cases };
  57. my @builds = @{ $plan->product->builds };
  58. my @envs = @{ $plan->product->environments };
  59. my $case = $cases[ int( rand( scalar @cases ) ) ];
  60. my $build = $builds[ int( rand( scalar @builds ) ) ];
  61. my $env = $envs[ int( rand( scalar @envs ) ) ];
  62. my $response = $proxy->call(
  63. "TestRun.create",
  64. {
  65. plan_id => $plan->{'plan_id'},
  66. build => $build->{'build_id'},
  67. environment => $env->{'environment_id'},
  68. manager => get_rep('profiles')->{'userid'},
  69. summary => 'API TEST RUN CREATE ' . time(),
  70. product_version => $plan->product_version,
  71. plan_text_version => $plan->version,
  72. notes => 'API TEST RUN NOTES' . time(),
  73. status => 1,
  74. target_pass => 90,
  75. target_completion => 95,
  76. cases => [ get_rep('test_cases')->{'case_id'}, get_rep('test_cases')->{'case_id'} ],
  77. }
  78. );
  79. check_fault( $response, $self );
  80. my $obj = Testopia::TestRun->new( $response->result->{'run_id'} );
  81. $obj->build;
  82. convert_undef($obj);
  83. # dump_all($response->result, $obj);
  84. cmp_deeply( $response->result, noclass($obj), "TestRun - test_create_by_id" );
  85. }
  86. sub test_create_by_string {
  87. my $self = shift;
  88. my $plan = Testopia::TestPlan->new( get_rep('test_plans')->{'plan_id'} );
  89. while (scalar @{ $plan->test_cases } == 0
  90. || scalar @{ $plan->product->environments } == 0
  91. || scalar @{ $plan->product->builds } == 0 )
  92. {
  93. $plan = Testopia::TestPlan->new( get_rep('test_plans')->{'plan_id'} );
  94. }
  95. my @cases = @{ $plan->test_cases };
  96. my @builds = @{ $plan->product->builds };
  97. my @envs = @{ $plan->product->environments };
  98. my $case = $cases[ int( rand( scalar @cases ) ) ];
  99. my $build = $builds[ int( rand( scalar @builds ) ) ];
  100. my $env = $envs[ int( rand( scalar @envs ) ) ];
  101. my $response = $proxy->call(
  102. "TestRun.create",
  103. {
  104. plan_id => $plan->{'plan_id'},
  105. build => $build->{'name'},
  106. environment => $env->{'name'},
  107. manager => get_rep('profiles')->{'login_name'},
  108. summary => 'API TEST RUN CREATE ' . time(),
  109. }
  110. );
  111. check_fault( $response, $self );
  112. my $obj = Testopia::TestRun->new( $response->result->{'run_id'} );
  113. convert_undef($obj);
  114. # dump_all($response->result, $obj);
  115. cmp_deeply( $response->result, noclass($obj), "TestRun - test_create_by_string" );
  116. }
  117. sub test_get {
  118. my $self = shift;
  119. my $rep = get_rep('test_runs');
  120. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  121. $obj->{'case_count'} = $obj->case_count();
  122. convert_undef($obj);
  123. my $response = $proxy->call( "TestRun.get", $rep->{'run_id'} );
  124. check_fault( $response, $self );
  125. # dump_all($response->result, $obj);
  126. cmp_deeply( $response->result, noclass($obj), "TestRun - test_get" );
  127. }
  128. sub test_add_cases {
  129. my $self = shift;
  130. my $response = $proxy->call( "TestRun.add_cases",
  131. [get_rep('test_cases')->{'case_id'}, get_rep('test_cases')->{'case_id'}],
  132. [get_rep('test_runs')->{'run_id'}]
  133. );
  134. check_fault( $response, $self );
  135. # dump_all($response->result, $obj);
  136. ok( scalar @{$response->result} == 0, "TestRun - test_add_cases" );
  137. }
  138. sub test_update {
  139. my $self = shift;
  140. my $plan = Testopia::TestPlan->new( get_rep('test_plans')->{'plan_id'} );
  141. while (scalar @{ $plan->test_cases } == 0
  142. || scalar @{ $plan->product->environments } == 0
  143. || scalar @{ $plan->product->builds } == 0 )
  144. {
  145. $plan = Testopia::TestPlan->new( get_rep('test_plans')->{'plan_id'} );
  146. }
  147. my @cases = @{ $plan->test_cases };
  148. my @builds = @{ $plan->product->builds };
  149. my @envs = @{ $plan->product->environments };
  150. my @versions = @{ $plan->product->versions };
  151. my $case = $cases[ int( rand( scalar @cases ) ) ];
  152. my $build = $builds[ int( rand( scalar @builds ) ) ];
  153. my $env = $envs[ int( rand( scalar @envs ) ) ];
  154. my $version = $versions[ int( rand( scalar @versions ) ) ];
  155. my $rep = get_rep('test_runs');
  156. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  157. my $response = $proxy->call(
  158. "TestRun.update",
  159. $rep->{'run_id'},
  160. {
  161. plan_id => $plan->{'plan_id'},
  162. build => $build->{'build_id'},
  163. environment => $env->{'environment_id'},
  164. manager => get_rep('profiles')->{'userid'},
  165. summary => 'API TEST RUN UPDATE ' . time(),
  166. product_version => $version->{'value'},
  167. plan_text_version => $plan->version,
  168. notes => 'API TEST RUN NOTES' . time(),
  169. target_pass => 90,
  170. target_completion => 95,
  171. status => 1,
  172. }
  173. );
  174. # Get the newly updated object to compare with
  175. $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  176. convert_undef($obj);
  177. check_fault( $response, $self );
  178. cmp_deeply( $response->result, noclass($obj), "TestRun - test_update" );
  179. }
  180. sub test_list {
  181. my $self = shift;
  182. my $cgi = Bugzilla->cgi;
  183. $cgi->param( "current_tab", "run" );
  184. $cgi->param( "pagesize", 25 );
  185. $cgi->param( 'distinct', 1 );
  186. $cgi->param( "Bugzilla_login", LOGIN_CREDENTIALS->{'admin'}->{'login_name'} );
  187. $cgi->param( "Bugzilla_password", LOGIN_CREDENTIALS->{'admin'}->{'password'} );
  188. Bugzilla->login();
  189. my $search = Testopia::Search->new($cgi);
  190. my $table =
  191. Testopia::Table->new( 'run', 'tr_xmlrpc.cgi', $cgi, undef, $search->query() );
  192. convert_undef( $table->list );
  193. my $response = $proxy->call( "TestRun.list", { pagesize => 25, } );
  194. check_fault( $response, $self );
  195. cmp_deeply( $response->result, noclass( $table->list ), "TestRun - test_list" );
  196. $response = $proxy->call( "TestRun.list_count", { pagesize => 25, } );
  197. ok($response->result == $table->list_count, 'list_count');
  198. }
  199. sub test_add_tag {
  200. my $self = shift;
  201. my $rep = get_rep('test_runs');
  202. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  203. my $orig_size = scalar @{ $obj->tags };
  204. delete $obj->{'tags'};
  205. my $tag = get_rep('test_tags');
  206. my $response = $proxy->call( "TestRun.add_tag", $rep->{'run_id'}, $tag->{'tag_name'} );
  207. check_fault( $response, $self );
  208. # dump_all($tag, $obj->tags);
  209. ok( scalar @{ $obj->tags } == ( $orig_size + 1 ), "TestRun - test_add_tag" );
  210. }
  211. sub test_get_bugs {
  212. my $self = shift;
  213. my $rep = get_rep('test_case_bugs');
  214. while ( !$rep->{'case_run_id'} ) {
  215. $rep = get_rep('test_case_bugs');
  216. }
  217. my $cr = Testopia::TestCaseRun->new( $rep->{'case_run_id'} );
  218. my $obj = Testopia::TestRun->new( $cr->run_id );
  219. my $response = $proxy->call( "TestRun.get_bugs", $cr->run_id );
  220. check_fault( $response, $self );
  221. my $list = $obj->bugs;
  222. convert_undef($list);
  223. # dump_all($obj->bugs, $response->result);
  224. cmp_deeply( $response->result, noclass($list), "TestRun - test_get_bugs" );
  225. }
  226. sub test_get_change_history {
  227. my $self = shift;
  228. my $rep = get_rep('test_run_activity');
  229. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  230. my $response = $proxy->call( "TestRun.get_change_history", $rep->{'run_id'} );
  231. check_fault( $response, $self );
  232. my $list = $obj->history;
  233. convert_undef($list);
  234. # dump_all($list, $response->result);
  235. cmp_deeply( $response->result, $list, "TestRun - test_get_change_history" );
  236. }
  237. sub test_get_completion_report {
  238. my $self = shift;
  239. my $rep = get_rep('test_case_runs');
  240. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  241. my $response = $proxy->call( "TestRun.get_completion_report", $rep->{'run_id'} );
  242. check_fault( $response, $self );
  243. # dump_all($obj, $response->result);
  244. isa_ok( $response->result, 'HASH', "TestRun - test_get_completion_report" );
  245. }
  246. sub test_get_tags {
  247. my $self = shift;
  248. my $rep = get_rep('test_run_tags');
  249. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  250. my $response = $proxy->call( "TestRun.get_tags", $rep->{'run_id'} );
  251. check_fault( $response, $self );
  252. my @results;
  253. foreach my $tag ( @{ $obj->tags } ) {
  254. push @results, $tag->name;
  255. }
  256. # dump_all(\@results, $response->result);
  257. cmp_deeply( $response->result, \@results, "TestRun - test_get_tags" );
  258. }
  259. sub test_get_test_case_runs {
  260. my $self = shift;
  261. my $rep = get_rep('test_case_runs');
  262. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  263. my $response = $proxy->call( "TestRun.get_test_case_runs", $rep->{'run_id'} );
  264. check_fault( $response, $self );
  265. my $list = $obj->caseruns;
  266. convert_undef($list);
  267. # dump_all($obj, $response->result);
  268. cmp_deeply( $response->result, noclass($list), "TestRun - test_get_test_case_runs" );
  269. }
  270. sub test_get_test_cases {
  271. my $self = shift;
  272. my $rep = get_rep('test_case_runs');
  273. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  274. my $response = $proxy->call( "TestRun.get_test_cases", $rep->{'run_id'} );
  275. check_fault( $response, $self );
  276. my $list = $obj->cases;
  277. convert_undef($list);
  278. # dump_all($obj, $response->result);
  279. cmp_deeply( $response->result, noclass( $list ), "TestRun - test_get_test_cases" );
  280. }
  281. sub test_get_test_plan {
  282. my $self = shift;
  283. my $rep = get_rep('test_runs');
  284. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  285. my $response = $proxy->call( "TestRun.get_test_plan", $rep->{'run_id'} );
  286. check_fault( $response, $self );
  287. # dump_all($obj, $response->result);
  288. cmp_deeply( $response->result, noclass( $obj->plan ), "TestRun - test_get_test_plan" );
  289. }
  290. sub test_remove_tag {
  291. my $self = shift;
  292. my $rep = get_rep('test_run_tags');
  293. my $obj = Testopia::TestRun->new( $rep->{'run_id'} );
  294. my $tag = Testopia::TestTag->new( $rep->{'tag_id'} );
  295. delete $obj->{'tags'};
  296. my $orig_size = scalar @{ $obj->tags };
  297. delete $obj->{'tags'};
  298. my $response = $proxy->call( "TestRun.remove_tag", $rep->{'run_id'}, $tag->name );
  299. check_fault( $response, $self );
  300. # dump_all($rep, $obj->tags);
  301. ok( scalar @{ $obj->tags } == ( $orig_size - 1 ), "TestRun - test_remove_tag" );
  302. }
  303. 1;
  304. __END__