API de comptabilité horaire.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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