/
20_generated.t
74 lines (58 loc) · 2.33 KB
/
20_generated.t
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
#!perl
use warnings;
use strict;
use Test::More;
use List::Util qw/sum/;
use lib qw(t/lib);
eval 'use TestUA';
plan skip_all => 'LWP::UserAgent 5.819 required for tests' if $@;
use Net::Twitter;
my $nt = Net::Twitter->new(
traits => [qw/API::REST API::Search API::TwitterVision/],
username => 'me', password => 'secret',
);
my $t = TestUA->new($nt->ua);
my @params = qw/twitter_id another_id/;
my @api_methods =
grep { blessed $_ && $_->isa('Net::Twitter::Meta::Method') }
$nt->meta->get_all_methods;
plan tests => 5 * 2 * sum map 1 + @{$_->aliases}, @api_methods;
# 2 passes to ensure nothing on the first pass changes internal state affecting the 2nd
for my $pass ( 1, 2 ) {
for my $entry ( sort { $a->name cmp $b->name } @api_methods ) {
my $pos_params = $entry->required;
my $path = $entry->path;
$pos_params = $entry->params if @$pos_params == 0 && @{$entry->params} == 1;
my $has_id = $path =~ s/:id\b/$params[0]/;
if ( $has_id && @$pos_params == 0 ) {
@$pos_params = 'id';
}
$path = "/$path.json";
for my $call ( $entry->name, @{$entry->aliases} ) {
# the parameter names/values expected in GET/POST parameters
my %expected;
my @local_params = @params[0..$#{$pos_params}];
@expected{@$pos_params} = @local_params;
# HACK! Expect "true" or "false" for boolean params
for my $bool_param ( @{ $entry->booleans || [] } ) {
if ( exists $expected{$bool_param} ) {
$expected{$bool_param} = $expected{$bool_param} ? 'true' : 'false';
}
}
$expected{source} = $nt->source if $entry->add_source;
my $r = eval { $nt->$call(@local_params) };
diag "$@\n" if $@;
ok $r, "[$pass] $call(@{[ join ', ' => @$pos_params ]})";
# horrible kludge
my $args = $t->args;
ok !$has_id || (
delete $expected{id} &&
$t->path =~ /\/twitter_id[\/.]/
), "id test";
is_deeply $args, \%expected, "[$pass] $call args";
is $t->path, $path, "[$pass] $call path";
is $t->method, $entry->method, "[$pass] $call method";
}
}
}
exit 0;