diff --git a/forex_python/converter.py b/forex_python/converter.py index bcc8348..316f0cf 100644 --- a/forex_python/converter.py +++ b/forex_python/converter.py @@ -56,6 +56,8 @@ def get_rates(self, base_cur, date_obj=None): raise RatesNotAvailableError("Currency Rates Source Not Ready") def get_rate(self, base_cur, dest_cur, date_obj=None): + if base_cur == dest_cur: + return 1. 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 040ed75..2501aa9 100644 --- a/tests/test.py +++ b/tests/test.py @@ -50,6 +50,11 @@ def test_get_rate_with_valid_codes(self): # check if return value is float self.assertTrue(isinstance(rate, float)) + + def test_get_rate_with_valid_codes_same_currency(self): + rate = get_rate('USD', 'USD') + # rate should be 1. + self.assertEqual(1., rate) def test_get_rate_with_date(self): date_obj = datetime.datetime.strptime('2010-05-10', "%Y-%m-%d").date()