def test_transactions(client: TestClient, db: Session) -> None: wallet = crud.wallet.create(db) deposit_wallet(db=db, wallet=wallet, amount=Decimal("1.1")) db.commit() response = client.get(f"wallets/{wallet.id}/transactions/") assert response.status_code == 200 assert response.text == f"amount,datetime\n1.1,{wallet.transactions[0].datetime}"
def test_zero_deposit(db: Session) -> None: wallet = Wallet(balance=0.1) db.add(wallet) db.commit() with pytest.raises(IntegrityError): deposit_wallet(db, wallet=wallet, amount=Decimal("0")) Session.rollback(db)
def test_negative_deposit(db: Session) -> None: wallet = Wallet(balance=0.1) db.add(wallet) db.commit() wallet_id = wallet.id with pytest.raises(IntegrityError): deposit_wallet(db, wallet=wallet, amount=Decimal("-0.2")) Session.rollback(db) wallet = db.query(Wallet).get(wallet_id) assert wallet.balance == Decimal("0.1") assert len(wallet.transactions) == 0
def test_wallet_deposit(db: Session) -> None: wallet = Wallet(balance=0.1) db.add(wallet) db.commit() wallet = deposit_wallet(db, wallet=wallet, amount=Decimal("0.2")) assert wallet.balance == Decimal("0.3") assert wallet.transactions[0].amount == Decimal("0.2")
def deposit( *, db: Session = Depends(deps.get_db), id: int, deposit_in: schemas.WalletDeposit, ) -> Any: """ Deposit wallet """ wallet = crud.wallet.get_for_update(db=db, id=id) if not wallet: raise HTTPException(status_code=404, detail="Wallet not found") wallet = deposit_wallet(db=db, wallet=wallet, amount=deposit_in.amount) return wallet