1use strict; 2use warnings; 3use Test::More; 4use Data::Dumper; 5use Storable; 6 7use Flickr::API; 8 9 10if (defined($ENV{MAKETEST_OAUTH_CFG})) { 11 plan( tests => 11 ); 12} 13else { 14 plan(skip_all => 'These tests require that MAKETEST_OAUTH_CFG points to a valid config, see README.'); 15} 16 17my $config_file = $ENV{MAKETEST_OAUTH_CFG}; 18my $config_ref; 19 20my $fileflag=0; 21if (-r $config_file) { $fileflag = 1; } 22is($fileflag, 1, "Is the config file: $config_file, readable?"); 23 24SKIP: { 25 26 skip "Skipping request token tests, oauth config isn't there or is not readable", 10 27 if $fileflag == 0; 28 29 30 my $api = Flickr::API->import_storable_config($config_file); 31 32 isa_ok($api, 'Flickr::API'); 33 is($api->is_oauth, 1, 'Does Flickr::API object identify as OAuth'); 34 35 SKIP: { 36 37 skip "Skipping request token tests, oauth config already has accesstoken", 8 38 if $api->get_oauth_request_type() =~ m/protected resource/i; 39 40 is($api->get_oauth_request_type(), 'consumer', 'Does Flickr::API object identify as consumer request'); 41 42 my $request_req = $api->oauth_request_token({'callback' => $config_ref->{callback}}); 43 44 is($request_req, 'ok', "Did oauth_request_token complete successfully"); 45 46 SKIP: { 47 skip "Skipping request token tests, oauth_request_token returns $request_req", 6 48 if $request_req ne 'ok'; 49 50 my %config = $api->export_config(); 51 $config{'continue-to-access'} = $request_req; 52 53 $fileflag=0; 54 if (-w $config_file) { $fileflag = 1; } 55 is($fileflag, 1, "Is the config file: $config_file, writeable?"); 56 57 $api->export_storable_config($config_file); 58 59 my $api2 = Flickr::API->import_storable_config($config_file); 60 61 isa_ok($api2, 'Flickr::API'); 62 63 is_deeply($api2->{oauth}, $api->{oauth}, "Did import_storable_config get back the config we stored"); 64 65 isa_ok($api2->{oauth}->{request_token}, 'Net::OAuth::V1_0A::RequestTokenResponse'); 66 is($api->{oauth}->{request_token}->{callback_confirmed}, 'true', 67 'Is the callback confirmed in the request token'); #10 68 like($api2->{oauth}->{request_token}->{token_secret}, qr/[0-9a-f]+/i, 69 'Was a request token received and are we good to go to to access token tests?'); 70 print "\n\nOAuth Config:\n\n",Dumper($api2->{oauth}),"\n\n"; 71 } 72 } 73} 74 75 76exit; 77 78 79# Local Variables: 80# mode: Perl 81# End: 82