MT#6195 api-tests: use is instead of ok

better diagnostics
agranig/selfsignup
Gerhard Jungwirth 11 years ago
parent cc3a7eaa2a
commit 386b2f410f

@ -32,7 +32,8 @@ $ua->ssl_opts(
SSL_ca_file => $ssl_ca_cert,
);
$res = $ua->get($uri.'/api/');
ok($res->code == 400, "check invalid client certificate");
is($res->code, 400, "check invalid client certificate")
|| note ($res->message);
# unauth cert
$ua->ssl_opts(
@ -41,7 +42,8 @@ $ua->ssl_opts(
SSL_ca_file => $ssl_ca_cert,
);
$res = $ua->get($uri.'/api/');
ok($res->code == 403, "check unauthorized client certificate");
is($res->code, 403, "check unauthorized client certificate")
|| note ($res->message);
# successful auth
$ua->ssl_opts(
@ -50,7 +52,8 @@ $ua->ssl_opts(
SSL_ca_file => $ssl_ca_cert,
);
$res = $ua->get($uri.'/api/');
ok($res->code == 200, "check valid client certificate");
is($res->code, 200, "check valid client certificate")
|| note ($res->message);
#my @links = $res->header('Link');
#ok(grep /^<\/api\/contacts\/>; rel="collection /, @links);

@ -25,7 +25,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/billingfees/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-billingfees", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -49,7 +49,7 @@ $req->content(JSON::to_json({
name => "test api name $t",
}));
$res = $ua->request($req);
ok($res->code == 201, "create test billing profile");
is($res->code, 201, "create test billing profile");
my $billing_profile_id = $res->header('Location');
# TODO: get it from body!
$billing_profile_id =~ s/^.+\/(\d+)$/$1/;
@ -64,7 +64,7 @@ $req->content(JSON::to_json({
detail => "test zone from api",
}));
$res = $ua->request($req);
ok($res->code == 201, "create test billing zone");
is($res->code, 201, "create test billing zone");
my $billing_zone_id = $res->header('Location');
# TODO: get it from body!
$billing_zone_id =~ s/^.+\/(\d+)$/$1/;
@ -93,7 +93,7 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test billing fee $i");
is($res->code, 201, "create test billing fee $i");
$fees{$res->header('Location')} = 1;
push @allfees, $res->header('Location');
$firstfee = $res->header('Location') unless $firstfee;
@ -117,7 +117,7 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile without billing_profile_id");
is($res->code, 422, "create profile without billing_profile_id");
my $err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'billing_profile_id'/, "check error message in body");
@ -140,7 +140,7 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile with invalid billing_profile_id");
is($res->code, 422, "create profile with invalid billing_profile_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'billing_profile_id'/, "check error message in body");
@ -163,7 +163,7 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile without billing_zone_id");
is($res->code, 422, "create profile without billing_zone_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='billing_zone_id'/, "check error message in body");
@ -186,7 +186,7 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile without billing_profile_id");
is($res->code, 422, "create profile without billing_profile_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'billing_zone_id'/, "check error message in body");
@ -197,7 +197,7 @@ my @allfees = ();
my $nexturi = $uri.'/api/billingfees/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch fees page");
is($res->code, 200, "fetch fees page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -249,7 +249,7 @@ my @allfees = ();
} while($nexturi);
ok(keys %fees == 0, "check if all test billing fees have been found");
is(scalar(keys %fees), 0, "check if all test billing fees have been found");
# try to create fee with implicit zone which already exists
$req = HTTP::Request->new('POST', $uri.'/api/billingfees/');
@ -270,16 +270,16 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 201, "create profile fee with existing implicit zone");
is($res->code, 201, "create profile fee with existing implicit zone");
$req = HTTP::Request->new('GET', $uri.$res->header('Location'));
$res = $ua->request($req);
ok($res->code == 200, "fetch profile fee with existing implicit zone");
is($res->code, 200, "fetch profile fee with existing implicit zone");
my $z_fee = JSON::from_json($res->decoded_content);
ok(exists $z_fee->{billing_zone_id} && $z_fee->{billing_zone_id} == $billing_zone_id, "check if implicit zone returns the correct zone id");
$req = HTTP::Request->new('DELETE', $uri.$z_fee->{_links}->{'self'}->{href});
$res = $ua->request($req);
ok($res->code == 204, "delete fee of existing implicit zone");
is($res->code, 204, "delete fee of existing implicit zone");
# try to create fee with implicit zone which doesn't exist yet
my $t = time;
@ -301,20 +301,20 @@ my @allfees = ();
offpeak_follow_interval => 30,
}));
$res = $ua->request($req);
ok($res->code == 201, "create profile fee with new implicit zone");
is($res->code, 201, "create profile fee with new implicit zone");
$req = HTTP::Request->new('GET', $uri.$res->header('Location'));
$res = $ua->request($req);
ok($res->code == 200, "fetch profile fee with new implicit zone");
is($res->code, 200, "fetch profile fee with new implicit zone");
$z_fee = JSON::from_json($res->decoded_content);
ok(exists $z_fee->{billing_zone_id} && $z_fee->{billing_zone_id} > $billing_zone_id, "check if implicit zone returns a new zone id");
$req = HTTP::Request->new('DELETE', $uri.$z_fee->{_links}->{'ngcp:billingzones'}->{href});
$res = $ua->request($req);
ok($res->code == 204, "delete new implicit zone");
is($res->code, 204, "delete new implicit zone");
$req = HTTP::Request->new('GET', $uri.$z_fee->{_links}->{'self'}->{href});
$res = $ua->request($req);
ok($res->code == 404, "check if fee is deleted when zone is deleted");
is($res->code, 404, "check if fee is deleted when zone is deleted");
}
@ -323,7 +323,7 @@ my @allfees = ();
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstfee);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -338,7 +338,7 @@ my @allfees = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstfee);
$res = $ua->request($req);
ok($res->code == 200, "fetch one fee item");
is($res->code, 200, "fetch one fee item");
my $fee = JSON::from_json($res->decoded_content);
ok(exists $fee->{billing_profile_id} && $fee->{billing_profile_id} == $billing_profile_id, "check existence of billing_profile_id");
ok(exists $fee->{billing_zone_id} && $fee->{billing_zone_id} == $billing_zone_id, "check existence of billing_zone_id");
@ -356,12 +356,12 @@ my @allfees = ();
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -369,12 +369,12 @@ my @allfees = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -382,12 +382,12 @@ my @allfees = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($fee));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_fee = JSON::from_json($res->decoded_content);
is_deeply($old_fee, $new_fee, "check put if unmodified put returns the same");
@ -403,7 +403,7 @@ my @allfees = ();
[ { op => 'replace', path => '/direction', value => 'in' } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched fee item");
is($res->code, 200, "check patched fee item");
my $mod_fee = JSON::from_json($res->decoded_content);
ok($mod_fee->{direction} eq "in", "check patched replace op");
ok($mod_fee->{_links}->{self}->{href} eq $firstfee, "check patched self link");
@ -413,25 +413,25 @@ my @allfees = ();
[ { op => 'replace', path => '/billing_profile_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef billing_profile_id");
is($res->code, 422, "check patched undef billing_profile_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_profile_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid billing_profile_id");
is($res->code, 422, "check patched invalid billing_profile_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_zone_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef billing_zone_id");
is($res->code, 422, "check patched undef billing_zone_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_zone_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid billing_zone_id");
is($res->code, 422, "check patched invalid billing_zone_id");
}
{
@ -439,20 +439,20 @@ my @allfees = ();
foreach my $f(@allfees) {
$req = HTTP::Request->new('DELETE', $uri.'/'.$f);
$res = $ua->request($req);
ok($res->code == 204, "check delete of fee");
is($res->code, 204, "check delete of fee");
$ff = $f unless $ff;
}
$req = HTTP::Request->new('GET', $uri.'/'.$ff);
$res = $ua->request($req);
ok($res->code == 404, "check if deleted fee is really gone");
is($res->code, 404, "check if deleted fee is really gone");
$req = HTTP::Request->new('DELETE', $uri.'/api/billingzones/'.$billing_zone_id);
$res = $ua->request($req);
ok($res->code == 204, "check delete of zone");
is($res->code, 204, "check delete of zone");
$req = HTTP::Request->new('GET', $uri.'/api/billingzones/'.$billing_zone_id);
$res = $ua->request($req);
ok($res->code == 404, "check if deleted zone is really gone");
is($res->code, 404, "check if deleted zone is really gone");
}
done_testing;

@ -25,7 +25,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/billingprofiles/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-billingprofiles", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -53,7 +53,7 @@ my @allprofiles = ();
name => "test api name $i".time,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test billing profile $i");
is($res->code, 201, "create test billing profile $i");
$profiles{$res->header('Location')} = 1;
push @allprofiles, $res->header('Location');
$firstprofile = $res->header('Location') unless $firstprofile;
@ -67,7 +67,7 @@ my @allprofiles = ();
name => "test api name",
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile without reseller_id");
is($res->code, 422, "create profile without reseller_id");
my $err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='reseller_id'/, "check error message in body");
@ -79,7 +79,7 @@ my @allprofiles = ();
reseller_id => undef,
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile with empty reseller_id");
is($res->code, 422, "create profile with empty reseller_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='reseller_id'/, "check error message in body");
@ -91,7 +91,7 @@ my @allprofiles = ();
reseller_id => 99999,
}));
$res = $ua->request($req);
ok($res->code == 422, "create profile with invalid reseller_id");
is($res->code, 422, "create profile with invalid reseller_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'reseller_id'/, "check error message in body");
@ -102,7 +102,7 @@ my @allprofiles = ();
my $nexturi = $uri.'/api/billingprofiles/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch profile page");
is($res->code, 200, "fetch profile page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -157,14 +157,14 @@ my @allprofiles = ();
} while($nexturi);
ok(keys %profiles == 0, "check if all test billing profiles have been found");
is(scalar(keys %profiles), 0, "check if all test billing profiles have been found");
}
# test profile item
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstprofile);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -179,7 +179,7 @@ my @allprofiles = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstprofile);
$res = $ua->request($req);
ok($res->code == 200, "fetch one contract item");
is($res->code, 200, "fetch one contract item");
my $profile = JSON::from_json($res->decoded_content);
ok(exists $profile->{reseller_id} && $profile->{reseller_id}->is_int, "check existence of reseller_id");
ok(exists $profile->{handle}, "check existence of handle");
@ -195,12 +195,12 @@ my @allprofiles = ();
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -208,12 +208,12 @@ my @allprofiles = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -221,12 +221,12 @@ my @allprofiles = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($profile));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_profile = JSON::from_json($res->decoded_content);
is_deeply($old_profile, $new_profile, "check put if unmodified put returns the same");
@ -243,7 +243,7 @@ my @allprofiles = ();
[ { op => 'replace', path => '/name', value => 'patched name '.$t } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched profile item");
is($res->code, 200, "check patched profile item");
my $mod_profile = JSON::from_json($res->decoded_content);
ok($mod_profile->{name} eq "patched name $t", "check patched replace op");
ok($mod_profile->{_links}->{self}->{href} eq $firstprofile, "check patched self link");
@ -254,13 +254,13 @@ my @allprofiles = ();
[ { op => 'replace', path => '/reseller_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef reseller");
is($res->code, 422, "check patched undef reseller");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/reseller_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid reseller");
is($res->code, 422, "check patched invalid reseller");
# TODO: invalid handle etc
}

@ -27,7 +27,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/contracts/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-contracts", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -48,7 +48,7 @@ $req->content(JSON::to_json({
reseller_id => 1,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test billing profile");
is($res->code, 201, "create test billing profile");
# TODO: get id from body once the API returns it
my $billing_profile_id = $res->header('Location');
$billing_profile_id =~ s/^.+\/(\d+)$/$1/;
@ -71,10 +71,10 @@ my @allcontracts = ();
email => "sys_contact\@syscontact.invalid",
}));
$res = $ua->request($req);
ok($res->code == 201, "create system contact");
is($res->code, 201, "create system contact");
$req = HTTP::Request->new('GET', $uri.'/'.$res->header('Location'));
$res = $ua->request($req);
ok($res->code == 200, "fetch system contact");
is($res->code, 200, "fetch system contact");
$syscontact = JSON::from_json($res->decoded_content);
# create 6 new reseller contracts
@ -89,7 +89,7 @@ my @allcontracts = ();
billing_profile_id => $billing_profile_id,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test reseller contract $i");
is($res->code, 201, "create test reseller contract $i");
$contracts{$res->header('Location')} = 1;
push @allcontracts, $res->header('Location');
$firstcontract = $res->header('Location') unless $firstcontract;
@ -105,7 +105,7 @@ my @allcontracts = ();
type => "invalid",
}));
$res = $ua->request($req);
ok($res->code == 422, "create contract with invalid type");
is($res->code, 422, "create contract with invalid type");
my $err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'type'/, "check error message in body");
@ -118,7 +118,7 @@ my @allcontracts = ();
billing_profile_id => 999999,
}));
$res = $ua->request($req);
ok($res->code == 422, "create contract with invalid billing profile");
is($res->code, 422, "create contract with invalid billing profile");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'billing_profile_id'/, "check error message in body");
@ -131,7 +131,7 @@ my @allcontracts = ();
contact_id => $customer_contact_id,
}));
$res = $ua->request($req);
ok($res->code == 422, "create contract with invalid contact");
is($res->code, 422, "create contract with invalid contact");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /The contact_id is not a valid ngcp:systemcontacts item/, "check error message in body");
@ -143,7 +143,7 @@ my @allcontracts = ();
billing_profile_id => $billing_profile_id,
}));
$res = $ua->request($req);
ok($res->code == 422, "create contract without contact");
is($res->code, 422, "create contract without contact");
# try to create invalid contract with invalid status
$req->content(JSON::to_json({
@ -153,7 +153,7 @@ my @allcontracts = ();
status => "invalid",
}));
$res = $ua->request($req);
ok($res->code == 422, "create contract with invalid status");
is($res->code, 422, "create contract with invalid status");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='status'/, "check error message in body");
@ -162,7 +162,7 @@ my @allcontracts = ();
my $nexturi = $uri.'/api/contracts/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch contacts page");
is($res->code, 200, "fetch contacts page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -221,14 +221,14 @@ my @allcontracts = ();
} while($nexturi);
ok(keys %contracts == 0, "check if all test contracts have been found");
is(scalar(keys %contracts), 0, "check if all test contracts have been found");
}
# test contacts item
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstcontract);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -243,7 +243,7 @@ my @allcontracts = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstcontract);
$res = $ua->request($req);
ok($res->code == 200, "fetch one contract item");
is($res->code, 200, "fetch one contract item");
my $contract = JSON::from_json($res->decoded_content);
ok(exists $contract->{status}, "check existence of status");
ok(exists $contract->{type}, "check existence of type");
@ -261,12 +261,12 @@ my @allcontracts = ();
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -274,12 +274,12 @@ my @allcontracts = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -287,12 +287,12 @@ my @allcontracts = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($contract));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_contract = JSON::from_json($res->decoded_content);
is_deeply($old_contract, $new_contract, "check put if unmodified put returns the same");
@ -310,7 +310,7 @@ my @allcontracts = ();
[ { op => 'replace', path => '/status', value => 'pending' } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched contract item");
is($res->code, 200, "check patched contract item");
my $mod_contact = JSON::from_json($res->decoded_content);
ok($mod_contact->{status} eq "pending", "check patched replace op");
ok($mod_contact->{_links}->{self}->{href} eq $firstcontract, "check patched self link");
@ -321,37 +321,37 @@ my @allcontracts = ();
[ { op => 'replace', path => '/status', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef status");
is($res->code, 422, "check patched undef status");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/status', value => 'invalid' } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid status");
is($res->code, 422, "check patched invalid status");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/contact_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid contact_id");
is($res->code, 422, "check patched invalid contact_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/contact_id', value => $customer_contact_id } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched customer contact_id");
is($res->code, 422, "check patched customer contact_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_profile_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef billing_profile_id");
is($res->code, 422, "check patched undef billing_profile_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_profile_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid billing_profile_id");
is($res->code, 422, "check patched invalid billing_profile_id");
}
# terminate
@ -359,7 +359,7 @@ my @allcontracts = ();
# check if deletion of contact fails before terminating the contracts
$req = HTTP::Request->new('DELETE', $uri.'/'.$syscontact->{_links}->{self}->{href});
$res = $ua->request($req);
ok($res->code == 423, "check locked status for deleting used contact");
is($res->code, 423, "check locked status for deleting used contact");
my $pc;
foreach my $contract(@allcontracts) {
@ -370,7 +370,7 @@ my @allcontracts = ();
{ "op" => "replace", "path" => "/status", "value" => "terminated" }
]));
$res = $ua->request($req);
ok($res->code == 200, "check termination of contract");
is($res->code, 200, "check termination of contract");
$pc = JSON::from_json($res->decoded_content);
ok($pc->{status} eq "terminated", "check termination status of contract");
}
@ -378,14 +378,14 @@ my @allcontracts = ();
# check if we can still get the terminated contract
$req = HTTP::Request->new('GET', $uri.'/'.$pc->{_links}->{self}->{href});
$res = $ua->request($req);
ok($res->code == 404, "check fetching of terminated contract");
is($res->code, 404, "check fetching of terminated contract");
# check if deletion of contact is now ok
# TODO: are we supposed to be able to delete a contact for a terminated
# contract? there are still DB contstraints in the way!
#$req = HTTP::Request->new('DELETE', $uri.'/'.$syscontact->{_links}->{self}->{href});
#$res = $ua->request($req);
#ok($res->code == 204, "check deletion of unused contact");
#is($res->code, 204, "check deletion of unused contact");
}
done_testing;

