PageRenderTime 21ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/testopia/t/OBJ_Builds.pm

https://code.google.com/p/bugzilla4intranet/
Perl | 160 lines | 105 code | 27 blank | 28 comment | 0 complexity | 258d750d7cc5e5fd108852f2423cd6a6 MD5 | raw file
  1. #!/usr/bin/perl -w
  2. # -*- Mode: perl; indent-tabs-mode: nil -*-
  3. #
  4. # The contents of this file are subject to the Mozilla Public
  5. # License Version 1.1 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of
  7. # the License at http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS
  10. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. # implied. See the License for the specific language governing
  12. # rights and limitations under the License.
  13. #
  14. # The Original Code is the Bugzilla Testopia System.
  15. #
  16. # The Initial Developer of the Original Code is Greg Hendricks.
  17. # Portions created by Greg Hendricks are Copyright (C) 2006
  18. # Novell. All Rights Reserved.
  19. #
  20. # Contributor(s): Greg Hendricks <ghendricks@novell.com>
  21. # Al Rodriguez <arodriquez@novell.com>
  22. package OBJ_Builds;
  23. use lib '.';
  24. use lib '../..';
  25. use strict;
  26. use base qw(Test::Unit::TestCase);
  27. use Bugzilla;
  28. use Bugzilla::Constants;
  29. use Testopia::Build;
  30. use Test;
  31. use Testopia::Test::Constants;
  32. use Testopia::Test::Util;
  33. use Test::More;
  34. use Test::Exception;
  35. use Test::Deep;
  36. Bugzilla->error_mode(ERROR_MODE_DIE);
  37. use constant DB_TABLE => 'test_builds';
  38. use constant ID_FIELD => 'build_id';
  39. our $obj = Test::test_init(DB_TABLE, ID_FIELD, 'Testopia::Build');
  40. our $dbh = Bugzilla->dbh;
  41. sub test_check_product{
  42. my $creds = Testopia::Test::Constants->LOGIN_CREDENTIALS;
  43. foreach (Testopia::Test::Constants->LOGIN_TYPES){
  44. my $login = $creds->{$_};
  45. Test::set_user($login->{'id'}, $login->{'login_name'}, $login->{'password'});
  46. # If the user does not have rights to check a product, this should die
  47. unless(Bugzilla->user->in_group('Testers') ){
  48. dies_ok( sub {$obj->_check_product($obj->product_id)}, "User " . Bugzilla->user->{'login_name'} ." does not have sufficient rights to check Product");
  49. }
  50. else{
  51. my $db_obj = Testopia::Test::Util::get_rep_by_field('products', 'id', $obj->product_id);
  52. # Check product by ID
  53. my $id = $obj->_check_product($obj->product_id);
  54. # Check product by Name
  55. my $name = $obj->_check_product($obj->product->name);
  56. cmp_ok( $db_obj->{'id'}, '==', $id, "Product Found By ID");
  57. cmp_ok( $db_obj->{'id'}, '==', $name, "Product Found By Name");
  58. }
  59. }
  60. }
  61. sub test_set_description(){
  62. my $db_obj = Testopia::Test::Util::get_rep_by_field(DB_TABLE, ID_FIELD, $obj->id);
  63. $obj->set_description('Some Description');
  64. #Defauls set to ''
  65. cmp_ok( $db_obj->{'description'}, '!~', $obj->description, 'Build Description Has Been Changed');
  66. }
  67. sub test_set_isactive(){
  68. my $db_obj = Testopia::Test::Util::get_rep_by_field(DB_TABLE, ID_FIELD, $obj->id);
  69. # Default set to 1
  70. $obj->set_isactive(0);
  71. cmp_ok($db_obj->{'isactive'}, '!=', $obj->isactive, "Build IsActive has Changed");
  72. }
  73. sub test_set_milestone{
  74. dies_ok(sub{$obj->set_milestone(undef)}, 'No Milestone Set');
  75. dies_ok(sub{$obj->set_milestone('Some Milestone Name')}, 'Milestone Name Does Not Exist');
  76. }
  77. sub test_set_name{
  78. dies_ok(sub{$obj->set_name()}, 'No Name Not Allwed For Build');
  79. dies_ok(sub{$obj->set_name('')}, 'Empty Name Not Allowed For Build');
  80. my $nonunique_name = $dbh->selectrow_array("SELECT name from test_builds WHERE build_id <> ? AND product_id = ?", undef, $obj->id, $obj->{'product_id'});
  81. dies_ok(sub{$obj->set_name($nonunique_name)}, 'Name For Build Already Exists');
  82. $obj->set_name('Some Unique Name');
  83. like($obj->name, '/Some Unique Name/', 'Build Name Changed' );
  84. }
  85. sub test_create{
  86. my $obj_hash = {'product_id' => 1,
  87. 'name' => 'Unique Name',
  88. 'milestone' => 'PUBLIC M1',
  89. 'isactive' => '1'};
  90. _bad_creates($obj_hash);
  91. my $creds = Testopia::Test::Constants->LOGIN_CREDENTIALS;
  92. foreach (Testopia::Test::Constants->LOGIN_TYPES){
  93. my $login = $creds->{$_};
  94. Test::set_user($login->{'id'}, $login->{'login_name'}, $login->{'password'});
  95. unless(Bugzilla->user->in_group('Testers') ){
  96. dies_ok( sub {Testopia::Build->create}, "User " . Bugzilla->user->{'login_name'} ." does not have sufficient rights to create new builds");
  97. }
  98. else{
  99. my $created_obj = Testopia::Build->create($obj_hash);
  100. # Must remove this entry now because we add it multiple times,
  101. # and the DB does not like that
  102. $dbh->do("DELETE FROM test_builds WHERE build_id = ?", undef, $created_obj->id);
  103. }
  104. }
  105. }
  106. sub _bad_creates{
  107. my $obj_hash = shift;
  108. delete $obj_hash->{'product_id'};
  109. dies_ok(sub{Testopia::Build->create($obj_hash)}, 'Missing product_id');
  110. $obj_hash->{'product_id'} = 1;
  111. delete $obj_hash->{'name'};
  112. dies_ok(sub{Testopia::Build->create($obj_hash)}, 'Missing name');
  113. $obj_hash->{'name'} = 'Unique Name';
  114. delete $obj_hash->{'mileston'};
  115. dies_ok(sub{Testopia::Build->create($obj_hash)}, 'Missing milestone');
  116. $obj_hash->{'milestone'} = 'PUBLIC M1';
  117. delete $obj_hash->{'isactive'};
  118. dies_ok(sub{Testopia::Build->create($obj_hash)}, 'Missing isactive');
  119. $obj_hash->{'isactive'} = 'INVALID';
  120. dies_ok(sub{Testopia::Build->create($obj_hash)}, 'Invalid isactive Value');
  121. $obj_hash->{'isactive'} = 1;
  122. }
  123. sub new {
  124. my $self = shift()->SUPER::new(@_);
  125. return $self;
  126. }
  127. sub set_up {
  128. my $self = shift;
  129. }
  130. sub tear_down {
  131. my $self = shift;
  132. }
  133. 1;