forked from MicroPyramid/forex-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bitcoin.py
More file actions
252 lines (194 loc) · 10.1 KB
/
test_bitcoin.py
File metadata and controls
252 lines (194 loc) · 10.1 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import datetime
from decimal import Decimal
from unittest import TestCase
from forex_python.bitcoin import (get_btc_symbol, convert_btc_to_cur_on, convert_to_btc_on,
convert_btc_to_cur, convert_to_btc, get_latest_price,
get_previous_price, get_previous_price_list, BtcConverter)
from forex_python.converter import RatesNotAvailableError, DecimalFloatMismatchError
class TestLatestPrice(TestCase):
"""
Test get latest price using currency code
"""
def test_latest_price_valid_currency(self):
price = get_latest_price('USD')
self.assertEqual(type(price), float)
def test_latest_price_invalid_currency(self):
price = get_latest_price('XYZ')
self.assertFalse(price)
class TestPreviousPrice(TestCase):
"""
Test Price with date input
"""
def test_previous_price_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
price = get_previous_price('USD', date_obj)
self.assertEqual(type(price), float)
def test_previous_price_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, get_previous_price, 'XYZ', date_obj)
class TestPreviousPriceList(TestCase):
"""
Test previous price list for a currency
"""
def test_previous_price_list_with_valid_currency(self):
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
end_date = datetime.datetime.today()
price_list = get_previous_price_list('USD', start_date, end_date)
self.assertTrue(price_list)
self.assertEqual(type(price_list), dict)
def test_previous_price_list_with_invalid_currency(self):
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
end_date = datetime.datetime.today()
price_list = get_previous_price_list('XYZ', start_date, end_date)
self.assertFalse(price_list)
self.assertEqual(type(price_list), dict)
class TestConvertBtc(TestCase):
"""
Test Converting amount to Bit coins
"""
def test_convet_to_btc_with_valid_currency(self):
coins = convert_to_btc(250, 'USD')
self.assertEqual(type(coins), float)
def test_convet_to_btc_with_invalid_currency(self):
self.assertRaises(RatesNotAvailableError, convert_to_btc, 250, 'XYZ')
class TestConvertBtcToCur(TestCase):
"""
Convert Bit Coins to Valid Currency amount
"""
def test_convert_btc_to_cur_valid_currency(self):
amount = convert_btc_to_cur(2, 'USD')
self.assertEqual(type(amount), float)
def test_convert_btc_to_cur_invalid_currency(self):
self.assertRaises(RatesNotAvailableError, convert_btc_to_cur, 2, 'XYZ')
class TestConvertToBtcOn(TestCase):
"""
Convert To bit coin based on previous dates
"""
def test_convert_to_btc_on_with_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
coins = convert_to_btc_on(300, 'USD', date_obj)
self.assertEqual(type(coins), float)
def test_convert_to_btc_on_with_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, convert_to_btc_on, 300, 'XYZ', date_obj)
class TestConvertBtcToCurOn(TestCase):
"""
Convert BitCoins to valid Currency
"""
def test_convert_to_btc_on_with_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
amount = convert_btc_to_cur_on(3, 'USD', date_obj)
self.assertEqual(type(amount), float)
def test_convert_to_btc_on_with_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, convert_btc_to_cur_on, 3, 'XYZ', date_obj)
class TestBitCoinSymbol(TestCase):
"""
Bit Coin symbol
"""
def test_bitcoin_symbol(self):
self.assertEqual(get_btc_symbol(), "\u0E3F")
class TestBitCoinWithoutForceDecimal(TestCase):
def setUp(self):
self.b = BtcConverter()
def test_latest_price_valid_currency(self):
price = self.b.get_latest_price('USD')
self.assertEqual(type(price), float)
def test_latest_price_invalid_currency(self):
price = self.b.get_latest_price('XYZ')
self.assertFalse(price)
def test_previous_price_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
price = self.b.get_previous_price('USD', date_obj)
self.assertEqual(type(price), float)
def test_previous_price_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, self.b.get_previous_price, 'XYZ', date_obj)
def test_previous_price_list_with_valid_currency(self):
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
end_date = datetime.datetime.today()
price_list = self.b.get_previous_price_list('USD', start_date, end_date)
self.assertTrue(price_list)
self.assertEqual(type(price_list), dict)
def test_previous_price_list_with_invalid_currency(self):
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
end_date = datetime.datetime.today()
price_list = self.b.get_previous_price_list('XYZ', start_date, end_date)
self.assertFalse(price_list)
self.assertEqual(type(price_list), dict)
def test_convet_to_btc_with_valid_currency(self):
coins = self.b.convert_to_btc(250, 'USD')
self.assertEqual(type(coins), float)
def test_convet_to_btc_with_invalid_currency(self):
self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc, 250, 'XYZ')
def test_convert_btc_to_cur_valid_currency(self):
amount = self.b.convert_btc_to_cur(2, 'USD')
self.assertEqual(type(amount), float)
def test_convert_btc_to_cur_invalid_currency(self):
self.assertRaises(RatesNotAvailableError, self.b.convert_btc_to_cur, 2, 'XYZ')
def test_convert_to_btc_on_with_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
coins = self.b.convert_to_btc_on(300, 'USD', date_obj)
self.assertEqual(type(coins), float)
def test_convert_to_btc_on_with_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc_on, 300, 'XYZ', date_obj)
def test_convert_to_btc_on_with_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
amount = self.b.convert_btc_to_cur_on(3, 'USD', date_obj)
self.assertEqual(type(amount), float)
def test_convert_to_btc_on_with_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, self.b.convert_btc_to_cur_on, 3, 'XYZ', date_obj)
class TestBitCoinForceDecimal(TestCase):
def setUp(self):
self.b = BtcConverter(force_decimal=True)
def test_latest_price_valid_currency(self):
price = self.b.get_latest_price('USD')
self.assertEqual(type(price), Decimal)
def test_latest_price_invalid_currency(self):
price = self.b.get_latest_price('XYZ')
self.assertFalse(price)
def test_previous_price_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
price = self.b.get_previous_price('USD', date_obj)
self.assertEqual(type(price), Decimal)
def test_previous_price_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, self.b.get_previous_price, 'XYZ', date_obj)
def test_previous_price_list_with_valid_currency(self):
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
end_date = datetime.datetime.today()
price_list = self.b.get_previous_price_list('USD', start_date, end_date)
self.assertTrue(price_list)
self.assertEqual(type(price_list), dict)
def test_previous_price_list_with_invalid_currency(self):
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
end_date = datetime.datetime.today()
price_list = self.b.get_previous_price_list('XYZ', start_date, end_date)
self.assertFalse(price_list)
self.assertEqual(type(price_list), dict)
def test_convet_to_btc_with_valid_currency(self):
coins = self.b.convert_to_btc(Decimal('250'), 'USD')
self.assertEqual(type(coins), Decimal)
def test_convet_to_btc_with_invalid_currency(self):
self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc, Decimal('250'), 'XYZ')
def test_convert_btc_to_cur_valid_currency(self):
amount = self.b.convert_btc_to_cur(Decimal('2'), 'USD')
self.assertEqual(type(amount), Decimal)
def test_convert_btc_to_cur_invalid_currency(self):
self.assertRaises(RatesNotAvailableError, self.b.convert_btc_to_cur, Decimal('250'), 'XYZ')
def test_convert_to_btc_on_with_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
coins = self.b.convert_to_btc_on(Decimal('300'), 'USD', date_obj)
self.assertEqual(type(coins), Decimal)
def test_convert_to_btc_on_with_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, self.b.convert_to_btc_on, Decimal('250'), 'XYZ', date_obj)
def test_convert_to_btc_on_with_valid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
amount = self.b.convert_btc_to_cur_on(Decimal('250'), 'USD', date_obj)
self.assertEqual(type(amount), Decimal)
def test_convert_to_btc_on_with_invalid_currency(self):
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
self.assertRaises(RatesNotAvailableError, self.b.convert_btc_to_cur_on, Decimal('3'), 'XYZ', date_obj)