API-ISPManager
view release on metacpan or search on metacpan
t/01-test.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
our $ONLINE;
BEGIN {
$ONLINE = $ENV{password};
}
use Test::More tests => $ONLINE ? 42 : 40;
my $test_host = $ENV{host} || 'ultrasam.ru';
ok(1, 'Test OK');
use_ok('API::ISPManager');
$a = 'refs';
is( refs( undef ), '', $a);
is( refs( {} ), 'HASH', $a );
is( refs( [] ), 'ARRAY', $a );
is( refs( sub {} ), 'CODE', $a );
is( refs( \$a ), 'SCALAR', $a );
$a = 'is_success';
ok(! is_success(), $a);
ok(! is_success( { error => {}, data => {} } ), $a);
ok( is_success( { data => {} } ), $a);
ok(! is_success( { } ), $a);
$a = 'get_data';
ok(! get_data(), $a);
ok(! get_data( { } ), $a);
ok(! get_data( { error => {}, data => {} } ), $a);
is_deeply( get_data( { data => { aaa => 'bbb' } } ), { aaa => 'bbb' }, $a);
$a = 'filter_hash';
is_deeply( API::ISPManager::filter_hash( { }, [ ]), {}, $a );
is_deeply( API::ISPManager::filter_hash( { aaa => 555, bbb => 111 }, [ 'aaa' ]), { aaa => 555 }, $a );
is_deeply( API::ISPManager::filter_hash( { aaa => 555, bbb => 111 }, [ ]), { }, $a );
is_deeply( API::ISPManager::filter_hash( { }, [ 'aaa' ]), { }, $a );
$a = 'mk_query_string';
is( API::ISPManager::mk_query_string( { } ), '', $a );
is( API::ISPManager::mk_query_string( '' ), '', $a );
is( API::ISPManager::mk_query_string( undef ), '', $a );
is( API::ISPManager::mk_query_string( { aaa => 111, bbb => 222 } ), 'aaa=111&bbb=222', $a );
is( API::ISPManager::mk_query_string( { bbb => 222, aaa => 111 } ), 'aaa=111&bbb=222', $a );
is( API::ISPManager::mk_query_string( [ ] ), '', $a );
is( API::ISPManager::mk_query_string( { dddd => 'dfdf' } ), 'dddd=dfdf', $a );
my $kill_start_end_slashes_test = {
'////aaa////' => 'aaa',
'bbb////' => 'bbb',
'////ccc' => 'ccc',
'' => '',
};
for (keys %$kill_start_end_slashes_test) {
is(
API::ISPManager::kill_start_end_slashes ($_),
$kill_start_end_slashes_test->{$_},
'kill_start_end_slashes'
);
}
$a = 'mk_full_query_string';
is( API::ISPManager::mk_full_query_string( {
host => $test_host,
} ),
'',
$a
);
is( API::ISPManager::mk_full_query_string( {
host => $test_host,
allow_http => 1,
path => 'manager',
} ),
'',
$a
);
is( API::ISPManager::mk_full_query_string( {
host => $test_host,
allow_http => 1,
path => '//my_manager///',
param1 => 'val1',
param2 => 'val2',
} ),
"http://$test_host/my_manager/ispmgr?param1=val1¶m2=val2",
$a
);
t/01-test.t view on Meta::CPAN
'used' => '16',
'limit' => '80017'
},
'database' => {
'used' => '17',
'limit' => '70021'
},
'mailuser' => {
'used' => '4',
'limit' => '60140'
},
'domain' => {
'used' => '23',
'limit' => '70022'
},
'bandwidth' => {
'used' => '8170',
'limit' => '1700000000'
},
'databaseuser' => {
'used' => '17',
'limit' => '70026'
},
'user' => {
'used' => '20',
'limit' => '0'
},
'reseller' => {
'used' => '1',
'limit' => '0'
},
'wwwdomain' => {
'used' => '20',
'limit' => '70022'
}
}
},
'usagestat test'
);
### Stats end
#exit;
no warnings 'once';
$API::ISPManager::DEBUG = 0;
### ONLINE TESTS
exit if !$ONLINE;
$a = 'get_auth_id';
is( get_auth_id(
username => 'root',
password => 'qwerty',
host => $test_host,
path => 'manager',
),
'',
"$a with error password"
);
my $auth_id;
like( $auth_id = get_auth_id(
username => $ENV{username} || 'root',
password => $ENV{password},
host => $test_host,
path => 'manager',
),
qr/\d+/,
"$a with correct password ($auth_id)"
);
=head
is(
scalar keys %{ API::ISPManager::user::list( { %correct_params } )->{elem} },
20,
'user::list test'
);
=cut
my $ip_list = API::ISPManager::ip::list( { %correct_params } );
diag "Get ips from panel: " . Dumper( $ip_list );
if ($ip_list && ref $ip_list eq 'ARRAY' && scalar @$ip_list) {
my $ip = $ip_list->[0];
if ($ip) {
diag $ip;
diag Dumper( API::ISPManager::user::create( {
%correct_params,
name => 'nrgxxxxxapi',
passwd => 'qwerty',
ip => $ip,
preset => 'Host-1',
domain => 'nrg.name',
} ) );
diag Dumper( API::ISPManager::ftp::list( {
%correct_params,
authinfo => 'username:password',
su => 'su_as_username',
} ) );
diag Dumper( API::ISPManager::user::disable( {
%correct_params,
elid => 'nrgxxxxxapi',
} ) );
diag Dumper( API::ISPManager::user::enable( {
%correct_params,
elid => 'nrgxxxxxapi',
} ) );
( run in 0.737 second using v1.01-cache-2.11-cpan-39bf76dae61 )