API de comptabilité horaire.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Batch.pm 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. use NRT::Test;
  2. use NRT::Helper;
  3. use NRT::User;
  4. use NRT::Activity;
  5. package Batch;
  6. sub new {
  7. my ($classe, %config) = @_;
  8. my $this = {};
  9. $classe = ref($classe) || $classe;
  10. bless ( $this, $classe );
  11. $this->{config} = {%config} ;
  12. $this->{tester} = Test->new( %config );
  13. $this->{users} = [];
  14. $this->{users_index} = 0;
  15. $this->{default_user_index} = "";
  16. return $this;
  17. }
  18. sub test_rq_empty {
  19. my $this = shift;
  20. print "\nTesting requests\n";
  21. my $rq = $this->{tester}->get_code();
  22. return $this->{tester}->assertEqual( $rq, "404 Not Found" );
  23. }
  24. sub test_user {
  25. my $this = shift;
  26. print "\nTesting users\n";
  27. $this->{tester}->test_user_authentification( $this->get_default_user );
  28. $this->{tester}->test_user_already_created( $this->get_default_user );
  29. my $user2_index = $this->add_user(
  30. $this->{config}{User}{Email},
  31. $this->{config}{User}{Username},
  32. $this->{config}{User}{Password} );
  33. $this->{tester}->test_user_not_exists(
  34. $this->{users}[$user2_index]);
  35. $this->{tester}->test_user_create(
  36. $this->{users}[$user2_index]);
  37. $this->{tester}->test_user_exists(
  38. $this->{users}[$user2_index]);
  39. $this->{tester}->test_user_remove(
  40. $this->{users}[$user2_index]);
  41. $this->{tester}->test_user_removed(
  42. $this->{users}[$user2_index]);
  43. $this->{tester}->test_user_already_removed(
  44. $this->{users}[$user2_index]);
  45. }
  46. sub add_user {
  47. my ($this, $email, $username, $password) = @_ ;
  48. push(
  49. @{$this->{users}},
  50. User->new( $email, $username, $password, $this->{tester})) ;
  51. return $this->{users_index}++;
  52. }
  53. sub add_default_user {
  54. my ($this) = @_ ;
  55. return $this->{default_user_index} = $this->add_user(
  56. $this->{config}{Authentification}{Email},
  57. $this->{config}{Authentification}{Username},
  58. $this->{config}{Authentification}{Password} )
  59. }
  60. sub get_default_user {
  61. my ($this) = @_ ;
  62. if( $this->{default_user_index} eq "" ){
  63. $this->add_default_user ;
  64. }
  65. return $this->{users}[ $this->{default_user_index} ];
  66. }
  67. sub test_activity {
  68. my $this = shift;
  69. print "\nTesting activities\n";
  70. my $activity = Activity->new( "test_1", $this->get_default_user );
  71. $this->{tester}->test_create_activity( $activity );
  72. $this->{tester}->test_activity_exists( $activity );
  73. $this->{tester}->test_activity_remove( $activity );
  74. $this->{tester}->test_activity_not_exists( $activity );
  75. }
  76. sub run {
  77. my $this = shift;
  78. $this->test_rq_empty();
  79. $this->test_user();
  80. $this->test_activity();
  81. $this->brief();
  82. }
  83. sub brief {
  84. my $this = shift;;
  85. print "\nResults :\n";
  86. Helper::printColor( "bright_green", "Tests succeed : ".$this->{tester}->{countSuccess}."\n" );
  87. Helper::printColor( "bright_red", "Tests failed : ".$this->{tester}->{countFailure}."\n" );
  88. }
  89. return 1;