コード例 #1
0
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}"
コード例 #2
0
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)
コード例 #3
0
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
コード例 #4
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")
コード例 #5
0
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