1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
use strict;
use warnings;
use Test::More tests => 17;
use Storable;
use Flickr::API;
my $config_file;
if (defined($ENV{MAKETEST_OAUTH_CFG})) {
$config_file = $ENV{MAKETEST_OAUTH_CFG};
}
else {
diag( 'No MAKETEST_OAUTH_CFG, shallow tests only' );
$config_file = '/no/file/by/this/name.is.there?';
}
my $config_ref;
my $api;
$api = Flickr::API->new(
{ consumer_key => '012345beefcafe543210',
consumer_secret => 'a234b345c456feed',
}
);
isa_ok($api, 'Flickr::API');
my $fileflag=0;
if ($config_file and -r $config_file) { $fileflag = 1; }
SKIP: {
skip "Skipping authentication tests, oauth config isn't there or is not readable", 16
if $fileflag == 0;
is(
$fileflag,
1,
'Is the config file: $config_file, readable?'
);
$api = Flickr::API->import_storable_config($config_file);
isa_ok($api, 'Flickr::API');
is(
$api->is_oauth,
1,
'Does Flickr::API object identify as OAuth');
like(
$api->{oauth}->{consumer_key},
qr/[0-9a-f]+/i,
"Did we get a consumer key from $config_file"
);
like(
$api->{oauth}->{consumer_secret},
qr/[0-9a-f]+/i,
"Did we get a consumer secret from $config_file"
);
like(
$api->{oauth}->{token},
qr/^[0-9]+-[0-9a-f]+$/i,
"Did we get an access_token token from $config_file"
);
like(
$api->{oauth}->{token_secret},
qr/^[0-9a-f]+$/i,
"Did we get an access_token token_secret from $config_file"
);
my $proceed = 0;
if ($api->{oauth}->{token} =~ m/^[0-9]+-[0-9a-f]+$/i and
$api->{oauth}->{token_secret} =~ m/^[0-9a-f]+$/i) {
$proceed = 1;
}
SKIP: {
skip "Skipping authentication tests, oauth access token seems wrong", 9
if $proceed == 0;
my $rsp = $api->execute_method('flickr.auth.oauth.checkToken');
my $ref = $rsp->as_hash();
is(
$ref->{stat},
'ok',
'Did flickr.auth.oauth.checkToken complete sucessfully'
);
isnt(
$ref->{oauth}->{user}->{nsid},
undef,
'Did flickr.auth.oauth.checkToken return nsid'
);
isnt(
$ref->{oauth}->{user}->{username},
undef,
'Did flickr.auth.oauth.checkToken return username'
);
$rsp = $api->execute_method('flickr.test.login');
$ref = $rsp->as_hash();
is(
$ref->{stat},
'ok',
'Did flickr.test.login complete sucessfully'
);
isnt(
$ref->{user}->{id},
undef,
'Did flickr.test.login return id'
);
isnt(
$ref->{user}->{username},
undef,
'Did flickr.test.login return username'
);
$rsp = $api->execute_method('flickr.prefs.getPrivacy');
$ref = $rsp->as_hash;
is(
$ref->{stat},
'ok',
'Did flickr.prefs.getPrivacy complete sucessfully'
);
isnt(
$ref->{person}->{nsid},
undef,
'Did flickr.prefs.getPrivacy return nsid'
);
isnt(
$ref->{person}->{privacy},
undef,
'Did flickr.prefs.getPrivacy return privacy'
);
}
}
exit;
__END__
# Local Variables:
# mode: Perl
# End:
|