|
@@ -1,112 +1,32 @@
|
1
|
|
-# @file journal.pl
|
2
|
1
|
#!/usr/bin/perl
|
|
2
|
+# @file journal.pl
|
3
|
3
|
# @author nas
|
4
|
4
|
# @date 31/01/2022
|
5
|
5
|
# @brief Remote call to the API in order to test
|
6
|
|
-
|
|
6
|
+BEGIN { push @INC,'.'; };
|
7
|
7
|
use Config::Std;
|
8
|
8
|
use LWP::UserAgent ();
|
9
|
9
|
use lib qw(..);
|
10
|
10
|
use JSON qw( );
|
11
|
11
|
use Data::Dumper;
|
12
|
|
-use Term::ANSIColor;
|
13
|
12
|
|
14
|
|
-read_config 'test.cfg' => my %config;
|
|
13
|
+use NRT::User;
|
|
14
|
+use NRT::Batch;
|
|
15
|
+#require NRT::User;
|
|
16
|
+#require NRT::Batch;
|
15
|
17
|
|
16
|
|
-local $url = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}";
|
|
18
|
+print User::v ;
|
|
19
|
+read_config 'test.cfg' => our %config;
|
|
20
|
+
|
|
21
|
+our $url = "$config{Authentification}{Protocol}$config{Authentification}{Host}$config{Authentification}{Path}";;
|
17
|
22
|
local $ua = LWP::UserAgent->new(timeout => 10);
|
18
|
23
|
$ua->env_proxy;
|
19
|
24
|
|
20
|
|
-my $count_success = 0;
|
21
|
|
-my $count_failure = 0;
|
22
|
|
-
|
23
|
|
-sub print_color {
|
24
|
|
- my $color = (exists $_[0])? $_[0] : "";
|
25
|
|
- my $text = (exists $_[0])? $_[1] : "";
|
26
|
|
- print color( "$color" );
|
27
|
|
- print "$text";
|
28
|
|
- print color('reset')
|
29
|
|
-}
|
30
|
|
-
|
31
|
|
-sub record_result {
|
32
|
|
- my $status = (exists $_[0])? $_[0] : false;
|
33
|
|
-
|
34
|
|
- if( $status ){
|
35
|
|
- print_color( "green", "Success :");
|
36
|
|
- $count_success++;
|
37
|
|
- }else{
|
38
|
|
- print_color( "red", "Failure :");
|
39
|
|
- $count_failure++;
|
40
|
|
- }
|
41
|
|
-}
|
42
|
|
-
|
43
|
|
-sub batch_brief {
|
44
|
|
- print "\nResults :\n";
|
45
|
|
- print_color( "bright_green", "Tests succeed : $count_success\n" );
|
46
|
|
- print_color( "bright_red", "Tests failed : $count_failure\n" );
|
47
|
|
-}
|
48
|
|
-
|
49
|
|
-sub get_code {
|
50
|
|
- my $path = (exists $_[0])? $_[0] : "";
|
51
|
|
- my $response = $ua->get( "$url$path" );
|
52
|
|
-
|
53
|
|
- if ($response->is_success) {
|
54
|
|
- return $response->decoded_content;
|
55
|
|
- }
|
56
|
|
- else {
|
57
|
|
- return $response->status_line;
|
58
|
|
- }
|
59
|
|
-}
|
60
|
|
-
|
61
|
|
-sub assertEqual {
|
62
|
|
- my $value1 = (exists $_[0])? $_[0] : "";
|
63
|
|
- my $value2 = (exists $_[1])? $_[1] : "";
|
64
|
|
- my $equal = (exists $_[1])? $_[1] : 1;
|
65
|
|
- my $success = 0;
|
66
|
|
-
|
67
|
|
- my $test = ( $value1 eq $value2 );
|
68
|
|
- $test = ( $equal )? $test : !$test;
|
69
|
|
-
|
70
|
|
- if( $test )
|
71
|
|
- {
|
72
|
|
- record_result( 1 );
|
73
|
|
- print " $value1 ";
|
74
|
|
- print_color( "bright_blue", "equal");
|
75
|
|
- print " $value2\n";
|
76
|
|
- }else{
|
77
|
|
- record_result( 0 );
|
78
|
|
- print " $value1 ";
|
79
|
|
- print_color( "bright_blue", "NOT equal");
|
80
|
|
- print " $value2\n";
|
81
|
|
- };
|
82
|
|
-}
|
83
|
|
-
|
84
|
|
-sub assertNotEqual {
|
85
|
|
- assertEqual( $_[0], $_[1], 0 );
|
86
|
|
-}
|
87
|
|
-
|
88
|
|
-sub rq {
|
89
|
|
- my $path = (exists $_[0])? $_[0] : "";
|
90
|
|
- my $method = (exists $_[1])? $_[1] : "";
|
91
|
|
- my $content = (exists $_[2])? $_[2] : "";
|
92
|
|
-
|
93
|
|
- my $req = HTTP::Request->new("$method" => "$url$path");
|
94
|
|
- $req->content_type('application/json');
|
95
|
|
- $req->content("$content");
|
96
|
|
- my $res = $ua->request($req);
|
97
|
|
- return $res->decoded_content;
|
98
|
|
- return $res->as_string;
|
99
|
|
-}
|
100
|
|
-
|
101
|
|
-sub json_parse {
|
102
|
|
- my $json_text = (exists $_[0])? $_[0] : "";
|
103
|
|
- my $json = JSON->new;
|
104
|
|
- return $json->decode($json_text);
|
105
|
|
-}
|
106
|
|
-
|
|
25
|
+our $batch = Batch->new( %config );
|
107
|
26
|
print "\nMaking all tests\n";
|
108
|
|
-assertEqual( get_code(), "404 Not Found" );
|
|
27
|
+#NRT::Basic::rq_empty;
|
109
|
28
|
|
110
|
|
-my $result = json_parse( rq( "tokens", "POST", "{\"user\" : {\"email\" : \"$config{Authentification}{Email}\", \"password\" : \"$config{Authentification}{Password}\"}}" ));
|
111
|
|
-assertEqual( "$config{Authentification}{Email}", $result->{"email"});
|
112
|
|
-batch_brief();
|
|
29
|
+#Test::init;
|
|
30
|
+#Batch::brief;
|
|
31
|
+#Batch::run();
|
|
32
|
+$batch->run();
|