[BACK]Return to network_tests.t CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / t

Diff for /HOPE/Net-OpenAMD/t/network_tests.t between version 1.8 and 1.15

version 1.8, 2010/07/13 01:14:43 version 1.15, 2010/07/17 13:10:48
Line 1 
Line 1 
 #!perl  #!perl
 package NetworkTests;  package NetworkTests;
   
 # $AFresh1: network_tests.t,v 1.7 2010/06/30 18:04:20 andrew Exp $  # $AFresh1: network_tests.t,v 1.14 2010/07/17 11:46:47 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;  
   
   #use Data::Dumper;
   
 if ( !caller() ) {  if ( !caller() ) {
     if ( $ENV{'NETWORK_TESTS'} ) {      if ( $ENV{'NETWORK_TESTS'} ) {
         plan tests => 13;          plan tests => 14;
     }      }
     else {      else {
         plan skip_all =>          plan skip_all =>
             'Network test.  Set $ENV{NETWORK_TESTS} to a true value to run.';              'Network test.  Set $ENV{NETWORK_TESTS} to a true value to run.';
     }      }
   
       my $amd = Net::OpenAMD->new();
       run_tests($amd);
   
       #done_testing();
   }
   
   1;
   
   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{1,2}\.\d+$'),
           boolean => any( 'True', 'False' ),
       );
   
       $cmp{user} = [
           $cmp{single_line},
           superhashof(
               {   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},
           }
       ];
   
       $cmp{location} = superhashof(
           {   #area => $cmp{area},
               user => $cmp{single_line},
   
               #button => $cmp{boolean},
               x => $cmp{coordinate},
               y => $cmp{coordinate},
   
               #time   => $cmp{single_line},
           }
       );
   
     my %tests = (      my %tests = (
         location => [          location => [
             {   args   => undef,              {   args   => undef,
                 expect => [                  expect => array_each( $cmp{location} ),
                     {   'y'    => '43.4861220266',  
                         'user' => 'user6',  
                         'x'    => '18.2468971683'  
                     },  
                     {   'y'    => '36.5212503999',  
                         'user' => 'user7',  
                         'x'    => '27.138154414'  
                     },  
                     {   'y'    => '45.4561205517',  
                         'user' => 'user4',  
                         'x'    => '43.2247016461'  
                     },  
                     {   'y'    => '33.3876312219',  
                         'user' => 'user5',  
                         'x'    => '1.88999914202'  
                     },  
                     {   'y'    => '6.24512871596',  
                         'user' => 'user2',  
                         'x'    => '19.3851425782'  
                     },  
                     {   'y'    => '11.5686903901',  
                         'user' => 'user3',  
                         'x'    => '37.0118334017'  
                     },  
                     {   'y'    => '39.6231665024',  
                         'user' => 'user0',  
                         'x'    => '4.80925926012'  
                     },  
                     {   'y'    => '30.0999230116',  
                         'user' => 'user1',  
                         'x'    => '1.48091119245'  
                     },  
                     {   'y'    => '44.0085836003',  
                         'user' => 'user8',  
                         'x'    => '15.5482823414'  
                     },  
                     {   'y'    => '35.8354729961',  
                         'user' => 'user9',  
                         'x'    => '1.3539559599'  
                     },  
                     {   'y'    => '23.0220504783',  
                         'user' => 'user10',  
                         'x'    => '16.5797941904'  
                     },  
                     {   'y'    => '18.1245161319',  
                         'user' => 'user11',  
                         'x'    => '39.2951848533'  
                     },  
                     {   'y'    => '11.3998081612',  
                         'user' => 'user12',  
                         'x'    => '3.99920632586'  
                     },  
                     {   'y'    => '13.1865736157',  
                         'user' => 'user13',  
                         'x'    => '20.5159017473'  
                     },  
                     {   'y'    => '17.742550877',  
                         'user' => 'user14',  
                         'x'    => '4.55691655225'  
                     },  
                     {   'y'    => '18.7671525659',  
                         'user' => 'user15',  
                         'x'    => '0.262498111169'  
                     },  
                     {   'y'    => '44.2762837418',  
                         'user' => 'user16',  
                         'x'    => '35.5124464395'  
                     },  
                     {   'y'    => '36.5340075619',  
                         'user' => 'user17',  
                         'x'    => '9.14220464394'  
                     },  
                     {   'y'    => '29.2264569149',  
                         'user' => 'user18',  
                         'x'    => '3.47406301583'  
                     },  
                     {   'y'    => '1.68159309609',  
                         'user' => 'user19',  
                         'x'    => '1.41024785197'  
                     }  
                 ],  
             },              },
             {   args   => [ user => 'user0' ],              {   args   => { user => 'user0' },
                 expect => [],                  expect => qr/^Invalid \s JSON|$/xms,
             },              },
               {   args   => { user => 'user0', limit => 5 },
                   expect => qr/^Invalid \s JSON|$/xms,
               },
               {   args   => { area => 'Lovelace' },
                   expect => array_each( $cmp{location} ),
               },
         ],          ],
         speakers => [          speakers => [
             {   args   => undef,              {   args   => undef,
                 expect => [                  expect => array_each( $cmp{speaker} ),
                     [   '9000',  
                         {   'name' => 'The Cheshire Catalyst',  
                             'bio'  => 'Jacob\'s bio'  
                         }  
                     ],  
                     [   'user0',  
                         {   'name' => 'Jacob',  
                             'bio'  => 'Jacob\'s bio'  
                         }  
                     ],  
                     [   'user1',  
                         {   'name' => 'Emma',  
                             'bio'  => 'Emma\'s bio'  
                         }  
                     ],  
                     [   'user10',  
                         {   'name' => 'Alexander',  
                             'bio'  => 'Alexander\'s bio'  
                         }  
                     ],  
                     [   'user11',  
                         {   'name' => 'Olivia',  
                             'bio'  => 'Olivia\'s bio'  
                         }  
                     ],  
                     [   'user12',  
                         {   'name' => 'Anthony',  
                             'bio'  => 'Anthony\'s bio'  
                         }  
                     ],  
                     [   'user13',  
                         {   'name' => 'Sophia',  
                             'bio'  => 'Sophia\'s bio'  
                         }  
                     ],  
                     [   'user14',  
                         {   'name' => 'William',  
                             'bio'  => 'William\'s bio'  
                         }  
                     ],  
                     [   'user15',  
                         {   'name' => 'Abigail',  
                             'bio'  => 'Abigail\'s bio'  
                         }  
                     ],  
                     [   'user16',  
                         {   'name' => 'Christopher',  
                             'bio'  => 'Christopher\'s bio'  
                         }  
                     ],  
                     [   'user17',  
                         {   'name' => 'Elizabeth',  
                             'bio'  => 'Elizabeth\'s bio'  
                         }  
                     ],  
                     [   'user18',  
                         {   'name' => 'Matthew',  
                             'bio'  => 'Matthew\'s bio'  
                         }  
                     ],  
                     [   'user19',  
                         {   'name' => 'Chloe',  
                             'bio'  => 'Chloe\'s bio'  
                         }  
                     ],  
                     [   'user2',  
                         {   'name' => 'Michael',  
                             'bio'  => 'Michael\'s bio'  
                         }  
                     ],  
                     [   'user3',  
                         {   'name' => 'Isabella',  
                             'bio'  => 'Isabella\'s bio'  
                         }  
                     ],  
                     [   'user4',  
                         {   'name' => 'Ethan',  
                             'bio'  => 'Ethan\'s bio'  
                         }  
                     ],  
                     [   'user5',  
                         {   'name' => 'Emily',  
                             'bio'  => 'Emily\'s bio'  
                         }  
                     ],  
                     [   'user6',  
                         {   'name' => 'Joshua',  
                             'bio'  => 'Joshua\'s bio'  
                         }  
                     ],  
                     [   'user7',  
                         {   'name' => 'Madison',  
                             'bio'  => 'Madison\'s bio'  
                         }  
                     ],  
                     [   'user8',  
                         {   'name' => 'Daniel',  
                             'bio'  => 'Daniel\'s bio'  
                         }  
                     ],  
                     [   'user9',  
                         {   'name' => 'Ava',  
                             'bio'  => 'Ava\'s bio'  
                         },  
                     ],  
                 ],  
             },              },
               {   args => { name => 'The Cheshire Catalyst' },
                   expect => array_each( $cmp{speaker} ),
               },
         ],          ],
         talks => [          talks => [
             {   args   => undef,              {   args   => undef,
                 expect => [                  expect => array_each(
                     [   'Hacking Democracy: An In Depth Analysis of the ES&S Voting Systems',                      {   abstract => $cmp{multi_line},
                         {   'speakers' =>                          speakers => array_each( $cmp{single_line} ),
                                 '["Matt Blaze", "Sandy Clark", "Eric Cronin", "Gaurav Shah", "Micah Sherr", "Adam Aviv", "Pavol Cerny"]',                          time     => $cmp{single_line},
                             'interests' => '["crypto", "telephones"]',                          title    => $cmp{single_line},
                             'time'      => '2008/07/14 13:00:00',                          track    => $cmp{track},
                             'track'     => 'Hooper',                      }
                             'abstract'  => '                  ),
                                      This talk will outline the U. Penn team\'s findings, which included  
                                      the discovery of exploitable security vulnerabilities in almost every  
                                      hardware and software component of the ES&S touch-screen and optical  
                                      scan systems.  
                                      ',  
                             'title' =>  
                                 'Hacking Democracy: An In Depth Analysis of the ES&S Voting Systems',  
                         },  
                     ],  
                 ],  
             },              },
               {   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 => [          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( $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 => [          stats => [
             {   args   => undef,              {   args   => undef,
Line 281 
Line 161 
         ],          ],
     );      );
   
     my $amd      foreach my $method ( keys %tests ) {
         = Net::OpenAMD->new( { base_uri => 'http://api.hope.net/api/', } );          foreach my $test ( @{ $tests{$method} } ) {
     run_tests( $amd, \%tests );  
   
     #done_testing();  
 }  
   
 1;  
   
 sub run_tests {  
     my ( $amd, $tests ) = @_;  
   
     foreach my $method ( keys %{$tests} ) {  
         foreach my $test ( @{ $tests->{$method} } ) {  
             no warnings 'uninitialized';              no warnings 'uninitialized';
             my $result;              my $result;
             eval { $result = $amd->$method( $test->{args} ) };              eval { $result = $amd->$method( $test->{args} ) };
Line 302 
Line 170 
                 like( $@, $test->{expect}, "AMD->$method($test->{args})" );                  like( $@, $test->{expect}, "AMD->$method($test->{args})" );
             }              }
             elsif ( ref $test->{expect} ) {              elsif ( ref $test->{expect} ) {
                 is( $@, '', "AMD->$method($test->{args})" );                  if ($@) {
                 is_deeply( $result, $test->{expect},                      is( $@, '', "AMD->$method($test->{args})" );
                           "AMD->$method($test->{args}) - "                  }
                         . 'got expected result' );                  else {
                       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})" );

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.15

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>