Skip to content

Commit a55d071

Browse files
author
ravi
committed
Test cases for bit coin conversion
1 parent 8c1c8cd commit a55d071

2 files changed

Lines changed: 123 additions & 2 deletions

File tree

tests/test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import datetime
22
from unittest import TestCase
3-
from forex_python.converter import CurrencyRates, CurrencyCodes
4-
from forex_python.converter import RatesNotAvailableError
3+
from forex_python.converter import CurrencyRates, CurrencyCodes, RatesNotAvailableError
54

65

76
class TestGetRates(TestCase):

tests/test_bitcoin.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import datetime
2+
from unittest import TestCase
3+
from forex_python.bitcoin import BtcConverter
4+
5+
6+
class TestCommon(TestCase):
7+
"""
8+
Common class with setUp method for all test cases
9+
"""
10+
def setUp(self):
11+
self.b = BtcConverter()
12+
13+
14+
class TestLatestPrice(TestCommon):
15+
"""
16+
Test get latest price using currency code
17+
"""
18+
def test_latest_price_valid_currency(self):
19+
price = self.b.get_latest_price('USD')
20+
self.assertEqual(type(price), float)
21+
22+
def test_latest_price_invalid_currency(self):
23+
price = self.b.get_latest_price('XYZ')
24+
self.assertFalse(price)
25+
26+
27+
class TestPreviousPrice(TestCommon):
28+
"""
29+
Test Price with date input
30+
"""
31+
def test_previous_price_valid_currency(self):
32+
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
33+
price = self.b.get_previous_price('USD', date_obj)
34+
self.assertEqual(type(price), float)
35+
36+
def test_previous_price_invalid_currency(self):
37+
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
38+
price = self.b.get_previous_price('XYZ', date_obj)
39+
self.assertFalse(price)
40+
41+
42+
class TestPreviousPriceList(TestCommon):
43+
"""
44+
Test previous price list for a currency
45+
"""
46+
def test_previous_price_list_with_valid_currency(self):
47+
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
48+
end_date = datetime.datetime.today()
49+
price_list = self.b.get_previous_price_list('USD', start_date, end_date)
50+
self.assertTrue(price_list)
51+
self.assertEqual(type(price_list), dict)
52+
53+
def test_previous_price_list_with_invalid_currency(self):
54+
start_date = datetime.datetime.today() - datetime.timedelta(days=15)
55+
end_date = datetime.datetime.today()
56+
price_list = self.b.get_previous_price_list('XYZ', start_date, end_date)
57+
self.assertFalse(price_list)
58+
self.assertEqual(type(price_list), dict)
59+
60+
61+
class TestConvertBtc(TestCommon):
62+
"""
63+
Test Converting amount to Bit coins
64+
"""
65+
def test_convet_to_btc_with_valid_currency(self):
66+
coins = self.b.convert_to_btc(250, 'USD')
67+
self.assertEqual(type(coins), float)
68+
69+
def test_convet_to_btc_with_invalid_currency(self):
70+
coins = self.b.convert_to_btc(250, 'XYZ')
71+
self.assertFalse(coins)
72+
73+
74+
class TestConvertBtcToCur(TestCommon):
75+
"""
76+
Convert Bit Coins to Valid Currency amount
77+
"""
78+
def test_convert_btc_to_cur_valid_currency(self):
79+
amount = self.b.convert_btc_to_cur(2, 'USD')
80+
self.assertEqual(type(amount), float)
81+
82+
def test_convert_btc_to_cur_invalid_currency(self):
83+
amount = self.b.convert_btc_to_cur(2, 'XYZ')
84+
self.assertFalse(amount)
85+
86+
87+
class TestConvertToBtcOn(TestCommon):
88+
"""
89+
Convert To bit coin based on previous dates
90+
"""
91+
def test_convert_to_btc_on_with_valid_currency(self):
92+
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
93+
coins = self.b.convert_to_btc_on(300, 'USD', date_obj)
94+
self.assertEqual(type(coins), float)
95+
96+
def test_convert_to_btc_on_with_invalid_currency(self):
97+
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
98+
coins = self.b.convert_to_btc_on(300, 'XYZ', date_obj)
99+
self.assertFalse(coins)
100+
101+
102+
class TestConvertBtcToCurOn(TestCommon):
103+
"""
104+
Convert BitCoins to valid Currency
105+
"""
106+
def test_convert_to_btc_on_with_valid_currency(self):
107+
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
108+
amount = self.b.convert_btc_to_cur_on(3, 'USD', date_obj)
109+
self.assertEqual(type(amount), float)
110+
111+
def test_convert_to_btc_on_with_invalid_currency(self):
112+
date_obj = datetime.datetime.today() - datetime.timedelta(days=15)
113+
amount = self.b.convert_btc_to_cur_on(3, 'XYZ', date_obj)
114+
self.assertFalse(amount)
115+
116+
117+
class TestBitCoinSymbol(TestCommon):
118+
"""
119+
Bit Coin symbol
120+
"""
121+
def test_bitcoin_symbol(self):
122+
self.assertEqual(self.b.get_symbol(), "\u0E3F")

0 commit comments

Comments
 (0)