@ -25,7 +25,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/customercontacts/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-customercontacts", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -42,7 +42,7 @@ my @allcontacts = ();
{
$req = HTTP::Request->new('GET', $uri.'/api/resellers/');
$res = $ua->request($req);
ok($res->code == 200, "fetch resellers");
is($res->code, 200, "fetch resellers");
my $reseller = JSON::from_json($res->decoded_content);
if(ref $reseller->{_embedded}->{'ngcp:resellers'} eq 'ARRAY') {
$reseller = $reseller->{_embedded}->{'ngcp:resellers'}->[0]->{id};
@ -65,7 +65,7 @@ my @allcontacts = ();
reseller_id => $reseller,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test contact $i");
is($res->code, 201, "create test contact $i");
$contacts{$res->header('Location')} = 1;
push @allcontacts, $res->header('Location');
$firstcontact = $res->header('Location') unless $firstcontact;
@ -80,7 +80,7 @@ my @allcontacts = ();
reseller_id => $reseller,
}));
$res = $ua->request($req);
ok($res->code == 422, "create invalid test contact with missing email");
is($res->code, 422, "create invalid test contact with missing email");
my $email_err = JSON::from_json($res->decoded_content);
ok($email_err->{code} eq "422", "check error code in body");
ok($email_err->{message} =~ /field=\'email\'/, "check error message in body");
@ -92,7 +92,7 @@ my @allcontacts = ();
#reseller_id => $reseller,
}));
$res = $ua->request($req);
ok($res->code == 422, "create invalid test contact with missing reseller_id");
is($res->code, 422, "create invalid test contact with missing reseller_id");
$email_err = JSON::from_json($res->decoded_content);
ok($email_err->{code} eq "422", "check error code in body");
ok($email_err->{message} =~ /field=\'reseller_id\'/, "check error message in body");
@ -105,7 +105,7 @@ my @allcontacts = ();
reseller_id => 99999,
}));
$res = $ua->request($req);
ok($res->code == 422, "create invalid test contact with invalid reseller_id");
is($res->code, 422, "create invalid test contact with invalid reseller_id");
$email_err = JSON::from_json($res->decoded_content);
ok($email_err->{code} eq "422", "check error code in body");
ok($email_err->{message} =~ /Invalid \'reseller_id\'/, "check error message in body");
@ -114,7 +114,7 @@ my @allcontacts = ();
my $nexturi = $uri.'/api/customercontacts/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch contacts page");
is($res->code, 200, "fetch contacts page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -158,14 +158,14 @@ my @allcontacts = ();
}
} while($nexturi);
ok(keys %contacts == 0, "check if all test contacts have been found");
is(scalar(keys %contacts), 0, "check if all test contacts have been found");
}
# test contacts item
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstcontact);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -179,7 +179,7 @@ my @allcontacts = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstcontact);
$res = $ua->request($req);
ok($res->code == 200, "fetch one contact item");
is($res->code, 200, "fetch one contact item");
my $contact = JSON::from_json($res->decoded_content);
ok(exists $contact->{firstname}, "check existence of firstname");
ok(exists $contact->{lastname}, "check existence of lastname");
@ -197,12 +197,12 @@ my @allcontacts = ();
# check if it fails without content type
$req->remove_header('Content-Type');
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -210,12 +210,12 @@ my @allcontacts = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -223,12 +223,12 @@ my @allcontacts = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($contact));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_contact = JSON::from_json($res->decoded_content);
is_deeply($old_contact, $new_contact, "check put if unmodified put returns the same");
@ -241,7 +241,7 @@ my @allcontacts = ();
[ { op => 'replace', path => '/firstname', value => 'patchedfirst' } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched contact item");
is($res->code, 200, "check patched contact item");
my $mod_contact = JSON::from_json($res->decoded_content);
ok($mod_contact->{firstname} eq "patchedfirst", "check patched replace op");
@ -249,7 +249,7 @@ my @allcontacts = ();
[ { op => 'replace', path => '/firstname', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched contact item");
is($res->code, 200, "check patched contact item");
$mod_contact = JSON::from_json($res->decoded_content);
ok(exists $mod_contact->{firstname} && !defined $mod_contact->{firstname}, "check patched replace op for undef");
@ -257,19 +257,19 @@ my @allcontacts = ();
[ { op => 'replace', path => '/email', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched contact with unset email");
is($res->code, 422, "check patched contact with unset email");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/reseller_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched contact with unset reseller_id");
is($res->code, 422, "check patched contact with unset reseller_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/reseller_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched contact with invalid reseller_id");
is($res->code, 422, "check patched contact with invalid reseller_id");
}
# DELETE
@ -277,7 +277,7 @@ my @allcontacts = ();
foreach my $contact(@allcontacts) {
$req = HTTP::Request->new('DELETE', $uri.'/'.$contact);
$res = $ua->request($req);
ok($res->code == 204, "check delete of contact");
is($res->code, 204, "check delete of contact");
}
}

@ -27,7 +27,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/customers/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-customers", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -50,7 +50,7 @@ $req->content(JSON::to_json({
reseller_id => $reseller_id,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test billing profile");
is($res->code, 201, "create test billing profile");
# TODO: get id from body once the API returns it
my $billing_profile_id = $res->header('Location');
$billing_profile_id =~ s/^.+\/(\d+)$/$1/;
@ -58,7 +58,7 @@ $billing_profile_id =~ s/^.+\/(\d+)$/$1/;
# fetch a system contact for later tests
$req = HTTP::Request->new('GET', $uri.'/api/systemcontacts/?page=1&rows=1');
$res = $ua->request($req);
ok($res->code == 200, "fetch system contacts");
is($res->code, 200, "fetch system contacts");
my $sysct = JSON::from_json($res->decoded_content);
my $system_contact_id = $sysct->{_embedded}->{'ngcp:systemcontacts'}->{id};
@ -77,10 +77,10 @@ my @allcustomers = ();
reseller_id => $reseller_id,
}));
$res = $ua->request($req);
ok($res->code == 201, "create customer contact");
is($res->code, 201, "create customer contact");
$req = HTTP::Request->new('GET', $uri.'/'.$res->header('Location'));
$res = $ua->request($req);
ok($res->code == 200, "fetch system contact");
is($res->code, 200, "fetch system contact");
$custcontact = JSON::from_json($res->decoded_content);
# create 6 new customers
@ -97,8 +97,8 @@ my @allcustomers = ();
external_id => undef,
}));
$res = $ua->request($req);
ok($res->code == 201, "create test customer $i");
$customers{$res->header('Location')} = 1;
is($res->code, 201, "create test customer $i");
$customers{$res->header('Location') // ''} = 1;
push @allcustomers, $res->header('Location');
$firstcustomer = $res->header('Location') unless $firstcustomer;
}
@ -115,7 +115,7 @@ my @allcustomers = ();
type => "invalid",
}));
$res = $ua->request($req);
ok($res->code == 422, "create customer with invalid type");
is($res->code, 422, "create customer with invalid type");
my $err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'type'/, "check error message in body");
@ -130,7 +130,7 @@ my @allcustomers = ();
billing_profile_id => 999999,
}));
$res = $ua->request($req);
ok($res->code == 422, "create customer with invalid billing profile");
is($res->code, 422, "create customer with invalid billing profile");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /Invalid 'billing_profile_id'/, "check error message in body");
@ -145,7 +145,7 @@ my @allcustomers = ();
contact_id => $system_contact_id,
}));
$res = $ua->request($req);
ok($res->code == 422, "create customer with invalid contact");
is($res->code, 422, "create customer with invalid contact");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /The contact_id is not a valid ngcp:customercontacts item/, "check error message in body");
@ -159,7 +159,7 @@ my @allcustomers = ();
external_id => undef,
}));
$res = $ua->request($req);
ok($res->code == 422, "create customer without contact");
is($res->code, 422, "create customer without contact");
# try to create invalid customer with invalid status
$req->content(JSON::to_json({
@ -171,7 +171,7 @@ my @allcustomers = ();
status => "invalid",
}));
$res = $ua->request($req);
ok($res->code == 422, "create customer with invalid status");
is($res->code, 422, "create customer with invalid status");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='status'/, "check error message in body");
@ -186,7 +186,7 @@ my @allcustomers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 422, "create customer with invalid max_subscribers");
is($res->code, 422, "create customer with invalid max_subscribers");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='max_subscribers'/, "check error message in body");
@ -195,7 +195,7 @@ my @allcustomers = ();
my $nexturi = $uri.'/api/customers/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch contacts page");
is($res->code, 200, "fetch contacts page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -253,14 +253,14 @@ my @allcustomers = ();
} while($nexturi);
ok(keys %customers == 0, "check if all test customers have been found");
is(scalar(keys %customers), 0, "check if all test customers have been found");
}
# test contacts item
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstcustomer);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -275,7 +275,7 @@ my @allcustomers = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstcustomer);
$res = $ua->request($req);
ok($res->code == 200, "fetch one customer item");
is($res->code, 200, "fetch one customer item");
my $customer = JSON::from_json($res->decoded_content);
ok(exists $customer->{status}, "check existence of status");
ok(exists $customer->{type}, "check existence of type");
@ -295,12 +295,12 @@ my @allcustomers = ();
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -308,12 +308,12 @@ my @allcustomers = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -321,12 +321,12 @@ my @allcustomers = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($customer));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_customer = JSON::from_json($res->decoded_content);
is_deeply($old_customer, $new_customer, "check put if unmodified put returns the same");
@ -344,7 +344,7 @@ my @allcustomers = ();
[ { op => 'replace', path => '/status', value => 'pending' } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched customer item");
is($res->code, 200, "check patched customer item");
my $mod_contact = JSON::from_json($res->decoded_content);
ok($mod_contact->{status} eq "pending", "check patched replace op");
ok($mod_contact->{_links}->{self}->{href} eq $firstcustomer, "check patched self link");
@ -355,43 +355,43 @@ my @allcustomers = ();
[ { op => 'replace', path => '/status', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef status");
is($res->code, 422, "check patched undef status");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/status', value => 'invalid' } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid status");
is($res->code, 422, "check patched invalid status");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/contact_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid contact_id");
is($res->code, 422, "check patched invalid contact_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/contact_id', value => $system_contact_id } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched system contact_id");
is($res->code, 422, "check patched system contact_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_profile_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef billing_profile_id");
is($res->code, 422, "check patched undef billing_profile_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/billing_profile_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid billing_profile_id");
is($res->code, 422, "check patched invalid billing_profile_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/max_subscribers', value => "abc" } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid max_subscribers");
is($res->code, 422, "check patched invalid max_subscribers");
}
# terminate
@ -399,7 +399,7 @@ my @allcustomers = ();
# check if deletion of contact fails before terminating the customers
$req = HTTP::Request->new('DELETE', $uri.'/'.$custcontact->{_links}->{self}->{href});
$res = $ua->request($req);
ok($res->code == 423, "check locked status for deleting used contact");
is($res->code, 423, "check locked status for deleting used contact");
my $pc;
foreach my $customer(@allcustomers) {
@ -410,7 +410,7 @@ my @allcustomers = ();
{ "op" => "replace", "path" => "/status", "value" => "terminated" }
]));
$res = $ua->request($req);
ok($res->code == 200, "check termination of customer");
is($res->code, 200, "check termination of customer");
$pc = JSON::from_json($res->decoded_content);
ok($pc->{status} eq "terminated", "check termination status of customer");
}
@ -418,14 +418,14 @@ my @allcustomers = ();
# check if we can still get the terminated customer
$req = HTTP::Request->new('GET', $uri.'/'.$pc->{_links}->{self}->{href});
$res = $ua->request($req);
ok($res->code == 404, "check fetching of terminated customer");
is($res->code, 404, "check fetching of terminated customer");
# check if deletion of contact is now ok
# TODO: are we supposed to be able to delete a contact for a terminated
# customer? there are still DB contstraints in the way!
#$req = HTTP::Request->new('DELETE', $uri.'/'.$custcontact->{_links}->{self}->{href});
#$res = $ua->request($req);
#ok($res->code == 204, "check deletion of unused contact");
#is($res->code, 204, "check deletion of unused contact");
}
done_testing;

