| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Tumblr::Test; |
|
2
|
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
20465
|
use strict; |
|
|
15
|
|
|
|
|
34
|
|
|
|
15
|
|
|
|
|
620
|
|
|
4
|
15
|
|
|
15
|
|
80
|
use warnings; |
|
|
15
|
|
|
|
|
27
|
|
|
|
15
|
|
|
|
|
1029
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
87
|
use WWW::Tumblr; |
|
|
15
|
|
|
|
|
27
|
|
|
|
15
|
|
|
|
|
415
|
|
|
7
|
15
|
|
|
15
|
|
71
|
use Test::More; |
|
|
15
|
|
|
|
|
26
|
|
|
|
15
|
|
|
|
|
196
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $t = WWW::Tumblr->new( |
|
10
|
|
|
|
|
|
|
# These are "public" keys for my small perlapi blog test. |
|
11
|
|
|
|
|
|
|
# Don't be a jerk :) |
|
12
|
|
|
|
|
|
|
consumer_key => 'm2TqZPKBN87VXTf0HZCDbLBmV8IKhjDnSh5SL2MrWYPrvDKIKE', |
|
13
|
|
|
|
|
|
|
secret_key => 'DfNf21jsNPkDfz5rRW4tUPQf0gR1G8mYtxqBDM62XQSGHNJRY9', |
|
14
|
|
|
|
|
|
|
token => '5koNK32cgylbsxs9LsTDCWFUrPccYjFCqFIbZayCFLrVlm1zuP', |
|
15
|
|
|
|
|
|
|
token_secret => 'VbFLz3lZ3P2ghw5b4dHwNNw4IAq13uHgDp4reZy4N24b4VlfM8', |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Track if we've hit the rate limit during this test run |
|
19
|
|
|
|
|
|
|
my $rate_limited = 0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
0
|
701
|
sub tumblr { $t } |
|
22
|
6
|
|
|
6
|
0
|
1992
|
sub user { $t->user } |
|
23
|
8
|
|
|
8
|
0
|
819265
|
sub blog { $t->blog('perlapi.tumblr.com') } |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Check if live tests should be skipped (env var or already rate limited) |
|
26
|
|
|
|
|
|
|
sub skip_live_tests { |
|
27
|
|
|
|
|
|
|
return 'TUMBLR_SKIP_LIVE_TESTS environment variable is set' |
|
28
|
5
|
50
|
|
5
|
0
|
34
|
if $ENV{TUMBLR_SKIP_LIVE_TESTS}; |
|
29
|
5
|
50
|
|
|
|
21
|
return 'Rate limit was hit earlier in this test run' |
|
30
|
|
|
|
|
|
|
if $rate_limited; |
|
31
|
5
|
|
|
|
|
14
|
return; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Check if we should skip posting tests specifically |
|
35
|
|
|
|
|
|
|
sub skip_posting_tests { |
|
36
|
5
|
|
|
5
|
0
|
1379249
|
my $reason = skip_live_tests(); |
|
37
|
5
|
50
|
|
|
|
22
|
return $reason if $reason; |
|
38
|
|
|
|
|
|
|
return 'TUMBLR_SKIP_POSTING_TESTS environment variable is set' |
|
39
|
5
|
50
|
|
|
|
26
|
if $ENV{TUMBLR_SKIP_POSTING_TESTS}; |
|
40
|
5
|
|
|
|
|
17
|
return; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Check an error object for rate limiting; sets flag and returns true if rate limited |
|
44
|
|
|
|
|
|
|
sub check_rate_limit { |
|
45
|
0
|
|
|
0
|
0
|
0
|
my $error = shift; |
|
46
|
0
|
0
|
0
|
|
|
0
|
return 0 unless $error && $error->can('is_rate_limited'); |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
0
|
if ($error->is_rate_limited) { |
|
49
|
0
|
|
|
|
|
0
|
$rate_limited = 1; |
|
50
|
0
|
|
|
|
|
0
|
diag("NOTE: Tumblr rate limit hit - skipping remaining posting tests"); |
|
51
|
0
|
|
|
|
|
0
|
diag("This is harmless and does not indicate a bug in WWW::Tumblr"); |
|
52
|
0
|
|
|
|
|
0
|
return 1; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
0
|
|
|
|
|
0
|
return 0; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Returns true if rate limited flag is set |
|
58
|
5
|
|
|
5
|
0
|
9754
|
sub is_rate_limited { $rate_limited } |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Helper to run a test that might hit rate limits |
|
61
|
|
|
|
|
|
|
# Usage: rate_limit_ok { $blog->post(...) } "post succeeded"; |
|
62
|
|
|
|
|
|
|
sub rate_limit_ok (&$) { |
|
63
|
0
|
|
|
0
|
0
|
|
my ($code, $name) = @_; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if (my $skip = skip_posting_tests()) { |
|
66
|
|
|
|
|
|
|
SKIP: { |
|
67
|
0
|
|
|
|
|
|
skip $skip, 1; |
|
|
0
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
|
|
|
|
|
return 1; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $result = $code->(); |
|
73
|
0
|
0
|
|
|
|
|
if ($result) { |
|
74
|
0
|
|
|
|
|
|
pass($name); |
|
75
|
0
|
|
|
|
|
|
return 1; |
|
76
|
|
|
|
|
|
|
} else { |
|
77
|
|
|
|
|
|
|
# Check if it's a rate limit error |
|
78
|
0
|
|
|
|
|
|
my $obj = $t->blog('perlapi.tumblr.com'); |
|
79
|
0
|
0
|
0
|
|
|
|
if ($obj->error && check_rate_limit($obj->error)) { |
|
80
|
|
|
|
|
|
|
SKIP: { |
|
81
|
0
|
|
|
|
|
|
skip "Rate limit exceeded", 1; |
|
|
0
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
return 1; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
fail($name); |
|
86
|
0
|
|
|
|
|
|
return 0; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |