def create_default_set(): """Create three new stocks and add them to the database""" stock1 = Stock('HD', '25', '247.29') stock2 = Stock('TWTR', '230', '31.89') stock3 = Stock('DIS', '65', '118.77') database.session.add(stock1) database.session.add(stock2) database.session.add(stock3) database.session.commit()
def add_stock(): if request.method == 'POST': # Save the form data to the database if current_user.has_funds(request.form['purchase_price'], request.form['number_of_shares']): new_stock = Stock( request.form['stock_symbol'], request.form['number_of_shares'], request.form['purchase_price'], current_user.id, datetime.fromisoformat(request.form['purchase_date'])) database.session.add(new_stock) database.session.commit() current_user.subtract_funds(request.form['purchase_price'], request.form['number_of_shares']) database.session.add(current_user) database.session.commit() flash(f"Added new stock ({ request.form['stock_symbol'] })!", 'success') current_app.logger.info( f"Added new stock ({ request.form['stock_symbol'] })!") return redirect(url_for('stocks.list_stocks')) else: flash(f"Not Enough Funds To Add Stock!", 'error') current_app.logger.info(f"Not Enough Funds To Add Stock!") return render_template('stocks/add_stock.html') else: return render_template('stocks/add_stock.html')
def test_new_stock(new_stock): """ GIVEN a Stock model WHEN a new Stock object is created THEN check the symbol, number of shares, and purchase price fields are defined correctly """ stock = Stock('GEX', '16', '406.78') assert stock.stock_symbol == 'GEX' assert stock.number_of_shares == 16 assert stock.purchase_price == 40678
def add_stock(): if request.method == 'POST': new_stock = Stock(request.form['stock_symbol'], request.form['number_of_shares'], request.form['purchase_price']) database.session.add(new_stock) database.session.commit() flash(f"Added new stock ({ request.form['stock_symbol'] })", 'success') current_app.logger.info( f"Added new stock ({ request.form['stock_symbol'] })!") return redirect(url_for('stocks.list_stocks')) else: return render_template('stocks/add_stock.html')
def create(symbol, number_of_shares, purchase_price): """Create a new stock and add it to the database""" stock = Stock(symbol, number_of_shares, purchase_price) database.session.add(stock) database.session.commit()
def create(symbol, number_of_shares, purchase_price): "Create new stock and add to db" stock = Stock(symbol, number_of_shares, purchase_price) database.session.add(stock) database.session.commit()
def new_stock(): stock = Stock('AAPL', '16', '406.78', 17, datetime.datetime(2020, 7, 10)) return stock
def new_stock(): stock = Stock('GEX', '16', '406.78') return stock
def new_stock(): stock = Stock('AAPL', '16', '406.78') return stock