diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py index 181f07257b..d4c9df380f 100644 --- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py +++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py @@ -6,15 +6,42 @@ from __future__ import unicode_literals import frappe, unittest test_records = frappe.get_test_records('Currency Exchange') + +def save_new_records(test_records): + for record in test_records: + kwargs = dict( + doctype=record.get("doctype"), + docname=record.get("date") + '-' + record.get("from_currency") + '-' + record.get("to_currency"), + fieldname="exchange_rate", + value=record.get("exchange_rate"), + ) + + try: + frappe.set_value(**kwargs) + except frappe.DoesNotExistError: + curr_exchange = frappe.new_doc(record.get("doctype")) + curr_exchange.date = record["date"] + curr_exchange.from_currency = record["from_currency"] + curr_exchange.to_currency = record["to_currency"] + curr_exchange.exchange_rate = record["exchange_rate"] + curr_exchange.insert() + + class TestCurrencyExchange(unittest.TestCase): def test_exchnage_rate(self): from erpnext.setup.utils import get_exchange_rate - - # Exchange rate as on 15th Jan, 2016, should be fetched from Currency Exchange record - exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15") + + save_new_records(test_records) + + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01") self.assertEqual(exchange_rate, 60.0) + + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15") + self.assertEqual(exchange_rate, 65.1) + + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30") + self.assertEqual(exchange_rate, 62.9) # Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15") - self.assertFalse(exchange_rate==60) - \ No newline at end of file + self.assertFalse(exchange_rate==60) \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange/test_records.json b/erpnext/setup/doctype/currency_exchange/test_records.json index 23edd8a799..d2f658b443 100644 --- a/erpnext/setup/doctype/currency_exchange/test_records.json +++ b/erpnext/setup/doctype/currency_exchange/test_records.json @@ -19,5 +19,19 @@ "exchange_rate": 0.0167, "from_currency": "INR", "to_currency": "USD" + }, + { + "doctype": "Currency Exchange", + "date": "2016-01-10", + "exchange_rate": 65.1, + "from_currency": "USD", + "to_currency": "INR" + }, + { + "doctype": "Currency Exchange", + "date": "2016-01-30", + "exchange_rate": 62.9, + "from_currency": "USD", + "to_currency": "INR" } ] \ No newline at end of file