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.

Test.pm 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. use NRT::Helper;
  2. package Test;
  3. require Exporter;
  4. #@ISA = qw(Exporter);
  5. #@EXPORT = qw(get_countSuccess get_countFailure rq assertEqual assertNotEqual get_code);
  6. sub new {
  7. my ($classe, %config) = @_;
  8. my $this = {};
  9. $classe = ref($classe) || $classe;
  10. bless ( $this, $classe );
  11. $this->{url} = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}";
  12. $this->{ua} = LWP::UserAgent->new(timeout => 10);
  13. $this->{ua}->env_proxy;
  14. $this->{countSuccess} = 0;
  15. $this->{countFailure} = 0;
  16. return $this;
  17. }
  18. sub rq {
  19. my $path = (exists $_[0])? $_[0] : "";
  20. my $method = (exists $_[1])? $_[1] : "";
  21. my $content = (exists $_[2])? $_[2] : "";
  22. my $req = HTTP::Request->new("$method" => "$url$path");
  23. $req->content_type('application/json');
  24. $req->content("$content");
  25. my $res = $ua->request($req);
  26. return $res->decoded_content;
  27. }
  28. sub assertEqual {
  29. my ($this, $value1, $value2, $equal ) = @_;
  30. $equal ||= 1;
  31. my $success = 0;
  32. my $test = ( $value1 eq $value2 );
  33. $test = ( $equal )? $test : !$test;
  34. if( $test )
  35. {
  36. $this->record_result( 1 );
  37. print " $value1 ";
  38. Helper::printColor( "bright_blue", "equal");
  39. print " $value2\n";
  40. return 1;
  41. }else{
  42. $this->record_result( 0 );
  43. print " $value1 ";
  44. Helper::printColor( "bright_blue", "NOT equal");
  45. print " $value2\n";
  46. return 0;
  47. };
  48. }
  49. sub assertNotEqual {
  50. my $this = shift;
  51. $this->assertEqual( $_[0], $_[1], 0 );
  52. }
  53. sub get_code {
  54. my ($this, $path) = @_;
  55. if(!defined $path){
  56. $path = "";
  57. #exit 1;
  58. }
  59. my $response = $this->{ua}->get( "$this->{url}$path" );
  60. if ($response->is_success) {
  61. return $response->decoded_content;
  62. }else{
  63. return $response->status_line;
  64. }
  65. }
  66. sub record_result {
  67. my $this = shift ;
  68. my $status = (exists $_[0])? $_[0] : false;
  69. if( $status ){
  70. Helper::printColor( "green", "Success :");
  71. $this->{countSuccess}++;
  72. }else{
  73. Helper::printColor( "red", "Failure :");
  74. $this->{countFailure}++;
  75. }
  76. }
  77. sub json_parse {
  78. my $json_text = (exists $_[0])? $_[0] : "";
  79. my $json = JSON->new;
  80. return $json->decode($json_text);
  81. }
  82. sub get_countSuccess {
  83. my $this = shift;
  84. return $this->{countSuccess} ;
  85. }
  86. sub get_countFailure{
  87. return $countFailure ;
  88. }
  89. sub get_url{
  90. my $this = shift;
  91. return $this->{url} ;
  92. }
  93. return 1;