MT#6295 API: fix tests Prefer header no longer required

agranig/selfsignup
Gerhard Jungwirth 11 years ago
parent 63aa4e35f7
commit edd904ce45

@ -100,10 +100,10 @@ sub validate_form {
if $resource->{$k}->$_isa('DateTime');
$resource->{$k} = $resource->{$k} + 0
if(defined $resource->{$k} && (
$resource->{$k}->is_int || $resource->{$k}->is_decimal) && (
$form->field($k)->$_isa('HTML::FormHandler::Field::Integer') ||
$form->field($k)->$_isa('HTML::FormHandler::Field::Money') ||
$form->field($k)->$_isa('HTML::FormHandler::Field::Float')));
$form->field($k)->$_isa('HTML::FormHandler::Field::Float')) &&
($resource->{$k}->is_int || $resource->{$k}->is_decimal));
# only do this for converting back from obj to hal
# otherwise it breaks db fields with the \0 and \1 notation
@ -192,10 +192,11 @@ sub valid_precondition {
sub require_preference {
my ($self, $c) = @_;
return 'minimal' unless $c->request->header('Prefer');
my @preference = grep { 'return' eq $_->[0] } split_header_words($c->request->header('Prefer'));
return $preference[0][1]
if 1 == @preference && ('minimal' eq $preference[0][1] || 'representation' eq $preference[0][1]);
return 'minimal';
$self->error($c, HTTP_BAD_REQUEST, "Header 'Prefer' must be either 'return=minimal' or 'return=representation'.");
}
sub require_wellformed_json {

@ -351,7 +351,7 @@ my @allfees = ();
delete $fee->{_links};
delete $fee->{_embedded};
$req = HTTP::Request->new('PUT', $uri.'/'.$firstfee);
# check if it fails without content type
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
@ -366,17 +366,11 @@ my @allfees = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
$req->header('Prefer' => "return=representation");

@ -205,11 +205,6 @@ my @allprofiles = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);

@ -271,17 +271,11 @@ my @allcontracts = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
$req->header('Prefer' => "return=representation");

@ -207,11 +207,6 @@ my @allcontacts = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);

@ -305,17 +305,11 @@ my @allcustomers = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
$req->header('Prefer' => "return=representation");

@ -279,7 +279,7 @@ my @allresellers = ();
delete $reseller->{_links};
delete $reseller->{_embedded};
$req = HTTP::Request->new('PUT', $uri.'/'.$firstreseller);
# check if it fails without content type
$req->remove_header('Content-Type');
$req->header('Prefer' => "return=minimal");
@ -294,11 +294,6 @@ my @allresellers = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);

@ -304,17 +304,11 @@ my @allrules = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
$req->header('Prefer' => "return=representation");

@ -154,7 +154,7 @@ my @allcontacts = ();
delete $contact->{_embedded};
$req = HTTP::Request->new('PUT', $uri.'/'.$firstcontact);
$req->header('Prefer' => 'return=minimal');
# check if it fails without content type
$req->remove_header('Content-Type');
$res = $ua->request($req);
@ -168,17 +168,11 @@ my @allcontacts = ();
$req->remove_header('Content-Type');
$req->header('Content-Type' => 'application/json');
# check if it fails with missing Prefer
$req->remove_header('Prefer');
$res = $ua->request($req);
is($res->code, 400, "check put missing prefer");
# check if it fails with invalid Prefer
$req->header('Prefer' => "return=invalid");
$res = $ua->request($req);
is($res->code, 400, "check put invalid prefer");
$req->remove_header('Prefer');
$req->header('Prefer' => "return=representation");

@ -24,11 +24,6 @@ $ua->ssl_opts(
{
$req = HTTP::Request->new('PATCH', $uri.'/api/systemcontacts/1');
$res = $ua->request($req);
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);
is($res->code, 415, "check patch missing media type");
@ -43,7 +38,7 @@ $ua->ssl_opts(
$res = $ua->request($req);
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");
like($body->{message}, qr/is missing a message body/, "check patch missing body response");
$req->content(JSON::to_json(
{ foo => 'bar' },
@ -51,7 +46,7 @@ $ua->ssl_opts(
$res = $ua->request($req);
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");
like($body->{message}, qr/must be an array/, "check patch missing body response");
$req->content(JSON::to_json(
[{ foo => 'bar' }],
@ -59,7 +54,7 @@ $ua->ssl_opts(
$res = $ua->request($req);
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");
like($body->{message}, qr/must have an 'op' field/, "check patch no op in body response");
$req->content(JSON::to_json(
[{ op => 'bar' }],
@ -67,23 +62,23 @@ $ua->ssl_opts(
$res = $ua->request($req);
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");
like($body->{message}, qr/Invalid PATCH op /, "check patch no op in body response");
$req->content(JSON::to_json(
[{ op => 'test' }],
[{ op => 'replace' }],
));
$res = $ua->request($req);
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");
like($body->{message}, qr/Missing PATCH keys /, "check patch missing fields for op response");
$req->content(JSON::to_json(
[{ op => 'test', path => '/foo', value => 'bar', invalid => 'sna' }],
[{ op => 'replace', path => '/foo', value => 'bar', invalid => 'sna' }],
));
$res = $ua->request($req);
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");
like($body->{message}, qr/Invalid PATCH key /, "check patch extra fields for op response");
}
done_testing;

Loading…
Cancel
Save