App-Dochazka-REST
view release on metacpan or search on metacpan
t/dispatch/001-resource.t view on Meta::CPAN
note( 'instantiate Plack::Test object' );
my $test = Plack::Test->create( $app );
isa_ok( $test, 'Plack::Test::MockHTTP' );
my ( $res, $json );
note( 'the very basic-est request (200)' );
req( $test, 200, 'demo', 'GET', '/' );
note( 'a too-long request (414)' );
req( $test, 414, 'demo', 'GET', '/' x 1001 );
note( 'request for HTML' );
my $r = GET '/', 'Accept' => 'text/html';
isa_ok( $r, 'HTTP::Request' );
$r->authorization_basic( 'root', 'immutable' );
my $resp = $test->request( $r );
isa_ok( $resp, 'HTTP::Response' );
is( $resp->code, 200 );
like( $resp->content, qr/<html>/ );
note( 'request with bad credentials (401)' );
req( $test, 401, 'fandango', 'GET', '/' );
note( 'request that doesn\'t pass ACL check (403)' );
req( $test, 403, 'demo', 'GET', '/forbidden' );
note( 'GET request for non-existent resource (400)' );
req( $test, 400, 'demo', 'GET', '/HEE HAW!!!/non-existent/resource' );
note( 'PUT request for non-existent resource (400)' );
req( $test, 400, 'demo', 'PUT', '/HEE HAW!!!/non-existent/resource' );
note( 'POST request for non-existent resource (400)' );
req( $test, 400, 'demo', 'POST', '/HEE HAW!!!/non-existent/resource' );
note( 'DELETE request on non-existent resource (400)' );
req( $test, 400, 'demo', 'DELETE', '/HEE HAW!!!/non-existent/resource' );
note( 'test argument validation in \'push_onto_context\' method' );
like( exception { Web::MREST::Resource::push_onto_context( undef, 'DUMMY2' ); },
qr/not one of the allowed types: hashref/ );
like( exception { Web::MREST::Resource::push_onto_context( undef, {}, ( 3..12 ) ); },
qr/but 1 was expected/ );
like( exception { Web::MREST::Resource::push_onto_context(); },
qr/0 parameters were passed.+but 1 was expected/ );
note( 'test if we can get the context' );
my $resource_self = bless {}, 'Web::MREST::Resource';
is_deeply( $resource_self->context, {} );
$resource_self->context( { 'bubba' => 'BAAAA' } );
is( $resource_self->context->{'bubba'}, 'BAAAA' );
note( 'test if the \'no_cache\' headers are present in each response' );
$r = GET '/', 'Accept' => 'application/json', 'Content_Type' => 'application/json';
isa_ok( $r, 'HTTP::Request' );
$r->authorization_basic( 'root', 'immutable' );
$resp = $test->request( $r );
isa_ok( $resp, 'HTTP::Response' );
is( $resp->header( 'Cache-Control' ), 'no-cache, no-store, must-revalidate, private' );
is( $resp->header( 'Pragma' ), 'no-cache' );
done_testing;
( run in 1.769 second using v1.01-cache-2.11-cpan-df04353d9ac )