Changeset 12106


Ignore:
Timestamp:
07/29/10 16:44:38 (19 months ago)
Author:
adamk
Message:

Bits and pieces

Location:
trunk/Madre-Sync
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Madre-Sync/Makefile.PL

    r12080 r12106  
    33name          'Madre-Sync'; 
    44all_from      'lib/Madre/Sync.pm'; 
     5requires      'JSON::XS'          => '2.29'; 
    56requires      'Catalyst::Runtime' => '5.80018'; 
    67requires      'Catalyst::Plugin::ConfigLoader'; 
  • trunk/Madre-Sync/lib/Madre/Sync/Controller/Conf.pm

    r12100 r12106  
    1818use Moose; 
    1919use namespace::autoclean; 
     20use JSON::XS (); 
    2021 
    2122BEGIN { 
    2223    extends 'Catalyst::Controller::REST'; 
    2324} 
    24  
    25 use JSON::Any; 
    2625 
    2726=pod 
     
    5554    $self->status_ok( 
    5655        $c, 
    57         entity => JSON::Any->jsonToObj($config), 
     56        entity => JSON::XS->new->decode($config), 
    5857    ); 
    5958} 
     
    7776            $c->model('padreDB::Config')->update_or_create( { 
    7877                id     => $c->user->id, 
    79                 config => JSON::Any->objToJson($data), 
     78                config => JSON::XS->new->encode($data), 
    8079            } ) 
    8180        }; 
  • trunk/Madre-Sync/lib/Madre/Sync/Controller/User.pm

    r12103 r12106  
    4949    my $data     = $c->request->data; 
    5050 
    51     if ( $c->user_exists ) {  
     51    if ( $c->user_exists ) { 
    5252        $self->status_bad_request( 
    5353            $c,  
  • trunk/Madre-Sync/t/02_requests.t

    r12104 r12106  
    66    $^W = 1; 
    77} 
    8 use Test::More tests => 7; 
     8use Test::More tests => 9; 
    99 
    1010use_ok( 'Catalyst::Test', 'Madre::Sync' ); 
     
    1313use_ok( 'Madre::Sync::Controller::Conf' ); 
    1414 
    15 ok( request('/')->is_success,       'Request should succeed' ); 
    16 ok( request('/user')->is_success,   'Request should succeed' ); 
    17 ok( request('/config')->is_success, 'Request should succeed' ); 
     15ok( request('/')->is_success,             'Request should succeed' ); 
     16ok( request('/bad')->code == 404,         'Request should fail with 404' ); 
     17ok( request('/login')->is_success,        'Request should succeed' ); 
     18ok( request('/user')->code == 415,        'Request should bounce to login page with 415' ); 
     19ok( request('/user/config')->code == 415, 'Request should bounce to login page with 415' ); 
  • trunk/Madre-Sync/t/03_rest.t

    r12105 r12106  
    1414} 
    1515 
    16 use LWP::UserAgent; 
    17 use HTTP::Cookies; 
     16use URI            (); 
     17use JSON::XS       (); 
     18use HTTP::Cookies  (); 
     19use LWP::UserAgent (); 
    1820use HTTP::Request::Common qw/GET POST PUT DELETE/; 
    19 use JSON::Any; 
    20 use URI; 
    2121 
    22 # set up browser and serializer 
    23 my $j = JSON::Any->new; 
    24 my $ua = LWP::UserAgent->new; 
    25  
     22# Set up browser and serializer 
     23my $json = JSON::XS->new; 
     24my $ua   = LWP::UserAgent->new; 
    2625push @{ $ua->requests_redirectable }, 'POST'; 
    27  
    28  
    29 my $cookie_jar = HTTP::Cookies->new( 
    30    file => "$ENV{'HOME'}/lwp_cookies.dat", 
    31    autosave => 1, 
     26$ua->timeout(5); 
     27$ua->cookie_jar( 
     28    HTTP::Cookies->new( 
     29        file     => "t/lwp_cookies.dat", 
     30        autosave => 1, 
     31    ) 
    3232); 
    3333 
    34 $ua->cookie_jar($cookie_jar); 
    35  
    36 # create account 
    37  
     34# Create account 
    3835my $req_data = {  
    39    username => "test_account",  
    40    password => "abcdefg",  
    41    email    => 'test@abcd.com'  
     36    username => "test_account",  
     37    password => "abcdefg",  
     38    email    => 'test@abcd.com'  
    4239}; 
    4340 
    44 #diag 'Add a user'; 
     41diag 'Add a user'; 
    4542my $resp = $ua->request( 
    4643    PUT 'http://localhost:3000/register', 
    4744    'Content-Type' => 'application/json', 
    48     'Content'      => $j->objToJson($req_data), 
     45    'Content'      => $json->objToJson($req_data), 
    4946); 
    5047is( $resp->code, 200, "Account creation" ); 
    5148 
    52 #diag $resp->status_line; 
    53 #diag $resp->content; 
    54 #diag $resp->status_line; 
    55  
    56 #diag 'login using above created account'; 
     49diag $resp->status_line; 
     50diag $resp->content; 
     51diag $resp->status_line; 
     52diag 'login using above created account'; 
    5753$resp = $ua->request( 
    5854    POST 'http://localhost:3000/login', 
     
    6561is( $resp->code, 200, "Login" ); 
    6662 
    67 # test uniqueness reregistration 
     63diag 'Test uniqueness reregistration'; 
    6864$resp = $ua->request( 
    6965    PUT 'http://localhost:3000/register', 
    7066    'Content-Type' => 'application/json', 
    71     'Content'      => $j->objToJson($req_data), 
     67    'Content'      => $json->objToJson($req_data), 
    7268); 
    7369is( $resp->code, 400, "Account creation reattempt with used email / name" ); 
    7470 
    75 # test updating information  
     71diag 'Test updating information'; 
    7672$resp = $ua->request( 
    7773    POST 'http://localhost:3000/user', 
    7874    'Content-Type' => 'application/json', 
    79     'Content'      => $j->objToJson( { 
     75    'Content'      => $json->objToJson( { 
    8076        email    => 'bademial.ean', 
    8177        password => 'qwerty', 
     
    8783    POST 'http://localhost:3000/user', 
    8884    'Content-Type' => 'application/json', 
    89     'Content'      => $j->objToJson( { 
     85    'Content'      => $json->objToJson( { 
    9086        email    => 'goodemail@yes.com', 
    9187        password => 'qwerty', 
     
    9490is( $resp->code, 200, "Account modification with valid email address" ); 
    9591 
    96 #test post of config  
     92diag 'Test post of config'; 
    9793$resp = $ua->request( 
    9894    POST 'http://localhost:3000/user/config', 
    9995    'Content-Type' => 'application/json', 
    100     'Content'      => $j->objToJson( { 
     96    'Content'      => $json->objToJson( { 
    10197        config => { test => 'goodemail@yes.com', password => 'qwerty' } 
    10298    } ) 
     
    104100is( $resp->code, 200, "Config submission" ); 
    105101 
    106 # test get of config 
     102diag 'Test get of config'; 
    107103$resp = $ua->request( 
    108104    GET 'http://localhost:3000/user/config', 
     
    110106); 
    111107 
    112 #$resp = $ua->request( GET , 'Content-Type' => 'application/json', Content => $j->objToJson( { email => 'goodemail@yes.com', password => 'qwerty' } ) ); 
     108#$resp = $ua->request( GET , 'Content-Type' => 'application/json', Content => $json->objToJson( { email => 'goodemail@yes.com', password => 'qwerty' } ) ); 
    113109#$resp =$ua->request( GET 'http://localhost:3000/user/config', 'Content-Type' => 'application/json' ); 
    114110#use Data::Dumper; 
     
    116112#diag $resp->content; 
    117113 
    118 # test deletion 
     114diag 'Test deletion'; 
    119115$resp = $ua->request( DELETE 'http://localhost:3000/user' ); 
    120 is( $resp->code, 200, "Deletion"); 
     116is( $resp->code, 200, "Deletion" ); 
Note: See TracChangeset for help on using the changeset viewer.