TT#10837 Test all collections in one script - POST

Change-Id: I05b3bb4f73813efe757e695c11315ff9fccd085d
changes/68/11568/52
Irina Peshinskaya 8 years ago
parent bf779bf61a
commit f508bf8831

@ -73,7 +73,7 @@ has_field 'token' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/subscriber_id destination/],
render_list => [qw/callid type caller callee status token/],
);
1;

@ -202,6 +202,7 @@ sub validate_form {
unless($form->validated) {
my $e = join '; ', map {
my $in = (defined $_->input && ref $_->input eq 'HASH' && exists $_->input->{id}) ? $_->input->{id} : ($_->input // '');
$in //= '';
sprintf 'field=\'%s\', input=\'%s\', errors=\'%s\'',
($_->parent->$_isa('HTML::FormHandler::Field') ? $_->parent->name . '_' : '') . $_->name,
$in,

@ -9,149 +9,240 @@ use File::Find::Rule;
use File::Basename;
use Clone qw/clone/;
my $opt = {
'collections' => {},
my($opt,$report,$api_config,$api_info,$config,$test_machine,$fake_data) =
({},{},{},{} );
$opt = {
'collections' => {'callcontrols' => 1,},
'collections' => {},
'ignore_existence' => 1,
'test_groups' => { post => 1, },#get2put,get2patch,bundle
};
my $opt_in = {};
GetOptions($opt_in,
"help|h|?" ,
"collections:s" ,
"ignore-existence" ,
) or pod2usage(2);
my @opt_keys = keys %$opt_in;
@{$opt}{ map{my $k=$_;$k=~s/\-/_/;$k;} @opt_keys } = map {my $v = $opt_in->{$_}; $v={ map {$_=>1;} split(/[^[:alnum:]]+/,$v ) }; $v;} @opt_keys ;
print Dumper $opt;
pod2usage(1) if $opt->{help};
pod2usage(1) unless( 1
# defined $opt->{collections} && defined $opt->{etc}
$test_machine = Test::Collection->new(
name => '',
ALLOW_EMPTY_COLLECTION => 1,
QUIET_DELETION => 0,
runas_role => 'reseller',
);
$fake_data = Test::FakeData->new;
$fake_data->test_machine->QUIET_DELETION(0);
$test_machine->clear_cache;
get_opt();
get_api_config();
init_config();
init_report();
my $test_machine = Test::Collection->new('name'=>'','ALLOW_EMPTY_COLLECTION' => 1);
my $fake_data = Test::FakeData->new;
$test_machine->clear_cache;
my $remote_config = $test_machine->init_catalyst_config;
print Dumper $remote_config ;
my $data = $remote_config->{meta}->{'collections'};
my %test_exclude = (
'metaconfigdefs' => 1,
'subscriberpreferencedefs' => 1,
'customerpreferencedefs' => 1,
'domainpreferencedefs' => 1,
'peeringserverpreferencedefs' => 1,
'profilepreferencedefs' => 1,
'subscriberpreferences' => 1,
'customerpreferences' => 1,
'domainpreferences' => 1,
'peeringserverpreferences' => 1,
'profilepreferences' => 1,
'pbxdevicepreferencedefs' => 1,
'pbxdeviceprofilepreferencedefs' => 1,
#defs and preferences are tested in context of preferences
'pbxdevicefirmwares' => 1, #too hard, fails with timeout on get
#falis with: not ok 163 - ccmapentries: check_get2put: check put successful (Unprocessable Entity: Validation failed. field='mappings', input='ARRAY(0x1a53f278)', errors='Mappings field is required')
'ccmapentries' => 1,
#fails with:
# got: 'https://127.0.0.1:1443/api/customerzonecosts/?page=1&rows=5&start=2016-10-01T000000&end=2016-10-31T235959'
# expected: 'https://127.0.0.1:1443/api/customerzonecosts/?page=1&rows=5'
'customerzonecosts' => 1,
#fails with: Unsupported media type 'application/json', accepting text/plain or text/xml only.)
'pbxdeviceconfigs' => 1,
#fails with: not ok 1131 - rtcapps: check_get2put: check put successful (Unprocessable Entity: Invalid field 'apps'. Must be an array.)
'rtcapps' => 1,
#fails with: not ok 1176 - rtcnetworks: check_get2put: check put successful (Unprocessable Entity: Invalid field 'networks'. Must be an array.)
'rtcnetworks' => 1,
);
my %test_exists;
{
my $dir = dirname($0);
my $rule = File::Find::Rule->new
->mindepth(1)
->maxdepth(1)
->name('api-*.t');
%test_exists = map {$_=~s/\Q$dir\/\E//;$_ => 1} $rule->in($dir);
}
run();
my $res = {
'collections_no_get' => [],
'collections_empty' => [],
'collections_not_empty' => [],
'strange_item_actions' => {},
'no_module_item' => [],
'tests_exists' => \%test_exists,
'tests_exists_skipped' => [],
'checked' => [],
'tests_exclude' => \%test_exclude,
'opt' => $opt
};
$test_machine->clear_test_data_all();
done_testing;
undef $fake_data;
undef $test_machine;
################################ RUN #############################
print Dumper $report;
#------------------------ subs -----------------------
foreach my $collection ( sort grep{(! ( scalar keys $opt->{collections} ) ) || $opt->{collections}->{$_} } keys %{$data} ){
if(!$opt->{collections}->{$collection}){
if($test_exists{'api-'.$collection.'.t'} && !$opt->{ignore_existence}){
push @{$res->{'tests_exists_skipped'}}, $collection;
#we will not test the same twice
next;
}
next if $test_exclude{$collection};
}
#print Dumper $data->{$collection}->{allowed_methods_item};
#print Dumper $collection;
sub run{
#my($opt,$report,$api_info,$test_machine,$fake_data,$config)
foreach my $collection ( sort grep { collection4testing($_) } keys %{$api_info} ){
my $item_allowed_actions = { allowed => {} };
if($data->{$collection}->{module_item}){
if(ref $data->{$collection}->{allowed_methods_item} eq 'HASH'){
$item_allowed_actions = { allowed => { map { $_ => 1 } keys %{$data->{$collection}->{allowed_methods_item}} }};
$test_machine->name($collection);
$test_machine->NO_ITEM_MODULE($api_info->{$collection}->{module_item} ? 0 : 1 );
$test_machine->methods({
collection => { allowed => { map { $_ => 1 } keys %{$api_info->{$collection}->{allowed_methods}} }},
item => { allowed => { map { $_ => 1 } keys %{$api_info->{$collection}->{allowed_methods_item}} }},
});
if($opt->{test_groups}->{bundle}){
$test_machine->check_bundle();
}
if($opt->{test_groups}->{post}){
if($test_machine->{methods}->{collection}->{allowed}->{POST}){
#load date
if(!$fake_data->{data}->{$collection}->{data}){
testscript_under_framework($collection);
}
if($fake_data->{data}->{$collection}->{data}){
my $data = $fake_data->{data}->{$collection}->{data};
#$data->{json} && ( $data = $data->{json});
#TODO: ALL packages should have information about content_typr
if($data->{json} && ( $data = $data->{json})){
$test_machine->content_type->{POST} = 'multipart/form-data';
}else{
$test_machine->content_type->{POST} = 'application/json';
}
$fake_data->process($collection);
$test_machine->check_create_correct(
1,
$fake_data->{data}->{$collection}->{uniquizer_cb},
clone $fake_data->{data}->{$collection}->{data}
);
push @{$report->{post_tested}}, $collection;
}else{
push @{$report->{post_untested}}, $collection;
}
}
}
if($opt->{test_groups}->{get}){
if($test_machine->{methods}->{collection}->{allowed}->{GET}){
my $item = $test_machine->get_item_hal( undef, undef, 1);#reload
}
}
if($opt->{test_groups}->{get2put}){
if($test_machine->{methods}->{collection}->{allowed}->{GET}){
my $item = $test_machine->get_item_hal( undef, undef, 1);#reload
if(!$test_machine->IS_EMPTY_COLLECTION){
if($test_machine->{methods}->{item}->{allowed}->{PUT}){
$test_machine->check_get2put();
}
}
}
}
if(!$test_machine->{methods}->{collection}->{allowed}->{GET}){
push @{$report->{'collections_no_get'}}, $collection;
}
if(!$api_info->{$collection}->{module_item}){
push @{$report->{'no_module_item'}}, $collection;
}
if(!$test_machine->IS_EMPTY_COLLECTION){
push @{$report->{'collections_not_empty'}}, $collection;
}else{
$res->{'strange_item_actions'}->{$collection} = $data->{$collection}->{allowed_methods_item};
push @{$report->{'collections_empty'}}, $collection;
}
}else{
push @{$res->{'no_module_item'}}, $collection;
push @{$report->{'checked'}}, $collection;
}
push @{$res->{'checked'}}, $collection;
$test_machine->name($collection);
$test_machine->NO_ITEM_MODULE($data->{$collection}->{module_item} ? 0 : 1 );
}
#------------------------ aux -----------------------
sub get_opt{#get $opt
my $opt_in = {};
GetOptions($opt_in,
"help|h|?" ,
"collections:s" ,
"ignore-existence",
"test-groups" ,
) or pod2usage(2);
my @opt_keys = keys %$opt_in;
@{$opt}{ map{my $k=$_;$k=~s/\-/_/;$k;} @opt_keys } = map {my $v = $opt_in->{$_}; $v={ map {$_=>1;} split(/[^[:alnum:]]+/,$v ) }; $v;} @opt_keys ;
print Dumper $opt;
pod2usage(1) if $opt->{help};
pod2usage(1) unless( 1
# defined $opt->{collections} && defined $opt->{etc}
);
}
sub get_api_config{#get api_config
my $api_config = $test_machine->init_catalyst_config;
$api_info = $api_config->{meta}->{'collections'};
}
sub init_config{#init config
my %test_exclude = (
'metaconfigdefs' => 1,
'subscriberpreferencedefs' => 1,
'customerpreferencedefs' => 1,
'domainpreferencedefs' => 1,
'peeringserverpreferencedefs' => 1,
'profilepreferencedefs' => 1,
'subscriberpreferences' => 1,
'customerpreferences' => 1,
'domainpreferences' => 1,
'peeringserverpreferences' => 1,
'profilepreferences' => 1,
'pbxdevicepreferencedefs' => 1,
'pbxdeviceprofilepreferencedefs' => 1,
#defs and preferences are tested in context of preferences
'pbxdevicefirmwares' => 1, #too hard, fails with timeout on get
#falis with: not ok 163 - ccmapentries: check_get2put: check put successful (Unprocessable Entity: Validation failed. field='mappings', input='ARRAY(0x1a53f278)', errors='Mappings field is required')
'ccmapentries' => 1,
#fails with:
# got: 'https://127.0.0.1:1443/api/customerzonecosts/?page=1&rows=5&start=2016-10-01T000000&end=2016-10-31T235959'
# expected: 'https://127.0.0.1:1443/api/customerzonecosts/?page=1&rows=5'
'customerzonecosts' => 1,
#fails with: Unsupported media type 'application/json', accepting text/plain or text/xml only.)
'pbxdeviceconfigs' => 1,
#fails with: not ok 1131 - rtcapps: check_get2put: check put successful (Unprocessable Entity: Invalid field 'apps'. Must be an array.)
'rtcapps' => 1,
#fails with: not ok 1176 - rtcnetworks: check_get2put: check put successful (Unprocessable Entity: Invalid field 'networks'. Must be an array.)
'rtcnetworks' => 1,
);
my %test_exists;
{
$test_machine->methods({
collection => { allowed => { map { $_ => 1 } keys %{$data->{$collection}->{allowed_methods}} }},
item => $item_allowed_actions,
});
my $dir = dirname($0);
my $rule = File::Find::Rule->new
->mindepth(1)
->maxdepth(1)
->name('api-*.t');
%test_exists = map {$_=~s/\Q$dir\/\E//;$_ => 1} $rule->in($dir);
}
$config->{tests_exists} = \%test_exists;
$config->{tests_exclude} = \%test_exclude;
}
$test_machine->check_bundle();
sub testscript_exists{
my $collection = shift;
return $config->{tests_exists}->{'api-'.$collection.'.t'};
}
if($test_machine->{methods}->{collection}->{allowed}->{GET}){
my $item = $test_machine->get_item_hal();
#if($item->{content}->{total_count}){
if(!$test_machine->IS_EMPTY_COLLECTION){
push @{$res->{'collections_not_empty'}}, $collection;
if($data->{$collection}->{allowed_methods}->{POST}){
my $item_post = clone($item);
delete $item_post->{content}->{id};
$test_machine->DATA_ITEM_STORE($item_post->{content});
$test_machine->form_data_item();
#test_machine->check_create_correct( 1 );
}
if($test_machine->{methods}->{item}->{allowed}->{PUT}){
$test_machine->check_get2put();
sub testscript_under_framework{
my $collection = shift;
eval{
$fake_data->load_data_from_script($collection);
};
if($@){
print Dumper ["testscript_under_framework", $@];
return 0;
}
else{
return 1;
}
}
sub collection4testing{
my $collection = shift;
my $r = (! ( scalar keys %{$opt->{collections}} ) ) || $opt->{collections}->{$collection};
if($r){
#by default we run requested collection scripts even when exists
if(!$opt->{collections}->{$collection}){
if(testscript_exists($collection) && !$opt->{ignore_existence}){
push @{$report->{'tests_exists_skipped'}}, $collection;
#we will not test the same twice
$r = 0;
}
}else{
push @{$res->{'collections_empty'}}, $collection;
$r = 0 if $config->{test_exclude}->{$collection};
}
}else{
push @{$res->{'collections_no_get'}}, $collection;
}
return $r;
}
sub init_report{
$report = {
'collections_no_get' => [],
'collections_empty' => [],
'collections_not_empty' => [],
'strange_item_actions' => {},
'no_module_item' => [],
'tests_exists_skipped' => [],
'checked' => [],
'post_tested' => [],
'post_untested' => [],
'opt' => $opt,
'config' => $config,
};
}
$test_machine->clear_test_data_all();
done_testing;
undef $fake_data;
undef $test_machine;
print Dumper $res;
#my $item_post = clone($item);
#delete $item_post->{content}->{id};
#$test_machine->DATA_ITEM_STORE($item_post->{content});
#$test_machine->form_data_item();
##$test_machine->check_create_correct( 1, undef, );
# vim: set tabstop=4 expandtab:

@ -22,6 +22,7 @@ $fake_data->set_data_from_script({
detail => "api_test zone",
},
'query' => ['zone','billing_profile_id'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{zone}); },
},
});

@ -18,10 +18,11 @@ my $fake_data = Test::FakeData->new;
$fake_data->set_data_from_script({
'domains' => {
'data' => {
domain => 'api_test_domain.api_test_domain',
domain => 'api_test.api_test',
reseller_id => sub { return shift->get_id('resellers',@_); },
},
'query' => ['domain'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{domain}); },
},
});

@ -18,9 +18,10 @@ $fake_data->set_data_from_script({
'emergencymappingcontainers' => {
data => {
reseller_id => sub { return shift->get_id('resellers', @_); },
name => "apitest_emergency_mapping_cont",
name => "apitest",
},
'query' => ['name','reseller_id'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
});

@ -17,12 +17,13 @@ $test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET HEAD OPT
$fake_data->set_data_from_script({
'lnpcarriers' => {
data => {
name => "apitest_emergency_mapping_cont",
name => "apitest_emrgnc_map",
prefix => "111",
authoritative => "0",
skip_rewrite => "0",
},
'query' => ['name'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
});

@ -17,12 +17,13 @@ my $fake_data = Test::FakeData->new;
$fake_data->set_data_from_script({
peeringgroups => {
data => {
name => 'test_api peering group',
name => 'test_api_p_group',
priority => '1',
description => 'test_api peering group',
contract_id => sub { return shift->get_id('contracts',@_); },,
},
query => ['name'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name});},
},
});

@ -27,7 +27,7 @@ $fake_data->set_data_from_script({
password => 'api_test_password',
webusername => 'api_test_webusername',
webpassword => undef,
domain_id => sub { return shift->get_id('domains',@_); },,
domain_id => sub { return shift->get_id('domains',@_); },
#domain_id =>
email => undef,
external_id => undef,

@ -8,6 +8,7 @@ Build-Depends: libboolean-perl,
libemail-sender-perl,
libhtml-formhandler-perl,
libjson-perl,
libfile-grep-perl,
libnetaddr-ip-perl,
libsereal-decoder-perl,
libsereal-encoder-perl,

@ -348,7 +348,12 @@ sub form_data_item{
}
sub get_id_from_created{
my($self, $created_info) = @_;
my $id = $created_info->{location} || '';
my $id = $self->get_id_from_location($created_info->{location});
return $id;
}
sub get_id_from_location{
my($self, $location) = @_;
my $id = $location // '';
$id=~s/.*?\D(\d+)$/$1/gis;
return $id;
}
@ -389,6 +394,7 @@ sub get_item_hal{
my($self,$name,$uri, $reload) = @_;
$name ||= $self->name;
my $resitem ;
#print Dumper ["get_item_hal",$name,$self->DATA_LOADED->{$name}];
if(!$uri && !$reload){
if(( $name eq $self->name ) && $self->DATA_CREATED->{FIRST}){
$resitem = $self->get_created_first;
@ -403,6 +409,7 @@ sub get_item_hal{
#print "uri=$uri;";
my($res,$list_collection,$req) = $self->check_item_get($self->normalize_uri($uri));
($reshal,$location,$total_count,$reshal_collection) = $self->get_hal_from_collection($list_collection,$name);
#print Dumper $reshal;
if($total_count || ('HASH' eq ref $reshal->{content} && $reshal->{content}->{total_count})){
$self->IS_EMPTY_COLLECTION(0);
$resitem = {
@ -648,7 +655,9 @@ sub request_post{
$req->header('Prefer' => 'return=representation');
my $res = $self->request($req);
my $rescontent = $self->get_response_content($res);
return wantarray ? ($res,$rescontent,$req,$content) : $res;
my $location = $res->header('Location') // '';
my $additional_info = { id => $self->get_id_from_location($location) // '' };
return wantarray ? ($res,$rescontent,$req,$content,$additional_info) : $res;
};
sub request_options{
my ($self,$uri) = @_;
@ -670,10 +679,13 @@ sub request_delete{
if($res->code == 404){
#todo: if fake data will provide tree of the cascade deletion - it can be checked here, I think
diag($name.": Item $del_uri is absent already.");
}elsif($res->code == 204){
diag($name.": Item $del_uri deleted.");
}elsif($res->code == 423){
#todo: if fake data will provide tree of the cascade deletion - it can be checked here, I think
diag($name.": Item '$del_uri' can't be deleted.");
}elsif(!$self->QUIET_DELETION){
$self->http_code_msg(204, "$name: check response from DELETE $uri", $res);
}elsif($res->code == 204){
diag($name.": Item $del_uri deleted.");
}
my $content = $self->get_response_content($res);
if($self->cache_data){
@ -1075,7 +1087,7 @@ sub check_item_delete{
return ($req,$res,$content);
};
sub check_create_correct{
my($self, $number, $uniquizer_cb) = @_;
my($self, $number, $uniquizer_cb, $data_in) = @_;
if(!$self->KEEP_CREATED){
$self->clear_data_created;
}
@ -1083,18 +1095,22 @@ sub check_create_correct{
my @created = ();
for(my $i = 1; $i <= $number; ++$i) {
my $created_info={};
my ($res, $content, $req, $content_post) = $self->check_item_post( $uniquizer_cb , undef, { i => $i } );
$self->http_code_msg(201, "create test item '".$self->name."' $i",$res,$content);
my ($res, $content, $req, $content_post) = $self->check_item_post( $uniquizer_cb , $data_in, { i => $i } );
if(exists $self->methods->{'item'}->{allowed}->{'GET'}){
$self->http_code_msg(201, "create test item '".$self->name."' $i",$res,$content);
}else{
$self->http_code_msg(200, "create test item '".$self->name."' $i",$res,$content);
}
my $location = $res->header('Location');
if($location){
#some interfaces (e.g. subscribers) don't provide hal after creation - is it correct, by the way?
my $get ={};
if(!$content){
if(!$content && exists $self->methods->{'item'}->{allowed}->{'GET'}){
@$get{qw/res_get content_get req_get/} = $self->check_item_get($location,"no object returned after POST");
}
$created_info = {
num => $i,
content => $content ? $content : $get->{content_get},
content => $content ? $content : ($get->{content_get} // {}),
res => $res,
req => $req,
location => $location,

@ -13,6 +13,8 @@ use Clone qw/clone/;
use File::Slurp qw/read_file/;
use URI::Escape;
use Storable;
use File::Grep qw/fgrep/;
use feature 'state';
sub BUILD {
my $self = shift;
@ -175,6 +177,119 @@ sub build_data_default{
sub build_data{
my ($self) = @_;
my $data = {
'admins' => {
'data' => {
login => 'api_test_admin',
password => 'api_test_admin',
reseller_id => sub { return shift->get_id('resellers',@_); },
},
'query' => ['login'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{login}); },
},
'applyrewrites' => {
'data' => {
direction => "caller_in",
number => "test",
subscriber_id => sub { return shift->get_id('subscribers',@_); },
},
},
'billingnetworks' => {
'data' => {
name => "api_test billingnetworks",
description => "api_test billingnetworks",
blocks => [
{ip=>'10.0.5.9',mask=>24},
{ip=>'10.0.6.9',mask=>24},
],
},
},
'callcontrols' => {
'data' => {
subscriber_id => sub { return shift->get_id('subscribers',@_); },
destination => "api_test",
},
},
'cfsourcesets' => {
'data' => {
sources => [{source => "test",}],
subscriber_id => sub { return shift->get_id('subscribers',@_); },
name => "from_test"
},
'query' => ['name','subscriber_id'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
'customerlocations' => {
'data' => {
blocks => [
{ip=>'10.0.5.9',mask=>24},
{ip=>'10.0.6.9',mask=>24},
],
contract_id => sub { return shift->get_id('contracts',@_); },
name => "test_api",
description => "test_api",
},
'query' => ['name'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
'ncoslnpcarriers' => {
'data' => {
ncos_level_id => sub { return shift->get_id('ncoslevels',@_); },
description => "test_api",
},
},
'ncospatterns' => {
'data' => {
ncos_level_id => sub { return shift->get_id('ncoslevels',@_); },
description => "test_api",
pattern => "aaabbbccc",
},
},
'partycallcontrols' => {
'data' => {
callee => "test",
caller => "test",
callid => "test",
status => "test",
token => "test",
type => "pcc",#'pcc' or 'sms'
},
},
'profilepackages' => {
'data' => {
name => "test",
description => "test",
initial_profiles => [
{
profile_id => sub { return shift->get_id('billingprofiles',@_); },
#network_id => sub { return shift->get_id('billingnetworks',@_); },
}
],
},
},
'rtcsessions' => {
'data' => {
subscriber_id => sub { return shift->get_id('subscribers',@_); },
},
},
'topupcash' => {
'data' => {
subscriber_id => sub { return shift->get_id('subscribers',@_); },
amount => 1.0,
},
},
'topupvouchers' => {
'data' => {
subscriber_id => sub { return shift->get_id('subscribers',@_); },
code => 'test',
},
},
'upnrewritesets' => {
'data' => {
new_cli => "test",
subscriber_id => sub { return shift->get_id('subscribers',@_); },
upn_rewrite_sources => [{ pattern => 'aaa'},{ pattern => 'bbb'}],
},
},
'systemcontacts' => {
'data' => {
email => 'api_test_reseller@reseller.invalid',
@ -251,13 +366,17 @@ sub build_data{
},
'billingprofiles' => {
'data' => {
name => 'api_test test profile'.time(),
handle => 'api_test_testprofile'.time(),
name => 'api_test'.time(),
handle => 'api_test'.time(),
reseller_id => sub { return shift->get_id('resellers',@_); },
},
'default' => 'billing_profiles',
'no_delete_available' => 1,
'dependency_requires_recreation' => ['resellers'],
'uniquizer_cb' => sub {
Test::FakeData::string_uniquizer(\$_[0]->{name});
Test::FakeData::string_uniquizer(\$_[0]->{handle});
},
},
'subscriberprofilesets' => {
'data' => {
@ -266,6 +385,7 @@ sub build_data{
description => 'api_test_subscriberprofileset',
},
'query' => ['name'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
'subscriberprofiles' => {
'data' => {
@ -274,6 +394,7 @@ sub build_data{
description => 'api_test subscriberprofile',
},
'query' => ['name'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
'pbxdeviceconfigs' => {
'data' => {
@ -299,11 +420,12 @@ sub build_data{
},
'query' => ['name'],
'no_delete_available' => 1,
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
'rewriterulesets' => {
'data' => {
reseller_id => sub { return shift->get_id('resellers',@_); },
name => 'api_test rule set name',
name => 'api_test',
description => 'api_test rule set description',
caller_in_dpid => '1',
callee_in_dpid => '2',
@ -311,6 +433,7 @@ sub build_data{
callee_out_dpid => '4',
},
'query' => ['name'],
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
};
$self->process_data($data);
@ -446,9 +569,12 @@ sub set_data_from_script{
sub load_data_from_script{
my($self, $collection_name) = @_;
my $collection_file = dirname($0)."/api-$collection_name.t";
my $collection_file = dirname($0)."/api-$collection_name-collection.t";
if(! -e $collection_file){
$collection_file = dirname($0)."/api-${collection_name}.t";
}
my $found = 0;
if(-e $collection_file){
if(-e $collection_file && fgrep { /set_data_from_script/ } $collection_file ){
#dirty hack, part 1. To think about Safe
local @ARGV = qw/load_data_only/;
our $data_out;
@ -596,6 +722,7 @@ sub create{
}
return $self->get_existent_id($collection_name);
}
sub create_special_upload{
my $self = shift;
return sub {
@ -673,7 +800,20 @@ sub get_collection_interface{
$data //= $self->data;
return $data->{$collection_name}->{collection} ? $data->{$collection_name}->{collection} : $collection_name;
}
sub string_uniquizer{
my($field,$data,$additions) = @_;
state $i;
$i++;
$additions //= '';
if(ref $field){
$$field = $$field.time().$i.$additions;
}else{
$field = $field.time().$i.$additions;
}
return $field;
}
1;
__END__
Further improvements:

Loading…
Cancel
Save