@ -25,7 +25,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/resellers/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-resellers", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -57,7 +57,7 @@ my @allresellers = ();
lastname => "api test last",
}));
$res = $ua->request($req);
ok($res->code == 201, "create system contact");
is($res->code, 201, "create system contact");
$syscontact = $res->header('Location');
# TODO: should be returned in post result
my $contact_id = $syscontact;
@ -75,7 +75,7 @@ my @allresellers = ();
}));
for(my $i = 1; $i <= 7; ++$i) { # create one more for later tests
$res = $ua->request($req);
ok($res->code == 201, "create reseller contract");
is($res->code, 201, "create reseller contract");
my $syscontract = $res->header('Location');
# TODO: should be returned in post result
my $contract_id = $syscontract;
@ -98,7 +98,7 @@ my @allresellers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 201, "create test reseller $i");
is($res->code, 201, "create test reseller $i");
$resellers{$res->header('Location')} = 1;
push @allresellers, $res->header('Location');
$firstreseller = $res->header('Location') unless $firstreseller;
@ -114,7 +114,7 @@ my @allresellers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller without contract_id");
is($res->code, 422, "create reseller without contract_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='contract_id'/, "check error message in body");
@ -126,7 +126,7 @@ my @allresellers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller with empty contract_id");
is($res->code, 422, "create reseller with empty contract_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='contract_id'/, "check error message in body");
@ -138,7 +138,7 @@ my @allresellers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller with existing contract_id");
is($res->code, 422, "create reseller with existing contract_id");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /reseller with this contract already exists/, "check error message in body");
@ -150,7 +150,7 @@ my @allresellers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller with existing name");
is($res->code, 422, "create reseller with existing name");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /reseller with this name already exists/, "check error message in body");
@ -161,7 +161,7 @@ my @allresellers = ();
status => "active",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller with missing name");
is($res->code, 422, "create reseller with missing name");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='name'/, "check error message in body");
@ -172,7 +172,7 @@ my @allresellers = ();
name => "test reseller $t 999",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller with invalid status");
is($res->code, 422, "create reseller with invalid status");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='status'/, "check error message in body");
@ -184,7 +184,7 @@ my @allresellers = ();
status => "invalid",
}));
$res = $ua->request($req);
ok($res->code == 422, "create reseller with invalid status");
is($res->code, 422, "create reseller with invalid status");
$err = JSON::from_json($res->decoded_content);
ok($err->{code} eq "422", "check error code in body");
ok($err->{message} =~ /field='status'/, "check error message in body");
@ -193,7 +193,7 @@ my @allresellers = ();
my $nexturi = $uri.'/api/resellers/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch reseller page");
is($res->code, 200, "fetch reseller page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -245,14 +245,14 @@ my @allresellers = ();
} while($nexturi);
ok(keys %resellers == 0, "check if all test resellers have been found");
is(scalar(keys %resellers), 0, "check if all test resellers have been found");
}
# test reseller item
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstreseller);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -267,7 +267,7 @@ my @allresellers = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstreseller);
$res = $ua->request($req);
ok($res->code == 200, "fetch one item");
is($res->code, 200, "fetch one item");
my $reseller = JSON::from_json($res->decoded_content);
ok(exists $reseller->{id} && $reseller->{id}->is_int, "check existence of id");
ok(exists $reseller->{contract_id} && $reseller->{contract_id}->is_int, "check existence of contract_id");
@ -284,12 +284,12 @@ my @allresellers = ();
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -297,12 +297,12 @@ my @allresellers = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -310,12 +310,12 @@ my @allresellers = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($reseller));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_reseller = JSON::from_json($res->decoded_content);
is_deeply($old_reseller, $new_reseller, "check put if unmodified put returns the same");
@ -331,7 +331,7 @@ my @allresellers = ();
[ { op => 'replace', path => '/name', value => 'patched name '.$t } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched reseller item");
is($res->code, 200, "check patched reseller item");
my $mod_reseller = JSON::from_json($res->decoded_content);
ok($mod_reseller->{name} eq "patched name $t", "check patched replace op");
ok($mod_reseller->{_links}->{self}->{href} eq $firstreseller, "check patched self link");
@ -341,43 +341,43 @@ my @allresellers = ();
[ { op => 'replace', path => '/contract_id', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef contract_id");
is($res->code, 422, "check patched undef contract_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/contract_id', value => 99999 } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid contract_id");
is($res->code, 422, "check patched invalid contract_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/contract_id', value => $secondcontract_id } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched existing contract_id");
is($res->code, 422, "check patched existing contract_id");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/name', value => "test reseller $t 2" } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched existing name");
is($res->code, 422, "check patched existing name");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/name', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef name");
is($res->code, 422, "check patched undef name");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/status', value => "invalid"} ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched invalid status");
is($res->code, 422, "check patched invalid status");
$req->content(JSON::to_json(
[ { op => 'replace', path => '/status', value => undef} ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched undef status");
is($res->code, 422, "check patched undef status");
}
# TODO: terminate our contracts and resellers again

@ -26,11 +26,11 @@ $ua->ssl_opts(
# test some uri params
$req = HTTP::Request->new('OPTIONS', $uri.'/api/?foo=bar&bla');
$res = $ua->request($req);
ok($res->code == 200, "check options request with uri params");
is($res->code, 200, "check options request with uri params");
$req = HTTP::Request->new('OPTIONS', $uri.'/api/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");

@ -25,7 +25,7 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('OPTIONS', $uri.'/api/systemcontacts/');
$res = $ua->request($req);
ok($res->code == 200, "check options request");
is($res->code, 200, "check options request");
ok($res->header('Accept-Post') eq "application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-systemcontacts", "check Accept-Post header in options response");
my $opts = JSON::from_json($res->decoded_content);
my @hopts = split /\s*,\s*/, $res->header('Allow');
@ -51,7 +51,7 @@ my @allcontacts = ();
email => "test.$i\@test.invalid",
}));
$res = $ua->request($req);
ok($res->code == 201, "create test contact $i");
is($res->code, 201, "create test contact $i");
$contacts{$res->header('Location')} = 1;
push @allcontacts, $res->header('Location');
$firstcontact = $res->header('Location') unless $firstcontact;
@ -65,7 +65,7 @@ my @allcontacts = ();
lastname => "Test_Last_invalid",
}));
$res = $ua->request($req);
ok($res->code == 422, "create invalid test contact with missing email");
is($res->code, 422, "create invalid test contact with missing email");
my $email_err = JSON::from_json($res->decoded_content);
ok($email_err->{code} eq "422", "check error code in body");
ok($email_err->{message} =~ /field=\'email\'/, "check error message in body");
@ -74,7 +74,7 @@ my @allcontacts = ();
my $nexturi = $uri.'/api/systemcontacts/?page=1&rows=5';
do {
$res = $ua->get($nexturi);
ok($res->code == 200, "fetch contacts page");
is($res->code, 200, "fetch contacts page");
my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href};
ok($selfuri eq $nexturi, "check _links.self.href of collection");
@ -119,14 +119,14 @@ my @allcontacts = ();
} while($nexturi);
ok(keys %contacts == 0, "check if all test contacts have been found");
is(scalar(keys %contacts), 0, "check if all test contacts have been found");
}
# test contacts item
{
$req = HTTP::Request->new('OPTIONS', $uri.'/'.$firstcontact);
$res = $ua->request($req);
ok($res->code == 200, "check options on item");
is($res->code, 200, "check options on item");
my @hopts = split /\s*,\s*/, $res->header('Allow');
my $opts = JSON::from_json($res->decoded_content);
ok(exists $opts->{methods} && ref $opts->{methods} eq "ARRAY", "check for valid 'methods' in body");
@ -140,7 +140,7 @@ my @allcontacts = ();
$req = HTTP::Request->new('GET', $uri.'/'.$firstcontact);
$res = $ua->request($req);
ok($res->code == 200, "fetch one contact item");
is($res->code, 200, "fetch one contact item");
my $contact = JSON::from_json($res->decoded_content);
ok(exists $contact->{firstname}, "check existence of firstname");
ok(exists $contact->{lastname}, "check existence of lastname");
@ -158,12 +158,12 @@ my @allcontacts = ();
# check if it fails without content type
$req->remove_header('Content-Type');
$res = $ua->request($req);
ok($res->code == 415, "check put missing content type");
is($res->code, 415, "check put missing content type");
# check if it fails with unsupported content type
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check put invalid content type");
is($res->code, 415, "check put invalid content type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
@ -171,12 +171,12 @@ my @allcontacts = ();
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
ok($res->code == 400, "check put missing prefer");
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
ok($res->code == 400, "check put invalid prefer");
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
@ -184,12 +184,12 @@ my @allcontacts = ();
# check if it fails with missing body
$res = $ua->request($req);
ok($res->code == 400, "check put no body");
is($res->code, 400, "check put no body");
# check if put is ok
$req->content(JSON::to_json($contact));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
my $new_contact = JSON::from_json($res->decoded_content);
is_deeply($old_contact, $new_contact, "check put if unmodified put returns the same");
@ -198,7 +198,7 @@ my @allcontacts = ();
$contact->{reseller_id} = 1;
$req->content(JSON::to_json($contact));
$res = $ua->request($req);
ok($res->code == 200, "check put successful");
is($res->code, 200, "check put successful");
$new_contact = JSON::from_json($res->decoded_content);
ok(!exists $new_contact->{reseller_id}, "check put if reseller_id is absent");
ok(!exists $new_contact->{_links}->{'ngcp:resellers'}, "check put absence of ngcp:resellers relation");
@ -211,7 +211,7 @@ my @allcontacts = ();
[ { op => 'replace', path => '/firstname', value => 'patchedfirst' } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched contact item");
is($res->code, 200, "check patched contact item");
my $mod_contact = JSON::from_json($res->decoded_content);
ok($mod_contact->{firstname} eq "patchedfirst", "check patched replace op");
@ -219,7 +219,7 @@ my @allcontacts = ();
[ { op => 'replace', path => '/firstname', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 200, "check patched contact item");
is($res->code, 200, "check patched contact item");
$mod_contact = JSON::from_json($res->decoded_content);
ok(exists $mod_contact->{firstname} && !defined $mod_contact->{firstname}, "check patched replace op for undef");
@ -227,7 +227,7 @@ my @allcontacts = ();
[ { op => 'replace', path => '/email', value => undef } ]
));
$res = $ua->request($req);
ok($res->code == 422, "check patched contact with unset email");
is($res->code, 422, "check patched contact with unset email");
}
# DELETE
@ -235,7 +235,7 @@ my @allcontacts = ();
foreach my $contact(@allcontacts) {
$req = HTTP::Request->new('DELETE', $uri.'/'.$contact);
$res = $ua->request($req);
ok($res->code == 204, "check delete of contact");
is($res->code, 204, "check delete of contact");
}
}

