def test_json_conversion_connectentry(): """Test the json conversion.""" # init the individual object a = ConnectEntry(title='Total individual', comment='Individual comment!', quantity=1.23, quantity_format='{F}:{R} min', is_time=True, multiplicator=9.99) c = BaseEntry() a.connect_entry([a, c], c.get_id()) assert c.get_id() in a.get_connected() assert a.get_id() not in a.get_connected() # make new default object b = ConnectEntry() # 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_is_time() != a.get_is_time() assert b.get_multiplicator() != a.get_multiplicator() assert b.get_connected() != a.get_connected() # load a into b with json as object with same attributes b = ConnectEntry().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_is_time() == a.get_is_time() assert b.get_multiplicator() == a.get_multiplicator() assert b.get_connected() == a.get_connected() # load a into b with json as a preset (don't keep the id) b = ConnectEntry().from_json(js=a.to_json(), keep_id=False) # now the values must be the same - preset alike assert b.get_id() != a.get_id( ) # except the id, since it's "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_is_time() == a.get_is_time() assert b.get_multiplicator() == a.get_multiplicator() assert b.get_connected() == a.get_connected()
def test_copy_entry(): """Copy an entry.""" ac = BaseEntry() bc = ac.copy() # by default copy does keep the ID assert ac.get_id() == bc.get_id() bc = ac.copy(keep_id=False) # now bc is a copy of ac, but with its own ID assert ac.get_id() != bc.get_id()
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()