use strict;
use warnings;
use Carp;
use Test::More;
use Test::LongString;
use Data::Dumper;
use lib 't';
use TestData;
BEGIN {
plan tests => $ENV{online_stress_tests} ? 34 : 28;
use_ok( 'API::PleskExpand' );
use_ok( 'API::PleskExpand::Accounts' );
use_ok( 'API::PleskExpand::Domains' );
use_ok( 'API::Plesk::Response');
}
my $expand_client = API::PleskExpand->new( %TestData::online_expand_valid_params);
isa_ok( $expand_client, 'API::PleskExpand', 'STATIC call new' );
# Calling undefined method from Plesk.pm
{
our $our_warning;
local $SIG{__DIE__} = sub { $our_warning = shift; }; # confess <=> die
eval { API::PleskExpand->new(%TestData::online_expand_valid_params)->aaa__bbbccc() };
like($our_warning, qr/aaa__bbbccc/,
'Checking AUTOLOAD by calling undefined method.');
}
my %create_account_data = (
'select' => 'optimal',
'template-id' => 1,
'general_info' => {
login => 'suxdffffxx',
pname => 'stdsdffafff',
passwd => '1234d5678',
status => 0,
cname => '',
phone => '',
fax => '',
email => '',
address => '',
city => '',
state => '',
pcode => '',
country => 'RU',
}
);
my $create_request = API::PleskExpand::Accounts::create( %create_account_data );
is_string($create_request, $_, 'create account test') for
'' .
'RUsuxdffffxx' .
'1234d5678stdsdffafff' .
'0' .
'1';
$create_request = API::PleskExpand::Accounts::create(
%create_account_data,
'attach_to_template' => 1
);
is_string($create_request, $_, 'create account test') for
'' .
'RUsuxdffffxx' .
'1234d5678stdsdffafff' .
'0' .
'1' .
'';
is_deeply(
API::PleskExpand::Accounts::create( %create_account_data, select => ''),
'',
'Manual select without server_id param'
);
like(
API::PleskExpand::Accounts::create( %create_account_data, select => '', server_id => 5),
qr#15$#,
'Manual select without server_id param'
);
like(
API::PleskExpand::Accounts::create(
%create_account_data,
select => 'optimal',
group_id => 2
),
qr#12$#x,
'Select "Optimal server" with group_id',
);
like(
API::PleskExpand::Accounts::create(
%create_account_data,
select => 'optimal',
server_keyword => 'Hosting'
),
qr#Hosting$#,
'Select "Optimal server" with keyword',
);
like(
API::PleskExpand::Accounts::create( %create_account_data, select => 'min_domains', server_keyword => 'Hosting'),
qr#Hosting$#x,
'Select server has "max_diskspace" with keyword',
);
like(
API::PleskExpand::Accounts::create( %create_account_data, select => 'max_diskspace', server_keyword => 'Hosting'),
qr#Hosting$#,
'Select server has "min_domains" with keyword',
);
my $delete_query = API::PleskExpand::Accounts::delete( id => 15 );
is_deeply( $delete_query . "\n", <15
DOC
my $modify_query = API::PleskExpand::Accounts::modify(
id => 15,
general_info => { status => 16 } # deactivate!
);
is_string( $modify_query, $_, 'modify account test') for
'15' .
'16';
my $modify_query_alter = API::PleskExpand::Accounts::modify(
id => 5,
general_info => { status => 0 } # deactivate!
);
is_string( $modify_query_alter, $_, 'modify account test') for
'5' .
'0';
my %new_domain_data = (
dname => 'y2a1ddsdfandex.ru',
client_id => 16,
'template-id' => 1,
ftp_login => 'nrddgddsdasd',
ftp_password => 'dadsdasd',
);
my $create_domain = API::PleskExpand::Domains::create( %new_domain_data );
is_string( $create_domain, $_, 'modify account test') for
'y2a1ddsdfandex.ru' .
'160' .
'nrddgddsdasd' .
'dadsdasd' .
'1';
$create_domain = API::PleskExpand::Domains::create( %new_domain_data, attach_to_template => 1 );
is_string( $create_domain, $_, 'modify account test') for
'y2a1ddsdfandex.ru' .
'160' .
'nrddgddsdasd' .
'dadsdasd' .
'1' .
'';
$expand_client->{dump_headers} = 1; # debugg =)
is_deeply(
$expand_client->_execute_query(''),
{
':HTTP_AUTH_LOGIN' => $TestData::online_expand_valid_params{'username'},
':HTTP_AUTH_PASSWD' => $TestData::online_expand_valid_params{'password'},
':HTTP_AUTH_OP' => 'exp_plesk_domain'
},
'test request headers'
);
is_deeply(
$expand_client->_execute_query(''),
{
':HTTP_AUTH_LOGIN' => $TestData::online_expand_valid_params{'username'},
':HTTP_AUTH_PASSWD' => $TestData::online_expand_valid_params{'password'},
':HTTP_AUTH_OP' => 'exp_plesk_client'
},
'exp_plesk_client'
);
$expand_client->{dump_headers} = 0;
my $req_answer1 = {
errtext => "[Operator] Client already exists. Plesk client 'hello_medved' is exist.",
server_id => 1,
status => 'error',
tmpl_id => 1,
expiration => -1,
errcode => 4203,
};
is_deeply(
API::PleskExpand::Accounts::create_response_parse( $_ ),
$req_answer1,
'create with error parser'
) for
'' .
'' .
'error4203' .
"[Operator] Client already exists. Plesk client 'hello_medved' " .
'is exist.11' .
'-1';
is_deeply(
API::PleskExpand::Accounts::create_response_parse( $_ ),
{
'server_id' => '1',
'status' => 'ok',
'expiration' => '-1',
'tmpl_id' => '1',
'id' => '29'
},
'parse success create xml response '
) for '' .
'ok' .
'2911' .
'-1' ;
is_deeply(
API::PleskExpand::Accounts::modify_response_parse( $_ ),
{
'server_id' => '1',
'status' => 'ok',
'tmpl_id' => '1',
'id' => '32',
'plesk_client_id' => '395',
'login' => 'aseaasdsassrews'
},
'parse success modify xml response'
) for '' .
'ok3211' .
'395aseaasdsassrews';
is_deeply(
API::PleskExpand::Accounts::delete_response_parse( $_ ),
{
'server_id' => '1',
'status' => 'ok',
'id' => '33',
},
'parse success delete xml response'
) for '' .
'ok331';
is_deeply(
API::PleskExpand::Domains::create_response_parse( $_ ),
{
'server_id' => '1',
'status' => 'ok',
'expiration' => '-1',
'tmpl_id' => '1',
'client_id' => '38',
'id' => '16'
},
'parse success add domain xml response')
for '' .
'ok1638' .
'11-1';
is_deeply(
API::PleskExpand::Domains::create_response_parse( $_ ),
{
errtext => "[Operator] Domain already exists. Plesk domain 'yandex.ru' is exist.",
errcode => '4304',
status => 'error',
tmpl_id => 1,
expiration => -1,
client_id => 40,
server_id => 1,
},
'parse fail add domain xml response')
for '' .
'error4304[Operator] Domain already exists.' .
" Plesk domain 'yandex.ru' is exist.401" .
'1-1';
is_string(
API::PleskExpand::Domains::get(all => 1),
'',
'Domains get'
);
exit unless $ENV{'online_stress_tests'};
my ($domain_template_id, $client_template_id);
$domain_template_id = $client_template_id = $ENV{template_id} || 1;
diag "Online tests start!";
# 5 tests -- full set !!!
my $login = $ENV{'online_stress_tests_login'} || 'expandtestaccount';
my $create_account_result = $expand_client->Accounts->create(
'select' => 'optimal',
'template-id' => $client_template_id,
'attach_to_template' => 1,
'general_info' => {
login => $login,
pname => $login,
passwd => 'asdasdasd',
status => 0,
cname => '',
phone => '',
fax => '',
email => '',
address => '',
city => '',
state => '',
pcode => '',
country => 'RU',
}
);
if ($create_account_result->is_success) {
#warn Dumper $create_account_result;
my $client_id = $create_account_result->{answer_data}->[0]->{id};
my $server_id = $create_account_result->{answer_data}->[0]->{server_id};
pass "Account succcessful created!";
my $deactivate_result = $expand_client->Accounts->modify(
general_info => { status => 16 }, # deactivate!
id => $client_id,
);
if ($deactivate_result->is_success) {
pass "Deactivation success!";
my $activate_result = $expand_client->Accounts->modify(
general_info => { status => 0 }, # activate!
id => $client_id,
);
my $plesk_id = $activate_result->get_data->[0]->{plesk_client_id};
if ($activate_result->is_success) {
pass "Activation success!";
my $create_domain = $expand_client->Domains->create(
dname => $login . '.ru',
client_id => $client_id,
'template-id' => $domain_template_id,
'attach_to_template' => 1,
ftp_login => $login,
ftp_password => 'afsfsaf',
);
if ($create_domain->is_success) {
pass "Create domain successful";
my $nop_result = $expand_client->Accounts->modify(
general_info => { }, # blank operation
id => $client_id,
);
if ($nop_result->is_success && $nop_result->get_data->[0]->{plesk_client_id} eq $plesk_id) {
pass "Get plesk_id $plesk_id success";
my $delete_result = $expand_client->Accounts->delete(
id => $client_id,
);
if ( $delete_result->is_success ) {
pass "Delete account success";
} else {
fail "Remove account failed";
exit;
}
} else {
fail "Get plesk_id failed";
exit;
}
} else {
fail "Add domain failed! " . $create_domain->get_error_string;
exit;
}
} else {
fail "Activation failed!";
exit;
}
} else {
fail "Deactivation failed!";
exit;
}
} else {
fail $create_account_result->get_error_string;
exit;
}