-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInvestNowExporterTest.py
117 lines (105 loc) · 3.62 KB
/
InvestNowExporterTest.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from InvestNowExporter import *
import unittest
class InvestNowExporterTest(unittest.TestCase):
def _get_exporter(self):
return InvestNowExporter({
"Smartshares - Emerging Markets Equities ESG (EMG)": {
"instrument_code": "EMG",
"market_code": "NZX"
},
"Vanguard Intl Shares Select Exclusions Index Fund - NZD Hedged": {
"instrument_code": "VAN8287AU",
"market_code": "FundNZ"
},
"Vanguard International Shares Select Exclusions Index Fund": {
"instrument_code": "VAN1579AU",
"market_code": "FundNZ"
}
})
def test_parses_full_description(self):
data = [
{
"date": "2020-12-14T00:00:00+13:00",
"description": "Buy 123 Smartshares - Emerging Markets Equities ESG (EMG) at 2.36",
"amount": 522.88
},
{
"date": "2020-12-14T00:00:00+13:00",
"description": "Sell 4 Vanguard Intl Shares Select Exclusions Index Fund - NZD Hedged at 1.23",
"amount": 123.45
},
{
"date": "2020-12-14T00:00:00+13:00",
"description": "Buy 579.98 Vanguard International Shares Select Exclusions Index Fund at 1.6073",
"amount": 1000
},
]
exporter = self._get_exporter()
result = exporter.export(data)
self.assertEqual(
{
"Trade Date": "2020-12-14T00:00:00+13:00",
"Instrument Code": "EMG",
"Market Code": "NZX",
"Quantity": 123,
"Price": 2.36,
"Transaction Type": "Buy"
},
result[0]
)
self.assertEqual(
{
"Trade Date": "2020-12-14T00:00:00+13:00",
"Instrument Code": "VAN8287AU",
"Market Code": "FundNZ",
"Quantity": 4,
"Price": 1.23,
"Transaction Type": "Sell"
},
result[1]
)
self.assertEqual(
{
"Trade Date": "2020-12-14T00:00:00+13:00",
"Instrument Code": "VAN1579AU",
"Market Code": "FundNZ",
"Quantity": 579.98,
"Price": 1.61,
"Transaction Type": "Buy"
},
result[2]
)
def test_parses_sparse_description(self):
data = [
{
"date": "2020-12-14T00:00:00+13:00",
"description": "Buy Smartshares - Emerging Markets Equities ESG (EMG) at 10.00",
"amount": 500.00
}
]
exporter = self._get_exporter()
result = exporter.export(data)
self.assertEqual(
{
"Trade Date": "2020-12-14T00:00:00+13:00",
"Instrument Code": "EMG",
"Market Code": "NZX",
"Quantity": 50,
"Price": 10.00,
"Transaction Type": "Buy"
},
result[0]
)
def test_handles_thousands_separators(self):
data = [
{
"date": "2020-12-14T00:00:00+13:00",
"description": "Buy 1,234 Smartshares - Emerging Markets Equities ESG (EMG) at 2.36",
"amount": 522.88
}
]
exporter = self._get_exporter()
result = exporter.export(data)
self.assertEqual(result[0]['Quantity'], 1234)
if __name__ == "__main__":
unittest.main()