def test_baseentry_set_price(): """Set the price for BaseEntry.""" a = BaseEntry(quantity=1) a.set_price(3) # integer gets two decimal after comma assert a.get_price() == Decimal('3.00') # price should not changed due to wrong input a.set_price('pupsen') assert a.get_price() == Decimal('3.00')
def test_unit_price(): """Test unit price and unit price tax methods.""" # BaseEntry a_unitp = BaseEntry(quantity=2, price=100) assert a_unitp.get_price() == Decimal('200.00') assert a_unitp.get_unit_price() == Decimal('100.00') # MultiplyEntry b_unitp = MultiplyEntry(quantity=2, hour_rate='0:30') assert b_unitp.get_price(wage=Decimal('50.00')) == Decimal('50.00') assert b_unitp.get_unit_price(wage=Decimal('50.00')) == Decimal('25.00') # ConnectEntry c_unitp = ConnectEntry(quantity=3, multiplicator=2) # list creation liste = [] liste.append(b_unitp) liste.append(c_unitp) # linking liste[1].connect_entry(entry_list=liste, entry_id=liste[0].get_id()) assert c_unitp.get_price(entry_list=liste, wage=Decimal('50.00')) == Decimal('300.00') assert c_unitp.get_unit_price(entry_list=liste, wage=Decimal('50.00')) == Decimal('100.00')
def test_json_conversion_baseentry(): """Test the json conversion.""" # init the individual object a = BaseEntry(title='Total individual', comment='Individual comment!', quantity=1.25, quantity_format='{F}:{R} min', time='1:45', price=1000) # make new default object b = BaseEntry() # for now the values must not be the same assert b.get_id() != a.get_id() assert b.title != a.title assert b.comment != a.comment assert b.get_quantity() != a.get_quantity() assert b.quantity_format != a.quantity_format assert b.get_time() != a.get_time() assert b.get_price() != a.get_price() # load a into b with json as object with same attrbutes b = BaseEntry().from_json(js=a.to_json()) # now the values must be the same assert b.get_id() == a.get_id() assert b.title == a.title assert b.comment == a.comment assert b.get_quantity() == a.get_quantity() assert b.quantity_format == a.quantity_format assert b.get_time() == a.get_time() assert b.get_price() == a.get_price() # load a into b with json as preset b = BaseEntry().from_json(js=a.to_json(), keep_id=False) # now the values must be the same assert b.get_id() != a.get_id() # not same, since "preset loading" assert b.title == a.title assert b.comment == a.comment assert b.get_quantity() == a.get_quantity() assert b.quantity_format == a.quantity_format assert b.get_time() == a.get_time() assert b.get_price() == a.get_price()