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
 use NRT::Test;
1
 use NRT::Test;
2
 use NRT::Helper;
2
 use NRT::Helper;
3
 use NRT::User;
3
 use NRT::User;
4
+use NRT::Activity;
4
 
5
 
5
 package Batch;
6
 package Batch;
6
 
7
 
13
     $this->{tester} = Test->new( %config );
14
     $this->{tester} = Test->new( %config );
14
     $this->{users} = [];
15
     $this->{users} = [];
15
     $this->{users_index} = 0;
16
     $this->{users_index} = 0;
17
+    $this->{default_user_index} = "";
16
     return $this;
18
     return $this;
17
 }
19
 }
18
 
20
 
24
 
26
 
25
 sub test_user {
27
 sub test_user {
26
   my $this = shift;
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
   my $user2_index = $this->add_user(
31
   my $user2_index = $this->add_user(
36
     $this->{config}{User}{Email},
32
     $this->{config}{User}{Email},
37
     $this->{config}{User}{Username},
33
     $this->{config}{User}{Username},
38
-      $this->{config}{User}{Password} );
34
+    $this->{config}{User}{Password} );
39
   $this->{tester}->test_user_not_exists(
35
   $this->{tester}->test_user_not_exists(
40
     $this->{users}[$user2_index]);
36
     $this->{users}[$user2_index]);
41
   $this->{tester}->test_user_create(
37
   $this->{tester}->test_user_create(
58
   return $this->{users_index}++;
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
 sub run {
83
 sub run {
62
   my $this = shift;
84
   my $this = shift;
63
-  $this->test_rq_empty();
85
+  #$this->test_rq_empty();
64
   $this->test_user();
86
   $this->test_user();
87
+  return $this->test_activity();
65
   $this->brief();
88
   $this->brief();
66
 }
89
 }
67
 
90
 

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

41
 
41
 
42
 sub assertEqual {
42
 sub assertEqual {
43
   my ($this, $value1, $value2, $equal ) = @_;
43
   my ($this, $value1, $value2, $equal ) = @_;
44
-  $equal ||= 1;
44
+  $equal //= 1;
45
   my $success = 0;
45
   my $success = 0;
46
 
46
 
47
   my $test = ( $value1 eq $value2 );
47
   my $test = ( $value1 eq $value2 );
48
   $test = ( $equal )? $test : !$test;
48
   $test = ( $equal )? $test : !$test;
49
+  $assertedComparator = ($equal)? "equal" : "NOT equal" ;
50
+  $unassertedComparator = ($equal)? "NOT equal" : "equal" ;
49
 
51
 
50
   if( $test )
52
   if( $test )
51
   {
53
   {
52
     $this->record_result( 1 );
54
     $this->record_result( 1 );
53
     print " $value1 ";
55
     print " $value1 ";
54
-    Helper::printColor( "bright_blue", "equal");
56
+    Helper::printColor( "bright_blue", $assertedComparator);
55
     print " $value2\n";
57
     print " $value2\n";
56
     return 1;
58
     return 1;
57
   }else{
59
   }else{
58
     $this->record_result( 0 );
60
     $this->record_result( 0 );
59
     print " $value1 ";
61
     print " $value1 ";
60
-    Helper::printColor( "bright_blue", "NOT equal");
62
+    Helper::printColor( "bright_blue", $assertedComparator);
61
     print " $value2\n";
63
     print " $value2\n";
62
     return 0;
64
     return 0;
63
   };
65
   };
65
 
67
 
66
 sub assertNotEqual {
68
 sub assertNotEqual {
67
   my $this = shift;
69
   my $this = shift;
68
-  $this->assertEqual( $_[0], $_[1], 0 );
70
+  return $this->assertEqual( $_[0], $_[1], 0 );
69
 }
71
 }
70
 
72
 
71
 sub get_code {
73
 sub get_code {
146
 
148
 
147
 sub test_user_not_exists {
149
 sub test_user_not_exists {
148
   my ($this, $user) = @_;
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
 sub test_user_create {
154
 sub test_user_create {
174
 
175
 
175
 sub test_user_already_created {
176
 sub test_user_already_created {
176
   my ($this, $user) = @_;
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
 return 1;
206
 return 1;

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

1
 use LWP::Simple;
1
 use LWP::Simple;
2
 use NRT::Test;
2
 use NRT::Test;
3
+use NRT::Activity;
3
 use Crypt::JWT(decode_jwt);
4
 use Crypt::JWT(decode_jwt);
4
 
5
 
5
 package User;
6
 package User;
15
   $this->{manager} = $manager;
16
   $this->{manager} = $manager;
16
   $this->{token} = "";
17
   $this->{token} = "";
17
   $this->{id} = "";
18
   $this->{id} = "";
19
+  $this->{activities} = [];
18
   return $this;
20
   return $this;
19
 }
21
 }
20
 
22
 
43
 
45
 
44
 sub fetch {
46
 sub fetch {
45
   my ($this) = @_ ;
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
 sub get_token {
55
 sub get_token {
61
     0 ;
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
 return 1;
85
 return 1;

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

10
 use JSON qw( );
10
 use JSON qw( );
11
 use Data::Dumper;
11
 use Data::Dumper;
12
 
12
 
13
-use NRT::User;
14
 use NRT::Batch;
13
 use NRT::Batch;
15
 
14
 
16
 print User::v ;
15
 print User::v ;

Loading…
Cancel
Save