Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions forex_python/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ def get_rate(self, base_cur, dest_cur, date_obj=None):
raise RatesNotAvailableError("Currency Rates Source Not Ready")

def convert(self, base_cur, dest_cur, amount, date_obj=None):
if base_cur == dest_cur:
return amount
if isinstance(amount, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal

date_str = self._get_date_string(date_obj)
payload = {'base': base_cur, 'symbols': dest_cur}
source_url = self._source_url() + date_str
Expand Down
5 changes: 5 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def test_amount_convert_valid_currency(self):
# test if amount returned in float
self.assertTrue(isinstance(amount, float))

def test_amount_convert_valid_currency_same_currency(self):
amount = convert('USD', 'USD', 10)
self.assertEqual(amount, 10)


def test_amount_convert_date(self):
date_obj = datetime.datetime.strptime('2010-05-10', "%Y-%m-%d").date()
amount = convert('USD', 'INR', 10, date_obj)
Expand Down