test user creation and deletion
This commit is contained in:
parent
ce69862008
commit
178527cb30
3 changed files with 69 additions and 9 deletions
|
|
@ -34,19 +34,58 @@ sub test_user {
|
|||
my $user2_index = $this->add_user(
|
||||
$this->{config}{User}{Email},
|
||||
$this->{config}{User}{Username},
|
||||
$this->{config}{User}{Password} );
|
||||
return $this->test_user_create( $user2_index );
|
||||
$this->{config}{User}{Password} );
|
||||
$this->test_user_not_exists( $user2_index );
|
||||
$this->test_user_create( $user2_index );
|
||||
$this->test_user_exists( $user2_index );
|
||||
$this->test_user_remove( $user2_index );
|
||||
$this->test_user_removed( $user2_index );
|
||||
$this->test_user_already_removed( $user2_index );
|
||||
}
|
||||
|
||||
sub test_user_authentification {
|
||||
my ($this, $index) = @_;
|
||||
my $auth = $this->{users}[ $index ]->authentification;
|
||||
return $this->{tester}->assertEqual( $auth->{email}, $this->{config}{Authentification}{Email} );
|
||||
return $this->{tester}->assertEqual( $auth->{email}, $this->{users}[ $index ]->{email} );
|
||||
}
|
||||
|
||||
sub test_user_exists {
|
||||
my ($this, $index) = @_;
|
||||
my $user = $this->{users}[ $index ]->fetch;
|
||||
return $this->{tester}->assertEqual( $user->{data}{attributes}{email}, $this->{users}[ $index ]->{email} );
|
||||
}
|
||||
|
||||
sub test_user_not_exists {
|
||||
my ($this, $index) = @_;
|
||||
my $user = $this->{users}[ $index ]->fetch();
|
||||
return $this->{tester}->assertEqual( $user, 0 );
|
||||
}
|
||||
|
||||
sub test_user_removed {
|
||||
my ($this, $index) = @_;
|
||||
my $user = $this->{users}[ $index ]->fetch();
|
||||
return $this->{tester}->assertEqual( $user, '404 Not Found' );
|
||||
}
|
||||
|
||||
sub test_user_create {
|
||||
my ($this, $index) = @_;
|
||||
return $this->create_user( $index );
|
||||
my $creation = $this->{users}[ $index ]->create();
|
||||
return $this->{tester}->assertEqual( $creation->{data}{attributes}{email}, $this->{users}[ $index ]->{email} );
|
||||
}
|
||||
|
||||
sub test_user_already_removed {
|
||||
my ($this, $index) = @_;
|
||||
return $this->{tester}->assertEqual($this->remove_user( $index ), '404 Not Found');
|
||||
}
|
||||
|
||||
sub test_user_remove {
|
||||
my ($this, $index) = @_;
|
||||
return $this->{tester}->assertEqual($this->remove_user( $index ), '204 No Content');
|
||||
}
|
||||
|
||||
sub remove_user {
|
||||
my ($this, $index) = @_;
|
||||
return $this->{users}[ $index ]->remove;
|
||||
}
|
||||
|
||||
sub test_user_already_created {
|
||||
|
|
@ -60,6 +99,11 @@ sub create_user {
|
|||
return $this->{users}[ $index ]->create;
|
||||
}
|
||||
|
||||
sub remove_user {
|
||||
my ($this, $index) = @_;
|
||||
return $this->{users}[ $index ]->remove;
|
||||
}
|
||||
|
||||
sub add_user {
|
||||
my ($this, $email, $username, $password) = @_ ;
|
||||
push(
|
||||
|
|
@ -71,7 +115,7 @@ sub add_user {
|
|||
sub run {
|
||||
my $this = shift;
|
||||
$this->test_rq_empty();
|
||||
return $this->test_user();
|
||||
$this->test_user();
|
||||
$this->brief();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,13 +22,19 @@ sub rq {
|
|||
my $path = (exists $_[0])? $_[0] : "";
|
||||
my $method = (exists $_[1])? $_[1] : "";
|
||||
my $content = (exists $_[2])? $_[2] : "";
|
||||
my $authorization = (exists $_[3])? $_[3] : "";
|
||||
|
||||
my $req = HTTP::Request->new( $method, $this->{url}.$path );
|
||||
my $req = HTTP::Request->new( $method, "$this->{url}$path" );
|
||||
$req->header( 'Content-Type' => 'application/json' );
|
||||
|
||||
if( $authorization ){
|
||||
$req->header(Authorization => $authorization);
|
||||
}
|
||||
|
||||
$req->content( $content );
|
||||
my $res = $this->{ua}->request($req) ;
|
||||
|
||||
return ( $res->is_success() )?
|
||||
return ( $res->is_success() && $this->is_json( $res->decoded_content ) )?
|
||||
$this->json_parse( $res->decoded_content )
|
||||
: $res->status_line();
|
||||
}
|
||||
|
|
@ -93,7 +99,17 @@ sub record_result {
|
|||
sub json_parse {
|
||||
my ($this, $json_text) = @_;
|
||||
my $json = JSON->new;
|
||||
return $json->decode("$json_text");
|
||||
$res = eval{ $json->decode("$json_text") };
|
||||
return ($@)?
|
||||
0 :
|
||||
$res ;
|
||||
}
|
||||
|
||||
sub is_json {
|
||||
my ($this, $json_text) = @_;
|
||||
my $json = JSON->new;
|
||||
$res = eval{ $json->decode("$json_text") };
|
||||
return ($@)? 0 : 1 ;
|
||||
}
|
||||
|
||||
sub get_countSuccess {
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@ read_config 'test.cfg' => our %config;
|
|||
our $batch = Batch->new( %config );
|
||||
print "\nMaking all tests\n";
|
||||
|
||||
print $batch->run();
|
||||
print Dumper $batch->run();
|
||||
|
|
|
|||
Loading…
Reference in a new issue