def test_sales_unit_as_display_unit(): sales_unit = SalesUnit(decimals=3) display_unit = SalesUnitAsDisplayUnit(sales_unit) assert display_unit.internal_unit == sales_unit assert display_unit.ratio == 1 assert display_unit.decimals == sales_unit.decimals assert display_unit.comparison_value == 1 assert display_unit.allow_bare_number is False assert display_unit.default is False assert display_unit.pk is None assert display_unit == display_unit # Name and symbol should be "lazy" to allow language switch sales_unit.set_current_language('en') sales_unit.symbol = "Kg" sales_unit.name = "Kilogram" assert display_unit.name == sales_unit.name assert display_unit.symbol == sales_unit.symbol assert '{}'.format(display_unit) == sales_unit.name sales_unit.set_current_language('fi') sales_unit.name = "kilogramma" sales_unit.symbol = "kg" assert display_unit.name == sales_unit.name assert display_unit.symbol == sales_unit.symbol assert '{}'.format(display_unit) == sales_unit.name
def test_sales_unit_str(): unit = SalesUnit() assert str(unit) == "" unit.identifier = "test" assert str(unit) == "test" unit.set_current_language("en") unit.name = "en" assert str(unit) == "en" unit.set_current_language("fi") unit.name = "fi" assert str(unit) == "fi" unit.set_current_language("en") assert unit.name == "en" # test fallback unit.set_current_language("ja") assert unit.name == "en"