Skip to content

Commit 004eb12

Browse files
author
ravigadila
committed
fixed converter error calling with samecurrency
1 parent b23daa1 commit 004eb12

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

forex_python/converter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ def get_rate(self, base_cur, dest_cur, date_obj=None):
6969
raise RatesNotAvailableError("Currency Rates Source Not Ready")
7070

7171
def convert(self, base_cur, dest_cur, amount, date_obj=None):
72+
if base_cur == dest_cur:
73+
return amount
7274
if isinstance(amount, Decimal):
7375
use_decimal = True
7476
else:
7577
use_decimal = self._force_decimal
78+
7679
date_str = self._get_date_string(date_obj)
7780
payload = {'base': base_cur, 'symbols': dest_cur}
7881
source_url = self._source_url() + date_str

tests/test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def test_amount_convert_valid_currency(self):
7474
# test if amount returned in float
7575
self.assertTrue(isinstance(amount, float))
7676

77+
def test_amount_convert_valid_currency_same_currency(self):
78+
amount = convert('USD', 'USD', 10)
79+
self.assertEqual(amount, 10)
80+
81+
7782
def test_amount_convert_date(self):
7883
date_obj = datetime.datetime.strptime('2010-05-10', "%Y-%m-%d").date()
7984
amount = convert('USD', 'INR', 10, date_obj)

0 commit comments

Comments
 (0)