Ver código fonte

test user authentification

nas 2 anos atrás
pai
commit
c144c7bfa8
4 arquivos alterados com 45 adições e 13 exclusões
  1. 5
    1
      .gitignore
  2. 31
    3
      test/remote/NRT/Batch.pm
  3. 7
    7
      test/remote/NRT/Test.pm
  4. 2
    2
      test/remote/test.pl

+ 5
- 1
.gitignore Ver arquivo

@@ -35,4 +35,8 @@
35 35
 .env
36 36
 
37 37
 # Ignore config file
38
-*.cfg
38
+*.cfg
39
+
40
+# Do not git perl dependencies
41
+test/remote/bin
42
+test/remote/lib

+ 31
- 3
test/remote/NRT/Batch.pm Ver arquivo

@@ -1,7 +1,6 @@
1
-use NRT::Test;# qw( rq assertEqual);
1
+use NRT::Test;
2 2
 use NRT::Helper;
3
-#require NRT::Test ;
4
-#require NRT::Helper;
3
+use NRT::User;
5 4
 
6 5
 package Batch;
7 6
 
@@ -10,7 +9,10 @@ sub new {
10 9
     my $this = {};
11 10
     $classe = ref($classe) || $classe;
12 11
     bless ( $this, $classe );
12
+    $this->{config} = {%config} ;
13 13
     $this->{tester} = Test->new( %config );
14
+    $this->{users} = [];
15
+    $this->{users_index} = 0;
14 16
     return $this;
15 17
 }
16 18
 
@@ -20,9 +22,35 @@ sub test_rq_empty {
20 22
   return $this->{tester}->assertEqual( $rq, "404 Not Found" );
21 23
 }
22 24
 
25
+sub test_user {
26
+  my $this = shift;
27
+  return $this->test_user_authentification;
28
+}
29
+
30
+sub test_user_authentification {
31
+  my $this = shift;
32
+  my $index = $this->add_user(
33
+      $this->{config}{Authentification}{Email},
34
+      $this->{config}{Authentification}{Password} );
35
+  my $auth = $this->{users}[ $index ]->authentification;
36
+  return $this->{tester}->assertEqual( $auth->{email}, $this->{config}{Authentification}{Email} );
37
+}
38
+
39
+sub add_user {
40
+  my ($this, $email, $password) = @_ ;
41
+  push(
42
+    @{$this->{users}},
43
+      User->new(
44
+        $this->{config}{Authentification}{Email},
45
+	$this->{config}{Authentification}{Password},
46
+        $this->{tester})) ;
47
+  return $this->{users_index}++;
48
+}
49
+
23 50
 sub run {
24 51
   my $this = shift;
25 52
   $this->test_rq_empty();
53
+  return $this->test_user();
26 54
   $this->brief();
27 55
 }
28 56
 

+ 7
- 7
test/remote/NRT/Test.pm Ver arquivo

@@ -1,9 +1,8 @@
1 1
 use NRT::Helper;
2
+use LWP::UserAgent;
2 3
 
3 4
 package Test;
4 5
 require Exporter;
5
-#@ISA = qw(Exporter);
6
-#@EXPORT = qw(get_countSuccess get_countFailure rq assertEqual assertNotEqual get_code);
7 6
 
8 7
 sub new {
9 8
   my ($classe, %config) = @_;
@@ -19,14 +18,14 @@ sub new {
19 18
 }
20 19
 
21 20
 sub rq {
21
+  my $this = shift ;
22 22
   my $path = (exists $_[0])? $_[0] : "";
23 23
   my $method = (exists $_[1])? $_[1] : "";
24 24
   my $content = (exists $_[2])? $_[2] : "";
25
-
26
-  my $req = HTTP::Request->new("$method" => "$url$path");
25
+  my $req = HTTP::Request->new("$method" => "$this->{url}$path");
27 26
   $req->content_type('application/json');
28 27
   $req->content("$content");
29
-  my $res = $ua->request($req);
28
+  my $res = $this->{ua}->request($req);
30 29
   return $res->decoded_content;
31 30
 }
32 31
 
@@ -88,9 +87,10 @@ sub record_result {
88 87
 }
89 88
 
90 89
 sub json_parse {
91
-  my $json_text = (exists $_[0])? $_[0] : "";
90
+  my $this = shift;
91
+  my $json_text = shift;
92 92
   my $json = JSON->new;
93
-  return $json->decode($json_text);
93
+  return $json->decode("$json_text");
94 94
 }
95 95
 
96 96
 sub get_countSuccess {

+ 2
- 2
test/remote/test.pl Ver arquivo

@@ -5,7 +5,7 @@
5 5
 # @brief Remote call to the API in order to test
6 6
 BEGIN { push @INC,'.'; };
7 7
 use Config::Std;
8
-use LWP::UserAgent ();
8
+use LWP::UserAgent;
9 9
 use lib qw(..);
10 10
 use JSON qw( );
11 11
 use Data::Dumper;
@@ -18,4 +18,4 @@ read_config 'test.cfg' => our %config;
18 18
 our $batch = Batch->new( %config );
19 19
 print "\nMaking all tests\n";
20 20
 
21
-$batch->run();
21
+print $batch->run();

Carregando…
Cancelar
Salvar