Debian Codegraph @

t/bseindia.t

raw
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 # Test BSEIndia functions.
11
12 my $q = Finance::Quote->new();
13 my @stocks = ("532540", "INE009A01021", "INE062A01020");
14 my $year = (localtime())[5] + 1900;
15 my $lastyear = $year - 1;
16
17 # Tests: fetch, fetch BOGUS, and 5 per stock
18 plan tests => 2 + 5*@stocks;
19
20 my %quotes = $q->fetch("bseindia", @stocks);
21 ok(%quotes);
22
23 # Check that the name and last are defined for all of the stocks.
24 foreach my $stock (@stocks) {
25 ok($quotes{$stock, "last"} > 0);
26 ok($quotes{$stock, "success"});
27 ok($quotes{$stock, "currency"} eq "INR");
28 ok(substr($quotes{$stock,"isodate"},0,4) == $year ||
29 substr($quotes{$stock,"isodate"},0,4) == $lastyear);
30 ok(substr($quotes{$stock,"date"},6,4) == $year ||
31 substr($quotes{$stock,"date"},6,4) == $lastyear);
32 }
33
34 # Check that a bogus fund returns no-success.
35 %quotes = $q->fetch("bseindia", "BOGUS");
36 ok(! $quotes{"BOGUS","success"});