| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::More; |
| 4 |
use Finance::Quote; |
| 5 |
|
| 6 |
if ( not $ENV{"ONLINE_TEST"} ) { |
| 7 |
plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; |
| 8 |
} |
| 9 |
|
| 10 |
my $q = Finance::Quote->new('TreasuryDirect'); |
| 11 |
my $year = ( localtime() )[5] + 1900; |
| 12 |
my $lastyear = $year - 1; |
| 13 |
|
| 14 |
my @symbols = qw/ |
| 15 |
912810QT8 |
| 16 |
912810QY7 |
| 17 |
/; |
| 18 |
|
| 19 |
plan tests => 1 + 9*(1+$#symbols) + 3; |
| 20 |
|
| 21 |
my %quotes = $q->treasurydirect( @symbols, "BOGUS" ); |
| 22 |
ok(%quotes); |
| 23 |
|
| 24 |
foreach my $symbol (@symbols) { |
| 25 |
ok( $quotes{ $symbol, "success" }, "$symbol success" ); |
| 26 |
ok( $quotes{ $symbol, "symbol" } eq $symbol , "$symbol defined" ); |
| 27 |
ok( $quotes{ $symbol, "bid" } > 0, "$symbol returned bid" ); |
| 28 |
ok( $quotes{ $symbol, "ask" } > 0, "$symbol returned ask" ); |
| 29 |
ok( $quotes{ $symbol, "price" } > 0, "$symbol returned price" ); |
| 30 |
ok( $quotes{ $symbol, "rate" } =~ /^\d+\.\d+%$/, "$symbol returned rate" ); |
| 31 |
ok( $quotes{ $symbol, "isodate" } =~ /^\d{4}-\d{2}-\d{2}$/, "$symbol returned isodate" ); |
| 32 |
ok( substr( $quotes{ $symbol, "isodate" }, 0, 4 ) == $year |
| 33 |
|| substr( $quotes{ $symbol, "isodate" }, 0, 4 ) == $lastyear ); |
| 34 |
ok( substr( $quotes{ $symbol, "date" }, 6, 4 ) == $year |
| 35 |
|| substr( $quotes{ $symbol, "date" }, 6, 4 ) == $lastyear ); |
| 36 |
} |
| 37 |
|
| 38 |
is( $quotes{ "912810QT8", "currency" }, 'USD' ); |
| 39 |
is( $quotes{ "912810QY7", "currency" }, 'USD' ); |
| 40 |
|
| 41 |
ok( !$quotes{ "BOGUS", "success" } ); |