App-Dochazka-REST

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

        'Module::Build'  => 0,
    },
    build_requires => {
        'App::CELL'      => 0.215,
        'App::Dochazka::Common'  => 0.205,
        'Authen::Passphrase::SaltedDigest' => 0.008,
        'Date::Holidays::CZ' => 0.12,
        'DBIx::Connector' => 0.47,
        'File::ShareDir::Install' => 0.11,
        'File::Slurp'    => 0,
        'HTTP::Request'  => 0,
        'Mason'          => 0,
        'Plack::Test'    => 0,
        'Test::Fatal'    => 0,
        'Test::JSON'     => 0,
        'Test::Warnings' => 0,
        'Web::Machine'   => 0.15,
        'Web::MREST'     => 0.287,
        'Web::MREST::CLI'     => 0.276,
    },
    requires => {

META.json  view on Meta::CPAN

   "prereqs" : {
      "build" : {
         "requires" : {
            "App::CELL" : "0.215",
            "App::Dochazka::Common" : "0.205",
            "Authen::Passphrase::SaltedDigest" : "0.008",
            "DBIx::Connector" : "0.47",
            "Date::Holidays::CZ" : "0.12",
            "File::ShareDir::Install" : "0.11",
            "File::Slurp" : "0",
            "HTTP::Request" : "0",
            "Mason" : "0",
            "Plack::Test" : "0",
            "Test::Fatal" : "0",
            "Test::JSON" : "0",
            "Test::Warnings" : "0",
            "Web::MREST" : "0.287",
            "Web::MREST::CLI" : "0.276",
            "Web::Machine" : "0.15"
         }
      },

META.yml  view on Meta::CPAN

author:
  - 'Nathan Cutler <ncutler@suse.com>'
build_requires:
  App::CELL: '0.215'
  App::Dochazka::Common: '0.205'
  Authen::Passphrase::SaltedDigest: '0.008'
  DBIx::Connector: '0.47'
  Date::Holidays::CZ: '0.12'
  File::ShareDir::Install: '0.11'
  File::Slurp: '0'
  HTTP::Request: '0'
  Mason: '0'
  Plack::Test: '0'
  Test::Fatal: '0'
  Test::JSON: '0'
  Test::Warnings: '0'
  Web::MREST: '0.287'
  Web::MREST::CLI: '0.276'
  Web::Machine: '0.15'
configure_requires:
  Module::Build: '0'

lib/App/Dochazka/REST/Test.pm  view on Meta::CPAN

use App::Dochazka::REST::Dispatch;
use App::Dochazka::REST::ConnBank qw( $dbix_conn conn_up );
use App::Dochazka::REST::Util qw( hash_the_password );
use App::Dochazka::REST::Model::Activity;
use App::Dochazka::REST::Model::Component;
use App::Dochazka::REST::Model::Privhistory qw( get_privhistory );
use App::Dochazka::REST::Model::Schedhistory qw( get_schedhistory );
use App::Dochazka::REST::Model::Shared qw( cud_generic noof select_single );
use Authen::Passphrase::SaltedDigest;
use Data::Dumper;
use HTTP::Request::Common qw( GET PUT POST DELETE );
use JSON;
use Params::Validate qw( :all );
use Test::JSON;
use Test::More;
use Try::Tiny;
use Web::MREST;



=head1 NAME

lib/App/Dochazka/REST/Test.pm  view on Meta::CPAN




=head1 PACKAGE VARIABLES

=cut

# faux context
our $faux_context;

# dispatch table with references to HTTP::Request::Common functions
my %methods = ( 
    GET => \&GET,
    PUT => \&PUT,
    POST => \&POST,
    DELETE => \&DELETE,
);




t/dispatch/001-resource.t  view on Meta::CPAN

#!perl
use 5.012;
use strict;
use warnings;

#use App::CELL::Test::LogToFile;
use App::CELL qw( $log $meta $site );
use App::CELL::Status;
use App::Dochazka::REST::Test;
use Data::Dumper;
use HTTP::Request::Common qw( GET PUT POST DELETE );
use JSON;
use Plack::Test;
use Scalar::Util qw( blessed );
use Test::Fatal;
use Test::JSON;
use Test::More;
use Test::Warnings;
use Web::MREST::Resource;

note( 'initialize, connect to database, and set up a testing plan' );

t/dispatch/001-resource.t  view on Meta::CPAN

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)' );

t/dispatch/001-resource.t  view on Meta::CPAN

      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 0.409 second using v1.01-cache-2.11-cpan-de7293f3b23 )