TT#7453 Fix fixing removal of r/o fields and tests

It's fine to remove read-only fields only if $run==1, but in any
case remove unknown fields.

Also the force-array change broke additional tests, fixed them.

Change-Id: I48ffcf201bd1eedb8fb317f1ca248af9e4a01e60
changes/53/12353/3
Andreas Granig 9 years ago
parent b3374b6eb4
commit 052e776317

@ -232,13 +232,18 @@ sub validate_fields {
if($resource->{$k}->$_isa('JSON::PP::Boolean')) {
$resource->{$k} = $resource->{$k} ? 1 : 0;
}
unless(exists $fields->{$k}) {
delete $resource->{$k};
next;
}
if($run){
#Prepare resource for the PATCH considering readonly fields.
#PATCH is supposed to take full item content and so will get readonly fields into resource too. And apply patch.
#It leads to the situation when we may try to change some not existing fields in the DB
#All readonly fields are considered as representation only and should never be applied.
if( (!exists $fields->{$k}) || $fields->{$k}->readonly) {
if($fields->{$k}->readonly) {
delete $resource->{$k};
next;
}
}
$resource->{$k} = DateTime::Format::RFC3339->format_datetime($resource->{$k})

@ -23,7 +23,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}->{self}{href} =~ m!subscribers/([0-9]*)$!;
}
cmp_ok ($sub1_id, '>', 0, "should be positive integer");
#----
@ -71,7 +71,7 @@ SKIP:
if ($cust1->{total_count} < 1) {
skip("Precondition not met: need a customer",1);
}
($cust1_id) = $cust1->{_embedded}->{'ngcp:customers'}->{_links}{self}{href} =~ m!customers/([0-9]*)$!;
($cust1_id) = $cust1->{_embedded}->{'ngcp:customers'}->[0]->{_links}{self}{href} =~ m!customers/([0-9]*)$!;
}
cmp_ok ($cust1_id, '>', 0, "should be positive integer");
@ -95,7 +95,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
#$sub1_user = $sub1->{_embedded}->{'ngcp:subscribers'}->{'username'};
#$sub1_pass = $sub1->{_embedded}->{'ngcp:subscribers'}->{'webpassword'} // '';

@ -18,7 +18,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
cmp_ok ($sub1_id, '>', 0, "should be positive integer");

@ -74,7 +74,7 @@ SKIP:
if ($sub1->{total_count} < 1) {
skip("Precondition not met: need a subscriber",1);
}
my ($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
my ($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->[0]->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
cmp_ok ($sub1_id, '>', 0, "should be positive integer");

@ -54,7 +54,7 @@ $req = HTTP::Request->new('GET', $uri.'/api/systemcontacts/?page=1&rows=1');
$res = $ua->request($req);
is($res->code, 200, "fetch system contacts");
my $sysct = JSON::from_json($res->decoded_content);
my $system_contact_id = $sysct->{_embedded}->{'ngcp:systemcontacts'}->{id};
my $system_contact_id = $sysct->{_embedded}->{'ngcp:systemcontacts'}->[0]->{id};
# first, create a contact
$req = HTTP::Request->new('POST', $uri.'/api/customercontacts/');
@ -325,7 +325,11 @@ my @allcustomers = ();
is($res->code, 200, "check put successful");
my $new_customer = JSON::from_json($res->decoded_content);
my $old_modify = delete $old_customer->{modify_timestamp};
my $new_modify = delete $new_customer->{modify_timestamp};
is_deeply($old_customer, $new_customer, "check put if unmodified put returns the same");
$old_customer->{modify_timestamp} = $old_modify;
$new_customer->{modify_timestamp} = $new_modify;
# check if we have the proper links
ok(exists $new_customer->{_links}->{'ngcp:customercontacts'}, "check put presence of ngcp:customercontacts relation");

@ -843,7 +843,13 @@ sub check_embedded {
my($self, $embedded, $check_embedded_cb) = @_;
defined $check_embedded_cb and $check_embedded_cb->($embedded);
foreach my $embedded_name(@{$self->embedded_resources}){
ok(exists $embedded->{_links}->{'ngcp:'.$embedded_name}, "$self->{name}: check presence of ngcp:$embedded_name relation");
if(ref $embedded eq "ARRAY") {
foreach my $emb(@{ $embedded }) {
ok(exists $emb->{_links}->{'ngcp:'.$embedded_name}, "$self->{name}: check presence of ngcp:$embedded_name relation");
}
} else {
ok(exists $embedded->{_links}->{'ngcp:'.$embedded_name}, "$self->{name}: check presence of ngcp:$embedded_name relation");
}
}
}

Loading…
Cancel
Save