def test_withdraw_25000_not_enough_10000_and_20000():
    amount = 25000
    stub_bills = [
        StubBill(3, 5000, 10),
        StubBill(5, 10000, 0),
        StubBill(1, 20000, 0),
        StubBill(4, 2000, 0),
    ]

    res = atm_controller.withdraw(amount, stub_bills)

    assert res['is_success'] == True
    assert res['20000'] == 0
    assert res['10000'] == 0
    assert res['5000'] == 5
    assert res['2000'] == 0
def test_withdraw_1000():
    amount = 1000
    stub_bills = [
        StubBill(3, 5000, 10),
        StubBill(5, 10000, 10),
        StubBill(1, 20000, 10),
        StubBill(4, 2000, 10),
    ]

    res = atm_controller.withdraw(amount, stub_bills)

    assert res['is_success'] == False
    assert res['20000'] == 0
    assert res['10000'] == 0
    assert res['5000'] == 0
    assert res['2000'] == 0
Beispiel #3
0
def withdraw():
    if request.method == "POST":
        time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        amount = int(request.json['amount'])
        bills = Bill.query.all()
        withdraw_action = atm_controller.withdraw(amount, bills)

        if withdraw_action['is_success']:
            for key, value in withdraw_action.items():
                if str(key).isdigit():
                    bill = [bill for bill in bills if bill.value == int(key)][0]
                    bill.quantity = bill.quantity - value

            add_transaction_to_db_session(time, amount, SUCCESS, db)
            db.session.commit()
            return withdraw_action

        else:
            add_transaction_to_db_session(time, amount, FAILURE, db)
            db.session.commit()
            return withdraw_action