File: 06-flickr-authenticated-methods.t

package info (click to toggle)
libflickr-api-perl 1.29-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 1,471; makefile: 22
file content (89 lines) | stat: -rw-r--r-- 2,452 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;
use Test::More;
use Storable;
use Flickr::API;

if (defined($ENV{MAKETEST_FLICKR_CFG})) {
	plan( tests => 15 );
}
else {
	plan(skip_all => 'These tests require that MAKETEST_FLICKR_CFG points to a valid config, see README.');
}



my $config_file  = $ENV{MAKETEST_FLICKR_CFG};
my $config_ref;
my $api;
my $proceed = 0;

my $fileflag=0;
if (-r $config_file) { $fileflag = 1; }
is($fileflag, 1, "Is the config file: $config_file, readable?");

SKIP: {

	skip "Skipping authentication tests, flickr config isn't there or is not readable", 15
	  if $fileflag == 0;

	$api = Flickr::API->import_storable_config($config_file);

	isa_ok($api, 'Flickr::API');
	is($api->is_oauth, 0, 'Does Flickr::API object identify as Flickr');

	like($api->{fauth}->{api_key},  qr/[0-9a-f]+/i, "Did we get an api key from $config_file");
	like($api->{fauth}->{api_secret}, qr/[0-9a-f]+/i, "Did we get an api secret from $config_file");

	if (defined($api->{fauth}->{token}) and $api->{fauth}->{token} =~ m/^[0-9]+-[0-9a-f]+$/i) {

		$proceed = 1;

	}

	  SKIP: {

			skip "Skipping authentication tests, flickr access token missing or seems wrong", 10
			  if $proceed == 0;

			my $rsp = $api->execute_method('flickr.auth.checkToken', {auth_token => $api->{fauth}->{token}});

			is($rsp->success(), 1, "Did flickr.auth.checkToken complete sucessfully");
			my $ref = $rsp->as_hash();

			is($ref->{stat}, 'ok', "Did flickr.auth.checkToken complete sucessfully");

			isnt($ref->{auth}->{user}->{nsid}, undef, "Did flickr.auth.checkToken return nsid");
			isnt($ref->{auth}->{user}->{username}, undef, "Did flickr.auth.checkToken return username");


			$rsp = $api->execute_method('flickr.test.login', {auth_token => $api->{fauth}->{token}});
			$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', {auth_token => $api->{fauth}->{token}});
			$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: