| version 1.4, 2010/06/27 01:52:33 | 
version 1.10, 2010/07/13 04:23:48 | 
 | 
 | 
|  #!perl | 
 #!perl | 
|  package NetworkTests; | 
 package NetworkTests; | 
|   | 
  | 
|  # $AFresh1: network_tests.t,v 1.3 2010/06/26 16:50:40 andrew Exp $ | 
 # $AFresh1: network_tests.t,v 1.9 2010/07/13 02:27:06 andrew Exp $ | 
|   | 
  | 
|  use strict; | 
 use strict; | 
|  use warnings; | 
 use warnings; | 
|   | 
  | 
|  use Test::More; | 
 use Test::More; | 
|   | 
 use Test::Deep; | 
|  use Net::OpenAMD; | 
 use Net::OpenAMD; | 
|   | 
 use Data::Dumper; | 
|   | 
  | 
|  if ( !caller() ) { | 
 if ( !caller() ) { | 
|      if ( $ENV{'NETWORK_TESTS'} ) { | 
     if ( $ENV{'NETWORK_TESTS'} ) { | 
|   | 
         plan tests => 13; | 
|          # plan tests => ??; | 
  | 
|      } | 
     } | 
|      else { | 
     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); | 
     run_tests($amd); | 
|   | 
  | 
|      done_testing(); | 
     #done_testing(); | 
|  } | 
 } | 
|   | 
  | 
|  1; | 
 1; | 
 | 
 | 
|  sub run_tests { | 
 sub run_tests { | 
|      my ($amd) = @_; | 
     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{speaker} = $cmp{single_line}; | 
|   | 
  | 
|      my %tests = ( | 
     my %tests = ( | 
|          location => [ | 
         location => [ | 
|              {   args   => undef, | 
             {   args   => undef, | 
|                  expect => [ | 
                 expect => array_each( | 
|                      {   'y'      => '83.1452331542969', | 
                     {   area   => $cmp{area}, | 
|                          'area'   => 'Engressia', | 
                         user   => $cmp{digits}, | 
|                          'time'   => 2387, | 
                         button => $cmp{boolean}, | 
|                          'user'   => 12983, | 
                         x      => $cmp{coordinate}, | 
|                          'x'      => '46.7369918823242', | 
                         y      => $cmp{coordinate}, | 
|                          'button' => 'False' | 
                         time   => $cmp{single_line}, | 
|                      } | 
                     } | 
|                  ], | 
                 ), | 
|              }, | 
             }, | 
|   | 
             {   args   => { user => 'user0' }, | 
|   | 
                 expect => array_each(), | 
|   | 
             }, | 
|          ], | 
         ], | 
|          speakers => [ | 
         speakers => [ | 
|              {   args   => undef, | 
             {   args   => undef, | 
|                  expect => [ | 
                 expect => array_each( | 
|                      {   'name' => 'Johnny', | 
                     [   $cmp{single_line}, | 
|                          'bio'  => 'Johnny\'s bio' | 
                         {   name => $cmp{single_line}, | 
|                      }, | 
                             bio  => $cmp{multi_line}, | 
|                  ], | 
                         } | 
|   | 
                     ] | 
|   | 
                 ), | 
|              }, | 
             }, | 
|          ], | 
         ], | 
|          talks => [ | 
         talks => [ | 
|              {   args   => undef, | 
             {   args   => undef, | 
|                  expect => [ | 
                 expect => array_each( | 
|                      {   'speakers'  => [ 'Judas', 'JohnnyX' ], | 
                     {   abstract => $cmp{multi_line}, | 
|                          'interests' => [ 'media', 'crypto' ], | 
                         speakers => array_each( $cmp{single_line} ), | 
|                          'time'      => '2008/7/18 13:00:00', | 
                         time     => $cmp{single_line}, | 
|                          'track'     => 'Hooper', | 
                         title    => $cmp{single_line}, | 
|                          'title' => 'Ancient Egyptian Music and DRM', | 
                         track    => $cmp{track}, | 
|                          'abstract' => | 
  | 
|                              'A discussion of the development of musical notation, which was designed as a means of reproducing music while making it impossible for the general public to perform without permission.' | 
  | 
|                      } | 
                     } | 
|                  ], | 
                 ), | 
|              }, | 
             }, | 
|          ], | 
         ], | 
|          interests => [ | 
         interests => [ | 
|              {   args   => undef, | 
             {   args   => undef, | 
|                  expect => [ | 
                 expect => $cmp{all_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', | 
  | 
|                  ], | 
  | 
|              }, | 
             }, | 
|          ], | 
         ], | 
|          users => [ | 
         users => [ | 
|              {   args   => undef, | 
             {   args   => undef, | 
|                  expect => [ | 
                 expect => array_each( | 
|                      {   'name'      => 'JohnnyX', | 
                     $cmp{single_line}, | 
|                          'x'         => '32.54091324', | 
                     {   name => $cmp{single_line}, | 
|                          'y'         => '54.10958384', | 
  | 
|                          'interests' => [ | 
                         #interests => array_each( $cmp{interests} ), | 
|                              'new tech',           'radio', | 
                         #x         => $cmp{coordinate}, | 
|                              'lockpicking',        'crypto', | 
                         #y         => $cmp{coordinate}, | 
|                              'telephones',         'social engineering', | 
  | 
|                              'hacker spaces',      'hardware hacking', | 
  | 
|                              'nostalgia',          'communities', | 
  | 
|                              'science',            'network security', | 
  | 
|                              'malicious software', 'pen testing' | 
  | 
|                          ], | 
  | 
|                      } | 
                     } | 
|                  ] | 
                 ), | 
|              }, | 
             }, | 
|          ], | 
         ], | 
|          stats => [ | 
         stats => [ | 
 | 
 | 
|              } | 
             } | 
|              elsif ( ref $test->{expect} ) { | 
             elsif ( ref $test->{expect} ) { | 
|                  is( $@, '', "AMD->$method($test->{args})" ); | 
                 is( $@, '', "AMD->$method($test->{args})" ); | 
|                  is_deeply( $result, $test->{expect}, 'got expected result' ); | 
                 cmp_deeply( $result, $test->{expect}, | 
|   | 
                           "AMD->$method($test->{args}) - " | 
|   | 
                         . 'got expected result' ); | 
|              } | 
             } | 
|              else { | 
             else { | 
|                  is( $@, $test->{expect}, "AMD->$method($test->{args})" ); | 
                 is( $@, $test->{expect}, "AMD->$method($test->{args})" ); |