def test_ledger_action_can_be_edited(database, function_scope_messages_aggregator): db = DBLedgerActions(database, function_scope_messages_aggregator) query = 'SELECT * FROM ledger_actions WHERE identifier=?' cursor = database.conn.cursor() # Add the entry that we want to edit action = LedgerAction( identifier=0, # whatever timestamp=1, action_type=LedgerActionType.INCOME, location=Location.EXTERNAL, amount=FVal(1), asset=A_ETH, rate=None, rate_asset=None, link=None, notes=None, ) identifier = db.add_ledger_action(action) # Data for the new entry new_entry = LedgerAction( identifier=identifier, timestamp=2, action_type=LedgerActionType.GIFT, location=Location.EXTERNAL, amount=FVal(3), asset=A_ETH, rate=FVal(100), rate_asset=A_USD, link='foo', notes='updated', ) assert db.edit_ledger_action(new_entry) is None # Check that changes have been committed cursor.execute(query, (identifier, )) updated_entry = LedgerAction.deserialize_from_db(cursor.fetchone()) new_entry.identifier = identifier assert updated_entry == new_entry # now try to see if the optional assets can also be set to None new_entry.rate = new_entry.rate_asset = new_entry.link = new_entry.notes = None assert db.edit_ledger_action(new_entry) is None cursor.execute(query, (identifier, )) updated_entry = LedgerAction.deserialize_from_db(cursor.fetchone()) assert updated_entry.rate is None assert updated_entry.rate_asset is None assert updated_entry.link is None assert updated_entry.notes is None
def test_ledger_action_can_be_edited(database, function_scope_messages_aggregator): db = DBLedgerActions(database, function_scope_messages_aggregator) query = 'SELECT * FROM ledger_actions WHERE identifier=?' cursor = database.conn.cursor() # Add the entry that we want to edit identifier = db.add_ledger_action( timestamp=1, action_type=LedgerActionType.INCOME, location=Location.EXTERNAL, amount=FVal(1), asset=A_ETH, link='', notes='', ) # Data for the new entry new_entry = LedgerAction( identifier=identifier, timestamp=2, action_type=LedgerActionType.GIFT, location=Location.EXTERNAL, amount=FVal(3), asset=A_ETH, link='', notes='updated', ) assert db.edit_ledger_action(new_entry) is None # Check that changes have been committed cursor.execute(query, (identifier, )) updated_entry = LedgerAction(*cursor.fetchone()) assert updated_entry.timestamp == new_entry.timestamp assert str(updated_entry.amount) == str(new_entry.amount) assert updated_entry.action_type == new_entry.action_type.serialize_for_db( )