Browse Source

test activity assertion

nas 2 years ago
parent
commit
f557a5fb72
4 changed files with 93 additions and 25 deletions
  1. 33
    10
      test/remote/NRT/Batch.pm
  2. 33
    8
      test/remote/NRT/Test.pm
  3. 27
    6
      test/remote/NRT/User.pm
  4. 0
    1
      test/remote/test.pl

+ 33
- 10
test/remote/NRT/Batch.pm View File

@@ -1,6 +1,7 @@
1 1
 use NRT::Test;
2 2
 use NRT::Helper;
3 3
 use NRT::User;
4
+use NRT::Activity;
4 5
 
5 6
 package Batch;
6 7
 
@@ -13,6 +14,7 @@ sub new {
13 14
     $this->{tester} = Test->new( %config );
14 15
     $this->{users} = [];
15 16
     $this->{users_index} = 0;
17
+    $this->{default_user_index} = "";
16 18
     return $this;
17 19
 }
18 20
 
@@ -24,18 +26,12 @@ sub test_rq_empty {
24 26
 
25 27
 sub test_user {
26 28
   my $this = shift;
27
-  my $user1_index = $this->add_user(
28
-    $this->{config}{Authentification}{Email},
29
-    $this->{config}{Authentification}{Username},
30
-    $this->{config}{Authentification}{Password} );
31
-  $this->{tester}->test_user_authentification(
32
-    $this->{users}[$user1_index]);
33
-  $this->{tester}->test_user_already_created( 
34
-    $this->{users}[$user1_index]);
29
+  $this->{tester}->test_user_authentification( $this->get_default_user );
30
+  $this->{tester}->test_user_already_created( $this->get_default_user );
35 31
   my $user2_index = $this->add_user(
36 32
     $this->{config}{User}{Email},
37 33
     $this->{config}{User}{Username},
38
-      $this->{config}{User}{Password} );
34
+    $this->{config}{User}{Password} );
39 35
   $this->{tester}->test_user_not_exists(
40 36
     $this->{users}[$user2_index]);
41 37
   $this->{tester}->test_user_create(
@@ -58,10 +54,37 @@ sub add_user {
58 54
   return $this->{users_index}++;
59 55
 }
60 56
 
57
+sub add_default_user {
58
+  my ($this) = @_ ;
59
+  return $this->{default_user_index} = $this->add_user(
60
+    $this->{config}{Authentification}{Email},
61
+    $this->{config}{Authentification}{Username},
62
+    $this->{config}{Authentification}{Password} )
63
+}
64
+
65
+sub get_default_user {
66
+  my ($this) = @_ ; 
67
+  if( $this->{default_user_index} eq "" ){
68
+    $this->add_default_user  ;
69
+  }
70
+  return $this->{users}[ $this->{default_user_index} ];  
71
+}
72
+
73
+sub test_activity {
74
+  my $this = shift;
75
+    
76
+  my $activity = Activity->new( "test_1", $this->get_default_user );
77
+  $this->{tester}->test_create_activity( $activity );
78
+  $this->{tester}->test_activity_exists( $activity );
79
+  $this->{tester}->test_activity_remove( $activity );
80
+  $this->{tester}->test_activity_not_exists( $activity );
81
+}
82
+
61 83
 sub run {
62 84
   my $this = shift;
63
-  $this->test_rq_empty();
85
+  #$this->test_rq_empty();
64 86
   $this->test_user();
87
+  return $this->test_activity();
65 88
   $this->brief();
66 89
 }
67 90
 

+ 33
- 8
test/remote/NRT/Test.pm View File

@@ -41,23 +41,25 @@ sub rq {
41 41
 
42 42
 sub assertEqual {
43 43
   my ($this, $value1, $value2, $equal ) = @_;
44
-  $equal ||= 1;
44
+  $equal //= 1;
45 45
   my $success = 0;
46 46
 
47 47
   my $test = ( $value1 eq $value2 );
48 48
   $test = ( $equal )? $test : !$test;
49
+  $assertedComparator = ($equal)? "equal" : "NOT equal" ;
50
+  $unassertedComparator = ($equal)? "NOT equal" : "equal" ;
49 51
 
50 52
   if( $test )
51 53
   {
52 54
     $this->record_result( 1 );
53 55
     print " $value1 ";
54
-    Helper::printColor( "bright_blue", "equal");
56
+    Helper::printColor( "bright_blue", $assertedComparator);
55 57
     print " $value2\n";
56 58
     return 1;
57 59
   }else{
58 60
     $this->record_result( 0 );
59 61
     print " $value1 ";
60
-    Helper::printColor( "bright_blue", "NOT equal");
62
+    Helper::printColor( "bright_blue", $assertedComparator);
61 63
     print " $value2\n";
62 64
     return 0;
63 65
   };
@@ -65,7 +67,7 @@ sub assertEqual {
65 67
 
66 68
 sub assertNotEqual {
67 69
   my $this = shift;
68
-  $this->assertEqual( $_[0], $_[1], 0 );
70
+  return $this->assertEqual( $_[0], $_[1], 0 );
69 71
 }
70 72
 
71 73
 sub get_code {
@@ -146,8 +148,7 @@ sub test_user_exists {
146 148
 
147 149
 sub test_user_not_exists {
148 150
   my ($this, $user) = @_;
149
-  my $user = $user->fetch();
150
-  return $this->assertEqual( $user, 0 );
151
+  return $this->assertNotEqual( $ruser->{data}{attributes}{email}, $user->{email} );
151 152
 }
152 153
 
153 154
 sub test_user_create {
@@ -174,8 +175,32 @@ sub test_user_remove {
174 175
 
175 176
 sub test_user_already_created {
176 177
   my ($this, $user) = @_;
177
-  my $creation = $user->create;
178
-  return $this->assertNotEqual( $creation, "422 Unprocessable Entity");
178
+  my $creation = $user->fetch;
179
+  return $this->assertEqual( $creation->{data}{id}, $user->get_id);
180
+}
181
+
182
+sub test_create_activity {
183
+  my ($this, $activity) = @_;
184
+  my $res = $activity->create;
185
+  return $this->assertEqual( $res->{data}{attributes}{name}, $activity->{name} );
186
+}
187
+
188
+sub test_activity_remove {
189
+  my ($this, $activity) = @_;
190
+  return $activity->remove;
191
+  return $this->assertEqual( $ractivity->{data}{id}, $activity->{id} );
192
+}
193
+
194
+sub test_activity_exists {
195
+  my ($this, $activity) = @_;
196
+  my $ractivity = $activity->fetch;
197
+  return $this->assertEqual( $ractivity->{data}{id}, $activity->{id} );
198
+}
199
+
200
+sub test_activity_not_exists {
201
+  my ($this, $activity) = @_;
202
+  my $ractivity = $activity->fetch;
203
+  return $this->assertNotEqual( $ractivity->{data}{id}, $activity->{id} );
179 204
 }
180 205
 
181 206
 return 1;

+ 27
- 6
test/remote/NRT/User.pm View File

@@ -1,5 +1,6 @@
1 1
 use LWP::Simple;
2 2
 use NRT::Test;
3
+use NRT::Activity;
3 4
 use Crypt::JWT(decode_jwt);
4 5
 
5 6
 package User;
@@ -15,6 +16,7 @@ sub new {
15 16
   $this->{manager} = $manager;
16 17
   $this->{token} = "";
17 18
   $this->{id} = "";
19
+  $this->{activities} = [];
18 20
   return $this;
19 21
 }
20 22
 
@@ -43,12 +45,11 @@ sub remove {
43 45
 
44 46
 sub fetch {
45 47
   my ($this) = @_ ;
46
-  $token = $this->get_token;
47
-  if( !$token ){
48
-    return 0;
49
-  }
50
-  my $user_id = Crypt::JWT::decode_jwt(token => $token, ignore_signature => 1)->{user_id};
51
-  return $this->{manager}->rq( "users/".$user_id, "GET", "", $this->get_token );
48
+  return $this->{manager}->rq(
49
+    "users/".$this->get_id,
50
+    "GET",
51
+    "",
52
+    $this->get_token );
52 53
 }
53 54
 
54 55
 sub get_token {
@@ -61,4 +62,24 @@ sub get_token {
61 62
     0 ;
62 63
 }
63 64
 
65
+sub get_id {
66
+  my $this = shift;
67
+  if( !($this->{id} eq "") ){
68
+    return $this->{id};
69
+  }
70
+  $token = $this->get_token;
71
+  if( !$token ){
72
+    return 0;
73
+  }
74
+  return Crypt::JWT::decode_jwt(token => $token, ignore_signature => 1)->{user_id};
75
+}
76
+
77
+sub create_activity {
78
+  my ($this, $name) = @_;
79
+  my $activity = Activity->new(
80
+    $name,
81
+    $this);;
82
+  return $activity;
83
+}
84
+
64 85
 return 1;

+ 0
- 1
test/remote/test.pl View File

@@ -10,7 +10,6 @@ use lib qw(..);
10 10
 use JSON qw( );
11 11
 use Data::Dumper;
12 12
 
13
-use NRT::User;
14 13
 use NRT::Batch;
15 14
 
16 15
 print User::v ;

Loading…
Cancel
Save