=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/t/network_tests.t,v retrieving revision 1.3 retrieving revision 1.12 diff -u -r1.3 -r1.12 --- HOPE/Net-OpenAMD/t/network_tests.t 2010/06/26 17:50:40 1.3 +++ HOPE/Net-OpenAMD/t/network_tests.t 2010/07/13 07:10:31 1.12 @@ -1,27 +1,31 @@ #!perl package NetworkTests; -# $AFresh1: network_tests.t,v 1.2 2010/06/26 16:47:01 andrew Exp $ +# $AFresh1: network_tests.t,v 1.11 2010/07/13 03:37:47 andrew Exp $ use strict; use warnings; use Test::More; +use Test::Deep; use Net::OpenAMD; +#use Data::Dumper; + if ( !caller() ) { if ( $ENV{'NETWORK_TESTS'} ) { - - # plan tests => ??; + plan tests => 31; } else { - plan skip_all => "Set env NETWORK_TESTS to test"; + plan skip_all => + 'Network test. Set $ENV{NETWORK_TESTS} to a true value to run.'; } - my $amd = Net::OpenAMD->new(); + my $amd + = Net::OpenAMD->new( { base_uri => 'http://api.hope.net/api/', } ); run_tests($amd); - done_testing(); + #done_testing(); } 1; @@ -29,35 +33,125 @@ sub run_tests { my ($amd) = @_; + my @interests = ( + "new tech", "activism", + "radio", "lockpicking", + "crypto", "privacy", + "ethics", "telephones", + "social engineering", "hacker spaces", + "hardware hacking", "nostalgia", + "communities", "science", + "government", "network security", + "malicious software", "pen testing", + "web", "niche hacks", + "media" + ); + my %cmp = ( + single_line => re('^[^\n]+$'), + multi_line => re('(?xms:^.*$)'), + digits => re('^\d+$'), + track => any( 'Lovelace', 'Tesla', 'Bell', 'Hooper' ), + area => any('Engressia'), + interests => any(@interests), + all_interests => bag(@interests), + coordinate => re('^\d\d\.\d+$'), + boolean => any( 'True', 'False' ), + ); + + $cmp{user} = [ + $cmp{single_line}, + { name => $cmp{single_line}, + + #interests => array_each( $cmp{interests} ), + #x => $cmp{coordinate}, + #y => $cmp{coordinate}, + } + ]; + + $cmp{speaker} = [ + $cmp{single_line}, + { name => $cmp{single_line}, + bio => $cmp{multi_line}, + } + ]; + my %tests = ( location => [ { args => undef, - expect => {}, + expect => array_each( + { area => $cmp{area}, + user => $cmp{digits}, + button => $cmp{boolean}, + x => $cmp{coordinate}, + y => $cmp{coordinate}, + time => $cmp{single_line}, + } + ), }, + { args => { user => 'user0' }, + expect => array_each(), + }, + { args => { user => 'user0', limit => 20 }, + expect => array_each(), + }, + { args => { area => 'Engressa' }, + expect => array_each(), + }, ], speakers => [ { args => undef, - expect => {}, + expect => array_each( $cmp{speaker} ), }, + { args => { name => 'The Cheshire Catalyst' }, + expect => array_each( $cmp{speaker} ), + }, ], talks => [ { args => undef, - expect => {}, + expect => array_each( + { abstract => $cmp{multi_line}, + speakers => array_each( $cmp{single_line} ), + time => $cmp{single_line}, + title => $cmp{single_line}, + track => $cmp{track}, + } + ), }, + { args => { interests => 'lockpicking' }, + expect => array_each( + { abstract => $cmp{multi_line}, + speakers => array_each( $cmp{single_line} ), + time => $cmp{single_line}, + title => $cmp{single_line}, + track => $cmp{track}, + + # interests => 'lockpicking', + } + ), + }, ], interests => [ { args => undef, - expect => {}, + expect => $cmp{all_interests}, }, ], users => [ { args => undef, - expect => {}, + expect => array_each( $cmp{user} ), }, + { args => { user => 'user0' }, + expect => array_each( $cmp{user} ), + }, + { args => { user => 'user0', limit => 20 }, + expect => array_each( $cmp{user} ), + }, + { args => { interests => 'lockpicking' }, + expect => array_each( $cmp{user} ), + }, ], stats => [ { args => undef, - expect => {}, + expect => qr/^Unused \s feature/xms, }, ], ); @@ -67,8 +161,18 @@ no warnings 'uninitialized'; my $result; eval { $result = $amd->$method( $test->{args} ) }; - is( $@, undef, "AMD->$method($test->{args})" ); - is( $result, $test->{expect}, 'got expected result' ); + if ( ref $test->{expect} eq 'Regexp' ) { + like( $@, $test->{expect}, "AMD->$method($test->{args})" ); + } + elsif ( ref $test->{expect} ) { + is( $@, '', "AMD->$method($test->{args})" ); + cmp_deeply( $result, $test->{expect}, + "AMD->$method($test->{args}) - " + . 'got expected result' ); + } + else { + is( $@, $test->{expect}, "AMD->$method($test->{args})" ); + } } } }