Debian Codegraph @

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