def scenario(session, new_user): data_1 = dict(user_id=new_user.id, reference='000051', account='C00099', date='2020-01-03', amount=-51.13, type='outflow', category='groceries') data_2 = dict(user_id=new_user.id, reference='000052', account='C00099', date='2020-01-10', amount=2500.72, type='inflow', category='salary') data_3 = dict(user_id=new_user.id, reference='000053', account='C00099', date='2020-01-10', amount=-150.72, type='outflow', category='transfer') data_4 = dict(user_id=new_user.id, reference='000054', account='C00099', date='2020-01-13', amount=-560.00, type='outflow', category='rent') data_5 = dict(user_id=new_user.id, reference='000689', account='S00012', date='2020-01-10', amount=150.72, type='inflow', category='savings') Transaction.create_bulk(db_session=session, data=[data_1, data_2, data_3, data_4, data_5])
def test_transaction_create_bulk_ok(session, new_user): count1 = session.query(Transaction).count() data_1 = dict( user_id=new_user.id, reference='reference1', account='account', date='2020-02-02', amount=1.00, type='inflow', category='category', ) data_2 = dict( user_id=new_user.id, reference='reference2', account='account', date='2020-02-02', amount=1.00, type='inflow', category='category', ) Transaction.create_bulk(db_session=session, data=[data_1, data_2]) count2 = session.query(Transaction).count() assert count1 + 2 == count2
def post_transactions(*, db_session: Session = Depends(get_db), payload: TransactionPostList) -> List[TransactionGet]: user = User.get_user_by_name(db_session=db_session, name=payload.name) if user is None: raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=messages.USER_NOT_FOUND) data = [] references_db = Transaction.get_referencez(db_session=db_session) for transaction in payload.transactions: if transaction.reference not in references_db: transaction.user_id = user.id references_db.append(transaction.reference) data.append(dict(transaction)) return Transaction.create_bulk(db_session=db_session, data=data)