MT#5255 API: Create roles for resources.

Collections and Items have common functions (e.g. hal_from_xxx),
so move them into separate roles.
agranig/rest
Andreas Granig 12 years ago
parent 458852f70e
commit 7a782eb4fb

@ -7,9 +7,10 @@ use Data::HAL::Link qw();
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use MooseX::ClassAttribute qw(class_has);
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Form::Contract::PeeringReseller qw();
use Path::Tiny qw(path);
use Safe::Isa qw($_isa);
BEGIN { extends 'Catalyst::Controller::ActionRole'; }
require Catalyst::ActionRole::ACL;
require Catalyst::ActionRole::CheckTrailingSlash;
@ -17,6 +18,7 @@ require Catalyst::ActionRole::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
with 'NGCP::Panel::Role::API';
with 'NGCP::Panel::Role::API::Contracts';
class_has('resource_name', is => 'ro', default => 'contracts');
class_has('dispatch_path', is => 'ro', default => '/api/contracts/');
@ -48,11 +50,15 @@ sub GET :Allow {
my $page = $c->request->params->{page} // 1;
my $rows = $c->request->params->{rows} // 10;
{
my $contracts = $c->model('DB')->resultset('contracts')
->search({
my $contracts = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'),
);
$contracts = $contracts->search({
'contact.reseller_id' => undef
},{
join => 'contact'
join => 'contact',
'+select' => 'billing_mappings.id',
'+as' => 'bmid',
});
my $total_count = int($contracts->count);
$contracts = $contracts->search(undef, {
@ -61,7 +67,7 @@ sub GET :Allow {
});
my (@embedded, @links);
my $form = NGCP::Panel::Form::Contract::PeeringReseller->new;
for my $contract ($contracts->search({}, {order_by => {-asc => 'me.id'}, prefetch => ['contact']})->all) {
for my $contract ($contracts->all) {
push @embedded, $self->hal_from_contract($c, $contract, $form);
push @links, Data::HAL::Link->new(
relation => 'ngcp:'.$self->resource_name,
@ -131,12 +137,14 @@ sub POST :Allow {
my $guard = $c->model('DB')->txn_scope_guard;
{
my $schema = $c->model('DB');
my $resource = $self->get_valid_post_data(
c => $c,
media_type => 'application/json',
);
last unless $resource;
my $product_class = delete $resource->{type};
my $form = NGCP::Panel::Form::Contract::PeeringReseller->new;
last unless $self->validate_form(
c => $c,
@ -144,15 +152,37 @@ sub POST :Allow {
form => $form,
);
my $now = DateTime->now;
my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{create_timestamp} = $now;
$resource->{modify_timestamp} = $now;
my $contract;
try {
$contract = $c->model('DB')->resultset('contracts')->create($resource);
my $billing_profile_id = delete $resource->{billing_profile_id};
my $billing_profile = $schema->resultset('billing_profiles')->find($billing_profile_id);
unless($billing_profile) {
$self->error($c, HTTP_NOT_FOUND, "Invalid 'billing_profile_id'.");
last;
}
my $product = $schema->resultset('products')->find({ class => $product_class });
unless($product) {
$self->error($c, HTTP_NOT_FOUND, "Invalid 'type'.");
last;
}
$contract = $schema->resultset('contracts')->create($resource);
if($contract->contact->reseller_id) {
$self->error($c, HTTP_NOT_FOUND, "The contact_id is not a valid ngcp:systemcontacts item, but an ngcp:customercontacts item");
last;
}
$contract->billing_mappings->create({
billing_profile_id => $billing_profile->id,
product_id => $product->id,
});
NGCP::Panel::Utils::Contract::create_contract_balance(
c => $c,
profile => $billing_profile,
contract => $contract,
);
# TODO: billing_mappings, contract_balances, ...
# TODO: product (sippeering or reseller)
} catch($e) {
$c->log->error("failed to create contract: $e"); # TODO: user, message, trace, ...
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create contract.");
@ -168,44 +198,6 @@ sub POST :Allow {
return;
}
sub hal_from_contract : Private {
my ($self, $c, $contract, $form) = @_;
# TODO: fixxxxxxme
my $billing_profile_id = 1;
my $contract_balance_id = 1;
my %resource = $contract->get_inflated_columns;
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf('/%s', $c->request->path)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("/%s%d", $c->request->path, $contract->id)),
Data::HAL::Link->new(relation => 'ngcp:systemcontacts', href => sprintf("/api/systemcontacts/%d", $contract->contact->id)),
Data::HAL::Link->new(relation => 'ngcp:billingprofiles', href => sprintf("/api/billingprofiles/%d", $billing_profile_id)),
Data::HAL::Link->new(relation => 'ngcp:contractbalances', href => sprintf("/api/contractbalances/%d", $contract_balance_id)),
],
relation => 'ngcp:'.$self->resource_name,
);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$hal->resource({%resource});
return $hal;
}
sub end : Private {
my ($self, $c) = @_;

@ -9,6 +9,7 @@ use HTTP::Status qw(:constants);
use MooseX::ClassAttribute qw(class_has);
use NGCP::Panel::Form::Contract::PeeringReseller qw();
use NGCP::Panel::Utils::ValidateJSON qw();
use NGCP::Panel::Utils::DateTime;
use Path::Tiny qw(path);
use Safe::Isa qw($_isa);
BEGIN { extends 'Catalyst::Controller::ActionRole'; }
@ -17,6 +18,7 @@ require Catalyst::ActionRole::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
with 'NGCP::Panel::Role::API';
with 'NGCP::Panel::Role::API::Contracts';
class_has('resource_name', is => 'ro', default => 'contracts');
class_has('dispatch_path', is => 'ro', default => '/api/contracts/');
@ -50,8 +52,7 @@ sub GET :Allow {
my $contract = $self->contract_by_id($c, $id);
last unless $self->resource_exists($c, contract => $contract);
my $form = NGCP::Panel::Form::Contract::PeeringReseller->new;
my $hal = $self->hal_from_contract($c, $contract, $form);
my $hal = $self->hal_from_contract($c, $contract);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
(map { # XXX Data::HAL must be able to generate links with multiple relations
@ -92,6 +93,7 @@ sub PATCH :Allow {
{
my $preference = $self->require_preference($c);
last unless $preference;
my $json = $self->get_valid_patch_data(
c => $c,
id => $id,
@ -101,8 +103,10 @@ sub PATCH :Allow {
my $contract = $self->contract_by_id($c, $id);
last unless $self->resource_exists($c, contract => $contract);
my $resource = { $contract->get_inflated_columns };
$resource = $self->apply_patch($c, $resource, $json);
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
my $old_resource = { $contract->get_inflated_columns };
$old_resource->{billing_profile_id} = $billing_mapping->billing_profile_id;
my $resource = $self->apply_patch($c, $old_resource, $json);
last unless $resource;
my $form = NGCP::Panel::Form::Contract::PeeringReseller->new;
@ -112,11 +116,22 @@ sub PATCH :Allow {
resource => $resource
);
$resource->{modify_timestamp} = DateTime->now;
my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{modify_timestamp} = $now;
if($old_resource->{billing_profile_id} != $resource->{billing_profile_id}) {
my $billing_profile = $c->model('DB')->resultset('billing_profiles')->find($resource->{billing_profile_id});
unless($billing_profile) {
$self->error($c, HTTP_NOT_FOUND, "Invalid 'billing_profile_id'");
last;
}
$billing_mapping->update({
billing_profile_id => $resource->{billing_profile_id}
});
}
delete $resource->{billing_profile_id};
$contract->update($resource);
# TODO: what about changed product, billing-profile etc?
# TODO: guess we need to update billing-mappings also
# TODO: what about changed product, do we allow it?
# TODO: handle termination, ....
$guard->commit;
@ -126,7 +141,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_contract($c, $contract);
my $hal = $self->hal_from_contract($c, $contract, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -142,29 +157,43 @@ sub PUT :Allow {
my ($self, $c, $id) = @_;
my $guard = $c->model('DB')->txn_scope_guard;
{
my $preference = $self->require_preference($c);
last unless $preference;
my $contract = $self->contract_by_id($c, $id);
last unless $self->resource_exists($c, contract => $contract);
my $resource = $self->get_valid_put_data(
c => $c,
id => $id,
media_type => 'application/json',
);
last unless $resource;
my $preference = $self->require_preference($c);
last unless $preference;
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
my $old_resource = { $contract->get_inflated_columns };
$old_resource->{billing_profile_id} = $billing_mapping->billing_profile_id;
my $form = NGCP::Panel::Form::Contract::PeeringReseller->new;
last unless $self->validate_form(
c => $c,
resource => $resource,
form => $form,
resource => $resource
);
$resource->{modify_timestamp} = DateTime->now;
my $contract = $self->contract_by_id($c, $id);
my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{modify_timestamp} = $now;
if($old_resource->{billing_profile_id} != $resource->{billing_profile_id}) {
my $billing_profile = $c->model('DB')->resultset('billing_profiles')->find($resource->{billing_profile_id});
unless($billing_profile) {
$self->error($c, HTTP_NOT_FOUND, "Invalid 'billing_profile_id'");
last;
}
$billing_mapping->update({
billing_profile_id => $resource->{billing_profile_id}
});
}
delete $resource->{billing_profile_id};
$contract->update($resource);
# TODO: again, billing-mappings etc
# TODO: handle termination, ....
# TODO: what about changed product, do we allow it?
# TODO: handle termination, ....
$guard->commit;
@ -186,6 +215,8 @@ sub PUT :Allow {
return;
}
=pod
# we don't allow to delete contracts
sub DELETE :Allow {
my ($self, $c, $id) = @_;
my $guard = $c->model('DB')->txn_scope_guard;
@ -210,61 +241,7 @@ sub DELETE :Allow {
}
return;
}
sub contract_by_id : Private {
my ($self, $c, $id) = @_;
# we only return system contracts, that is, those with contacts without
# reseller
my $contract_rs = $c->model('DB')->resultset('contracts')
->search({
'contact.reseller_id' => undef
}, {
join => 'contact'
});
return $contract_rs->find({'me.id' => $id});
}
sub hal_from_contract : Private {
my ($self, $c, $contract) = @_;
my %resource = $contract->get_inflated_columns;
my $id = $resource{id};
# TODO: fixxxxxx
my $billing_profile_id = 1;
my $contract_balance_id = 1;
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf("/api/%s/", $self->resource_name)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("/%s", $c->request->path)),
Data::HAL::Link->new(relation => 'ngcp:billingprofiles', href => sprintf("/api/billingprofiles/%d", $billing_profile_id)),
Data::HAL::Link->new(relation => 'ngcp:contractbalances', href => sprintf("/api/contractbalances/%d", $contract_balance_id)),
],
relation => 'ngcp:'.$self->resource_name,
);
# TODO: add billing_profile_id, contract_balance_id etc to
# %resource as well
my $form = NGCP::Panel::Form::Contract::PeeringReseller->new;
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$hal->resource({%resource});
return $hal;
}
=cut
sub end : Private {
my ($self, $c) = @_;

@ -18,6 +18,7 @@ require Catalyst::ActionRole::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
with 'NGCP::Panel::Role::API';
with 'NGCP::Panel::Role::API::SystemContacts';
class_has('resource_name', is => 'ro', default => 'systemcontacts');
class_has('dispatch_path', is => 'ro', default => '/api/systemcontacts/');
@ -158,37 +159,6 @@ sub POST :Allow {
return;
}
sub hal_from_contact : Private {
my ($self, $c, $contact, $form) = @_;
my %resource = $contact->get_inflated_columns;
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf('/%s', $c->request->path)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("/%s%d", $c->request->path, $contact->id)),
],
relation => 'ngcp:'.$self->resource_name,
);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$hal->resource({%resource});
return $hal;
}
sub end : Private {
my ($self, $c) = @_;

@ -1,9 +1,6 @@
package NGCP::Panel::Controller::API::SystemContactsItem;
use Sipwise::Base;
use namespace::sweep;
use boolean qw(true);
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use MooseX::ClassAttribute qw(class_has);
@ -18,6 +15,7 @@ require Catalyst::ActionRole::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
with 'NGCP::Panel::Role::API';
with 'NGCP::Panel::Role::API::SystemContacts';
class_has('resource_name', is => 'ro', default => 'systemcontacts');
class_has('dispatch_path', is => 'ro', default => '/api/systemcontacts/');
@ -51,8 +49,7 @@ sub GET :Allow {
my $contact = $self->contact_by_id($c, $id);
last unless $self->resource_exists($c, systemcontact => $contact);
my $form = NGCP::Panel::Form::Contact::Reseller->new;
my $hal = $self->hal_from_contact($c, $contact, $form);
my $hal = $self->hal_from_contact($c, $contact);
# TODO: we don't need reseller stuff here!
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
@ -124,7 +121,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_contact($c, $contact);
my $hal = $self->hal_from_contact($c, $contact, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -202,47 +199,6 @@ sub DELETE :Allow {
return;
}
sub contact_by_id : Private {
my ($self, $c, $id) = @_;
# we only return system contacts, that is, a contact without reseller
my $contact_rs = $c->model('DB')->resultset('contacts')
->search({ reseller_id => undef });
return $contact_rs->find({'me.id' => $id});
}
sub hal_from_contact : Private {
my ($self, $c, $contact) = @_;
my %resource = $contact->get_inflated_columns;
my $id = $resource{id};
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf("/api/%s/", $self->resource_name)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("/%s", $c->request->path)),
],
relation => 'ngcp:'.$self->resource_name,
);
my $form = NGCP::Panel::Form::Contact::Reseller->new;
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$hal->resource({%resource});
return $hal;
}
sub end : Private {
my ($self, $c) = @_;

@ -41,7 +41,6 @@ sub get_valid_put_data {
return unless $self->valid_id($c, $id);
return unless $self->forbid_link_header($c);
return unless $self->valid_media_type($c, $media_type);
return unless $self->require_precondition($c, 'If-Match');
return unless $self->require_body($c);
my $json = $c->stash->{body};
return unless $self->require_wellformed_json($c, $media_type, $json);
@ -79,7 +78,7 @@ sub validate_form {
# move {xxx_id} into {xxx}{id} for FormHandler
foreach my $key(keys %{ $resource } ) {
if($key =~ /^([a-z]+)_id$/) {
if($key =~ /^(.+)_id$/ && $key ne "external_id") {
$c->log->debug("++++++++++++ moving key $key with value " . ($resource->{$key} // '<null>') . " to $1/id");
push @normalized, $1;
$resource->{$1}{id} = delete $resource->{$key};
@ -356,7 +355,7 @@ sub log_request {
}
$c->log->info("API function '".$c->request->path."' called by '" . $user .
"' ('" . $c->user->roles . "') from host '".$c->request->address."' with params " .
"' ('" . $c->user->roles . "') from host '".$c->request->address."' with method '" . $c->request->method . "' and params " .
(length $params ? $params : "''") .
" and body '" . $c->stash->{body} . "'");
}

@ -0,0 +1,98 @@
package NGCP::Panel::Role::API::Contracts;
use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Form::Contract::PeeringReseller qw();
sub hal_from_contract {
my ($self, $c, $contract, $form) = @_;
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
my $billing_profile_id = $billing_mapping->billing_profile->id;
my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1);
my $contract_balance = $contract->contract_balances
->find({
start => { '>=' => $stime },
end => { '<' => $etime },
});
unless($contract_balance) {
try {
NGCP::Panel::Utils::Contract::create_contract_balance(
c => $c,
profile => $billing_mapping->billing_profile,
contract => $contract,
);
} catch {
$self->log->error("Failed to create current contract balance for contract id '".$contract->id."': $_");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error.");
}
$contract_balance = $contract->contract_balances->find({
start => { '>=' => $stime },
end => { '<' => $etime },
});
}
my %resource = $contract->get_inflated_columns;
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf('/%s', $c->request->path)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("/%s%d", $c->request->path, $contract->id)),
Data::HAL::Link->new(relation => 'ngcp:systemcontacts', href => sprintf("/api/systemcontacts/%d", $contract->contact->id)),
Data::HAL::Link->new(relation => 'ngcp:billingprofiles', href => sprintf("/api/billingprofiles/%d", $billing_profile_id)),
Data::HAL::Link->new(relation => 'ngcp:contractbalances', href => sprintf("/api/contractbalances/%d", $contract_balance->id)),
],
relation => 'ngcp:'.$self->resource_name,
);
$form //= NGCP::Panel::Form::Contract::PeeringReseller->new;
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$resource{id} = int($contract->id);
$resource{type} = $billing_mapping->product->class;
$resource{billing_profile_id} = int($billing_profile_id);
$hal->resource({%resource});
return $hal;
}
sub contract_by_id {
my ($self, $c, $id) = @_;
# we only return system contracts, that is, those with contacts without
# reseller
my $contracts = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'),
);
$contracts = $contracts->search({
'contact.reseller_id' => undef
},{
join => 'contact',
'+select' => 'billing_mappings.id',
'+as' => 'bmid',
});
return $contracts->find({'me.id' => $id});
}
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,54 @@
package NGCP::Panel::Role::API::SystemContacts;
use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Form::Contact::Reseller;
sub hal_from_contact {
my ($self, $c, $contact, $form) = @_;
my %resource = $contact->get_inflated_columns;
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
Data::HAL::Link->new(relation => 'collection', href => sprintf("/api/%s/", $self->resource_name)),
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("/%s", $c->request->path)),
],
relation => 'ngcp:'.$self->resource_name,
);
$form //= NGCP::Panel::Form::Contact::Reseller->new;
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$resource{id} = int($contact->id);
$hal->resource({%resource});
return $hal;
}
sub contact_by_id {
my ($self, $c, $id) = @_;
# we only return system contacts, that is, a contact without reseller
my $contact_rs = $c->model('DB')->resultset('contacts')
->search({ reseller_id => undef });
return $contact_rs->find({'me.id' => $id});
}
1;
# vim: set tabstop=4 expandtab:

@ -1,9 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"required": ["external_id", "status"],
"description": "A billing container for a reseller or peering",
"required": ["external_id", "status", "type", "billing_profile_id", "contact_id"],
"properties": {
"external_id": { "type": ["null", "string"], "description": "XXX" },
"status": { "enum": [null, "active", "locked", "pending", "terminated"], "description": "XXX" }
"status": { "enum": ["active", "locked", "pending", "terminated"], "description": "The operational status of the contract" }
"type": { "enum": ["reseller", "sippeering"], "description": "The type of the contract" }
"contact_id": { "type": "number", "description": "The ID of the 'ngcp:systemcontacts' item this contract belongs to" },
"billing_profile_id": { "type": "number", "description": "The ID of the 'ngcp:billingprofiles' item this contract uses" },
"external_id": { "type": ["null", "string"], "description": "An external ID e.g. to identify the contract in a 3rd party system" },
},
"title": "contract",
"type": "object"

@ -145,6 +145,7 @@ my @allcontacts = ();
ok(exists $contact->{firstname}, "check existence of firstname");
ok(exists $contact->{lastname}, "check existence of lastname");
ok(exists $contact->{email}, "check existence of email");
ok(exists $contact->{id} && $contact->{id}->is_int, "check existence of id");
ok(!exists $contact->{reseller_id}, "check absence of reseller_id");
# PUT same result again
@ -153,13 +154,6 @@ my @allcontacts = ();
delete $contact->{_embedded};
$req = HTTP::Request->new('PUT', $uri.'/'.$firstcontact);
# check if it fails without If-Match
$req->header('Content-Type' => 'application/json');
$res = $ua->request($req);
ok($res->code == 428, "check put precondition-required");
$req->header('If-Match' => '*');
# check if it fails without content type
$req->remove_header('Content-Type');
$res = $ua->request($req);

Loading…
Cancel
Save