def test_import_rollback_batch(self): # # We split up two transactions into two batches. At some point # we figure out, that the last batch was faulty and revert it. # account = BankAccount(name='123-123', description='Test Description', currency='EUR') b1 = [ FundTransaction(description='first', amount=-2.30, effective=datetime.date.today()), ] b2 = [ FundTransaction(description='second', amount=10.02, effective=datetime.date.today()), ] self.session.add(ImportBatch(bank_account=account, transactions=b1)) self.session.add(ImportBatch(bank_account=account, transactions=b2)) self.session.commit() self.assertEqual(2, self.session.query(ImportBatch).count()) # # now roll back the last set of transactions # account.rollback_batch(self.session, 2) self.assertFalse( self.session.query(FundTransaction).filter_by(description='second').first() ) self.assertEqual(1, self.session.query(ImportBatch).count())
def client(): """ Imports new data into the given database.""" parser = _setup_commandline_arguments() arguments = parser.parse_args() engine = sqlalchemy.create_engine(arguments.database) Base.metadata.bind = engine Base.metadata.create_all(engine) Session.configure(bind=engine) session = Session() if arguments.list_accounts: names = [x.name for x in session.query(BankAccount).all()] print '\n'.join(names) if arguments.config and os.path.exists(arguments.config): fundscout.importer.config.configure_and_run(arguments.config) if arguments.csv and os.path.exists(arguments.csv): ba_name = fundscout.importer.guess_accountname_from_filename( arguments.csv) bankaccount = BankAccount.find_by_name(session, ba_name) if bankaccount is None: print 'Unable to find Bankaccount {}'.format(ba_name) else: print '{} transactions imported.'.format( fundscout.importer.import_csv(session, arguments.csv, bankaccount)) sys.exit(0)