From 004eb1229303fd60d87d8af01b514ea42e3da4a2 Mon Sep 17 00:00:00 2001 From: ravigadila Date: Fri, 24 Feb 2017 21:28:37 +0530 Subject: [PATCH] fixed converter error calling with samecurrency --- forex_python/converter.py | 3 +++ tests/test.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/forex_python/converter.py b/forex_python/converter.py index 774e294..bcc8348 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -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 diff --git a/tests/test.py b/tests/test.py index b025218..040ed75 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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)