1use strict; 2use warnings; 3use Test::More; 4use Storable; 5use Flickr::API; 6 7if (defined($ENV{MAKETEST_FLICKR_CFG})) { 8 plan( tests => 15 ); 9} 10else { 11 plan(skip_all => 'These tests require that MAKETEST_FLICKR_CFG points to a valid config, see README.'); 12} 13 14 15 16my $config_file = $ENV{MAKETEST_FLICKR_CFG}; 17my $config_ref; 18my $api; 19my $proceed = 0; 20 21my $fileflag=0; 22if (-r $config_file) { $fileflag = 1; } 23is($fileflag, 1, "Is the config file: $config_file, readable?"); 24 25SKIP: { 26 27 skip "Skipping authentication tests, flickr config isn't there or is not readable", 15 28 if $fileflag == 0; 29 30 $api = Flickr::API->import_storable_config($config_file); 31 32 isa_ok($api, 'Flickr::API'); 33 is($api->is_oauth, 0, 'Does Flickr::API object identify as Flickr'); 34 35 like($api->{fauth}->{api_key}, qr/[0-9a-f]+/i, "Did we get an api key from $config_file"); 36 like($api->{fauth}->{api_secret}, qr/[0-9a-f]+/i, "Did we get an api secret from $config_file"); 37 38 if (defined($api->{fauth}->{token}) and $api->{fauth}->{token} =~ m/^[0-9]+-[0-9a-f]+$/i) { 39 40 $proceed = 1; 41 42 } 43 44 SKIP: { 45 46 skip "Skipping authentication tests, flickr access token missing or seems wrong", 10 47 if $proceed == 0; 48 49 my $rsp = $api->execute_method('flickr.auth.checkToken', {auth_token => $api->{fauth}->{token}}); 50 51 is($rsp->success(), 1, "Did flickr.auth.checkToken complete sucessfully"); 52 my $ref = $rsp->as_hash(); 53 54 is($ref->{stat}, 'ok', "Did flickr.auth.checkToken complete sucessfully"); 55 56 isnt($ref->{auth}->{user}->{nsid}, undef, "Did flickr.auth.checkToken return nsid"); 57 isnt($ref->{auth}->{user}->{username}, undef, "Did flickr.auth.checkToken return username"); 58 59 60 $rsp = $api->execute_method('flickr.test.login', {auth_token => $api->{fauth}->{token}}); 61 $ref = $rsp->as_hash(); 62 63 is($ref->{stat}, 'ok', "Did flickr.test.login complete sucessfully"); 64 65 isnt($ref->{user}->{id}, undef, "Did flickr.test.login return id"); 66 isnt($ref->{user}->{username}, undef, "Did flickr.test.login return username"); 67 68 69 $rsp = $api->execute_method('flickr.prefs.getPrivacy', {auth_token => $api->{fauth}->{token}}); 70 $ref = $rsp->as_hash(); 71 72 is($ref->{stat}, 'ok', "Did flickr.prefs.getPrivacy complete sucessfully"); 73 74 isnt($ref->{person}->{nsid}, undef, "Did flickr.prefs.getPrivacy return nsid"); 75 isnt($ref->{person}->{privacy}, undef, "Did flickr.prefs.getPrivacy return privacy"); 76 77 } 78} 79 80 81 82exit; 83 84__END__ 85 86 87# Local Variables: 88# mode: Perl 89# End: 90