TT#49754 add t/api-rest/api-headerrulesets.t

Change-Id: I9a841dee3a91117df63059cb6fd6ee49a0a4345e
changes/62/26062/4
Kirill Solomko 7 years ago
parent 9b2ec32e4a
commit 66241b6d03

@ -726,6 +726,18 @@ sub update_item {
}
last SWITCH;
};
/^header_rule_set$/ && do {
my $hdr_set = $c->model('DB')->resultset('voip_header_rule_sets')->find({
name => $resource->{$pref},
reseller_id => $reseller_id,
});
unless($hdr_set) {
$c->log->error("no header rule set '".$resource->{$pref}."' for reseller id $reseller_id found");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Unknown header_rule_set '".$resource->{$pref}."'");
return;
}
last SWITCH;
};
/^(adm_)?(cf_)?ncos$/ && do {
my $pref_name = $pref . "_id";
my $ncos = $c->model('DB')->resultset('ncos_levels')->find({

@ -0,0 +1,53 @@
use strict;
use warnings;
use Test::Collection;
use Test::FakeData;
use Test::More;
use Data::Dumper;
#init test_machine
my $test_machine = Test::Collection->new(
name => 'headerrulesets',
embedded_resources => []
);
$test_machine->methods->{collection}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS POST)};
$test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS PUT PATCH DELETE)};
my $fake_data = Test::FakeData->new;
$fake_data->set_data_from_script({
headerrulesets => {
'data' => {
reseller_id => sub { return shift->get_id('resellers',@_); },
name => 'api_test',
description => 'api_test rule set description',
},
'query' => ['name'],
'data_callbacks' => {
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
},
});
#for item creation test purposes /post request data/
$test_machine->DATA_ITEM_STORE($fake_data->process('headerrulesets'));
$test_machine->form_data_item( );
my $sets = $test_machine->check_create_correct( 3, sub{ $_[0]->{name} .= $_[1]->{i}.time(); } );
$test_machine->check_get2put();
$test_machine->check_bundle();
# try to create ruleset without reseller_id
{
my ($res, $err) = $test_machine->check_item_post(sub{delete $_[0]->{reseller_id};});
is($res->code, 422, "create ruleset without reseller_id");
is($err->{code}, "422", "check error code in body");
ok($err->{message} =~ /field='reseller_id'/, "check error message in body");
}
$test_machine->clear_test_data_all();
done_testing;
# vim: set tabstop=4 expandtab:

@ -29,6 +29,7 @@ $fake_data->set_data_from_script({
emergencymappingcontainer_id => sub { return shift->get_id('emergencymappingcontainers',@_); },
rewriteruleset_id => sub { return shift->get_id('rewriterulesets',@_); },
headerruleset_id => sub { return shift->get_id('headerrulesets',@_); },
soundset_id => sub { return shift->get_id('soundsets',@_); },
ncoslevel_id => sub { return shift->get_id('ncoslevels',@_); },
},

@ -25,10 +25,10 @@ fi
if [ "${SELECT}" = "stable" ] ; then
echo "Test selection: ${SELECT}"
SELECT=$(echo ./t/api-rest/api-{all-links,balanceintervals,bannedips,bannedusers,billingfees,billingnetworks,billingprofiles,billingzones,calllists,calls,cert-auth,cfdestinationsets,contracts,conversations,customercontacts,customers,emailtemplates,faxes,journals,lnp,ncoslevels,pbxdevicemodels,pbxdevices,peeringgroups,peeringrules,peeringinboundrules,peeringservers,preferences,profilepackages,resellers,rewriterules,rewriterulesets,root,soundsets,subscriberregistrations,subscribers,systemcontacts,threads,topuplogs,trustedsources,valid-patch,vouchers,method-override}.t)
SELECT=$(echo ./t/api-rest/api-{all-links,balanceintervals,bannedips,bannedusers,billingfees,billingnetworks,billingprofiles,billingzones,calllists,calls,cert-auth,cfdestinationsets,contracts,conversations,customercontacts,customers,emailtemplates,faxes,journals,headerrulesets,lnp,ncoslevels,pbxdevicemodels,pbxdevices,peeringgroups,peeringrules,peeringinboundrules,peeringservers,preferences,profilepackages,resellers,rewriterules,rewriterulesets,root,soundsets,subscriberregistrations,subscribers,systemcontacts,threads,topuplogs,trustedsources,valid-patch,vouchers,method-override}.t)
elif [ "${SELECT}" = "fast" ] ; then
echo "Test selection: ${SELECT}"
SELECT=$(echo ./t/api-rest/api-{bannedips,bannedusers,billingnetworks,billingzones,calls,cert-auth,cfdestinationsets,ncoslevels,peeringgroups,peeringrules,peeringinboundrules,peeringservers,resellers,rewriterules,root,soundsets,systemcontacts,valid-patch,vouchers,method-override}.t)
SELECT=$(echo ./t/api-rest/api-{bannedips,bannedusers,billingnetworks,billingzones,calls,cert-auth,cfdestinationsets,headerrulesets,ncoslevels,peeringgroups,peeringrules,peeringinboundrules,peeringservers,resellers,rewriterules,root,soundsets,systemcontacts,valid-patch,vouchers,method-override}.t)
elif [ "${SELECT}" = "all" ] ; then
echo "Test selection: all"
SELECT=$(echo ./t/api-rest/*.t)

@ -467,6 +467,17 @@ sub build_data{
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
},
'headerrulesets' => {
'data' => {
reseller_id => sub { return shift->get_id('resellers',@_); },
name => 'api_test',
description => 'api_test rule set description',
},
'query' => ['name'],
'data_callbacks' => {
'uniquizer_cb' => sub { Test::FakeData::string_uniquizer(\$_[0]->{name}); },
},
},
};
$self->process_data($data);
return $data;

Loading…
Cancel
Save