@ -25,23 +25,23 @@ $ua->ssl_opts(
$req = HTTP::Request->new('PATCH', $uri.'/api/systemcontacts/1');
$res = $ua->request($req);
ok($res->code == 400, "check patch missing Prefer code");
is($res->code, 400, "check patch missing Prefer code");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /Use the 'Prefer' header/, "check patch missing Prefer response");
$req->header('Prefer' => 'return=minimal');
$res = $ua->request($req);
ok($res->code == 415, "check patch missing media type");
is($res->code, 415, "check patch missing media type");
$req->header('Content-Type' => 'application/xxx');
$res = $ua->request($req);
ok($res->code == 415, "check patch invalid media type");
is($res->code, 415, "check patch invalid media type");
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json-patch+json');
$res = $ua->request($req);
ok($res->code == 400, "check patch missing body");
is($res->code, 400, "check patch missing body");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /is missing a message body/, "check patch missing body response");
@ -49,7 +49,7 @@ $ua->ssl_opts(
{ foo => 'bar' },
));
$res = $ua->request($req);
ok($res->code == 400, "check patch no array body");
is($res->code, 400, "check patch no array body");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /must be an array/, "check patch missing body response");
@ -57,7 +57,7 @@ $ua->ssl_opts(
[{ foo => 'bar' }],
));
$res = $ua->request($req);
ok($res->code == 400, "check patch no op in body");
is($res->code, 400, "check patch no op in body");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /must have an 'op' field/, "check patch no op in body response");
@ -65,7 +65,7 @@ $ua->ssl_opts(
[{ op => 'bar' }],
));
$res = $ua->request($req);
ok($res->code == 400, "check patch invalid op in body");
is($res->code, 400, "check patch invalid op in body");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /Invalid PATCH op /, "check patch no op in body response");
@ -73,7 +73,7 @@ $ua->ssl_opts(
[{ op => 'test' }],
));
$res = $ua->request($req);
ok($res->code == 400, "check patch missing fields for op");
is($res->code, 400, "check patch missing fields for op");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /Missing PATCH keys /, "check patch missing fields for op response");
@ -81,7 +81,7 @@ $ua->ssl_opts(
[{ op => 'test', path => '/foo', value => 'bar', invalid => 'sna' }],
));
$res = $ua->request($req);
ok($res->code == 400, "check patch extra fields for op");
is($res->code, 400, "check patch extra fields for op");
$body = JSON::from_json($res->decoded_content);
ok($body->{message} =~ /Invalid PATCH key /, "check patch extra fields for op response");
}

Loading…
Cancel
Save