import xhiveframework
from xhiveframework import format
from xhiveframework.tests.utils import XhiveFrameworkTestCase


class TestFormatter(XhiveFrameworkTestCase):
	def test_currency_formatting(self):
		df = xhiveframework._dict({"fieldname": "amount", "fieldtype": "Currency", "options": "currency"})

		doc = xhiveframework._dict({"amount": 5})
		xhiveframework.db.set_default("currency", "INR")

		# if currency field is not passed then default currency should be used.
		self.assertEqual(format(100000, df, doc, format="#,###.##"), "₹ 100,000.00")

		doc.currency = "USD"
		self.assertEqual(format(100000, df, doc, format="#,###.##"), "$ 100,000.00")

		xhiveframework.db.set_default("currency", None)
