-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOMSETest.pl
executable file
·74 lines (57 loc) · 1.74 KB
/
BOMSETest.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl -w
# A test script to check for working of the BOMSE module.
use strict;
use Test;
use Data::Dumper;
use Finance::Quote;
BEGIN {plan tests => 26};
#Ensure that print statements print in order
autoflush STDOUT 1;
my $q = Finance::Quote->new();
#List of stocks to fetch. Feel free to change this during testing
my @stocks = ("SBIN", "INDIGO", "SUZLON", "HDFC");
my %quotes = $q->fetch("bomse", @stocks);
print "\nChecking if any data is returned: ";
ok(%quotes);
#print($q);
#exit();
foreach my $stock (@stocks)
{
my $name = $quotes{$stock, "name"};
print "\n\n#Testing $stock";
print "\nFetch successful?: ";
ok($quotes{$stock, "success"});
if(!$quotes{$stock, "success"})
{
my $errmsg = $quotes{$stock, "errormsg"};
print "Error Message:\n$errmsg\n";
}
else
{
print "Returned name: $name";
my $exchange = $quotes{$stock, "exchange"};
#print "\nCheck Exchange: $exchange ";
ok($exchange eq 'Sourced from NSE via python-nsetools (as JSON)');
my $fetch_method = $quotes{$stock, "method"};
#print "Fetch Method: $fetch_method ";
ok($fetch_method eq 'bomse');
my $last = $quotes{$stock, "last"};
#print "Last Price: $last ";
ok($last > 0);
my $volume = $quotes{$stock, "volume"};
#print "Volumes: $volume ";
ok($volume > 0);
my $currency = $quotes{$stock, "currency"};
#print "Currency: $currency ";
ok($currency eq 'INR');
#TODO: Add a test to raise a warning if the quote is excessively old
my $isodate = $quotes{$stock, "isodate"};
print "ISOdate: $isodate ";
my $date = $quotes{$stock, "date"};
print "Date: $date ";
}
}
print "\nChecking for a bogus stock: ";
# Check that a bogus stock returns no-success.
%quotes = $q->fetch("bomse", "BOGUS");
ok(! $quotes{"BOGUS","success"});