Changeset 12106
- Timestamp:
- 07/29/10 16:44:38 (19 months ago)
- Location:
- trunk/Madre-Sync
- Files:
-
- 5 edited
-
Makefile.PL (modified) (1 diff)
-
lib/Madre/Sync/Controller/Conf.pm (modified) (3 diffs)
-
lib/Madre/Sync/Controller/User.pm (modified) (1 diff)
-
t/02_requests.t (modified) (2 diffs)
-
t/03_rest.t (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Madre-Sync/Makefile.PL
r12080 r12106 3 3 name 'Madre-Sync'; 4 4 all_from 'lib/Madre/Sync.pm'; 5 requires 'JSON::XS' => '2.29'; 5 6 requires 'Catalyst::Runtime' => '5.80018'; 6 7 requires 'Catalyst::Plugin::ConfigLoader'; -
trunk/Madre-Sync/lib/Madre/Sync/Controller/Conf.pm
r12100 r12106 18 18 use Moose; 19 19 use namespace::autoclean; 20 use JSON::XS (); 20 21 21 22 BEGIN { 22 23 extends 'Catalyst::Controller::REST'; 23 24 } 24 25 use JSON::Any;26 25 27 26 =pod … … 55 54 $self->status_ok( 56 55 $c, 57 entity => JSON:: Any->jsonToObj($config),56 entity => JSON::XS->new->decode($config), 58 57 ); 59 58 } … … 77 76 $c->model('padreDB::Config')->update_or_create( { 78 77 id => $c->user->id, 79 config => JSON:: Any->objToJson($data),78 config => JSON::XS->new->encode($data), 80 79 } ) 81 80 }; -
trunk/Madre-Sync/lib/Madre/Sync/Controller/User.pm
r12103 r12106 49 49 my $data = $c->request->data; 50 50 51 if ( $c->user_exists ) { 51 if ( $c->user_exists ) { 52 52 $self->status_bad_request( 53 53 $c, -
trunk/Madre-Sync/t/02_requests.t
r12104 r12106 6 6 $^W = 1; 7 7 } 8 use Test::More tests => 7;8 use Test::More tests => 9; 9 9 10 10 use_ok( 'Catalyst::Test', 'Madre::Sync' ); … … 13 13 use_ok( 'Madre::Sync::Controller::Conf' ); 14 14 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' ); 15 ok( request('/')->is_success, 'Request should succeed' ); 16 ok( request('/bad')->code == 404, 'Request should fail with 404' ); 17 ok( request('/login')->is_success, 'Request should succeed' ); 18 ok( request('/user')->code == 415, 'Request should bounce to login page with 415' ); 19 ok( request('/user/config')->code == 415, 'Request should bounce to login page with 415' ); -
trunk/Madre-Sync/t/03_rest.t
r12105 r12106 14 14 } 15 15 16 use LWP::UserAgent; 17 use HTTP::Cookies; 16 use URI (); 17 use JSON::XS (); 18 use HTTP::Cookies (); 19 use LWP::UserAgent (); 18 20 use HTTP::Request::Common qw/GET POST PUT DELETE/; 19 use JSON::Any;20 use URI;21 21 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 23 my $json = JSON::XS->new; 24 my $ua = LWP::UserAgent->new; 26 25 push @{ $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 ) 32 32 ); 33 33 34 $ua->cookie_jar($cookie_jar); 35 36 # create account 37 34 # Create account 38 35 my $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' 42 39 }; 43 40 44 #diag 'Add a user';41 diag 'Add a user'; 45 42 my $resp = $ua->request( 46 43 PUT 'http://localhost:3000/register', 47 44 'Content-Type' => 'application/json', 48 'Content' => $j ->objToJson($req_data),45 'Content' => $json->objToJson($req_data), 49 46 ); 50 47 is( $resp->code, 200, "Account creation" ); 51 48 52 #diag $resp->status_line; 53 #diag $resp->content; 54 #diag $resp->status_line; 55 56 #diag 'login using above created account'; 49 diag $resp->status_line; 50 diag $resp->content; 51 diag $resp->status_line; 52 diag 'login using above created account'; 57 53 $resp = $ua->request( 58 54 POST 'http://localhost:3000/login', … … 65 61 is( $resp->code, 200, "Login" ); 66 62 67 # test uniqueness reregistration 63 diag 'Test uniqueness reregistration'; 68 64 $resp = $ua->request( 69 65 PUT 'http://localhost:3000/register', 70 66 'Content-Type' => 'application/json', 71 'Content' => $j ->objToJson($req_data),67 'Content' => $json->objToJson($req_data), 72 68 ); 73 69 is( $resp->code, 400, "Account creation reattempt with used email / name" ); 74 70 75 # test updating information 71 diag 'Test updating information'; 76 72 $resp = $ua->request( 77 73 POST 'http://localhost:3000/user', 78 74 'Content-Type' => 'application/json', 79 'Content' => $j ->objToJson( {75 'Content' => $json->objToJson( { 80 76 email => 'bademial.ean', 81 77 password => 'qwerty', … … 87 83 POST 'http://localhost:3000/user', 88 84 'Content-Type' => 'application/json', 89 'Content' => $j ->objToJson( {85 'Content' => $json->objToJson( { 90 86 email => 'goodemail@yes.com', 91 87 password => 'qwerty', … … 94 90 is( $resp->code, 200, "Account modification with valid email address" ); 95 91 96 #test post of config 92 diag 'Test post of config'; 97 93 $resp = $ua->request( 98 94 POST 'http://localhost:3000/user/config', 99 95 'Content-Type' => 'application/json', 100 'Content' => $j ->objToJson( {96 'Content' => $json->objToJson( { 101 97 config => { test => 'goodemail@yes.com', password => 'qwerty' } 102 98 } ) … … 104 100 is( $resp->code, 200, "Config submission" ); 105 101 106 # test get of config 102 diag 'Test get of config'; 107 103 $resp = $ua->request( 108 104 GET 'http://localhost:3000/user/config', … … 110 106 ); 111 107 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' } ) ); 113 109 #$resp =$ua->request( GET 'http://localhost:3000/user/config', 'Content-Type' => 'application/json' ); 114 110 #use Data::Dumper; … … 116 112 #diag $resp->content; 117 113 118 # test deletion 114 diag 'Test deletion'; 119 115 $resp = $ua->request( DELETE 'http://localhost:3000/user' ); 120 is( $resp->code, 200, "Deletion" );116 is( $resp->code, 200, "Deletion" );
Note: See TracChangeset
for help on using the changeset viewer.
