Ejemplo n.º 1
0
    def test_get_users_stocks(self):
        """tests that get_user_stocks function returns a tuple with flaskSQL object, value for current val and initial val"""

        returned = User_Stock.get_users_stocks(user_id=self.u.id)
        # checks a value is returned for total initial val is greater then the default 0
        self.assertTrue(returned[1] > 0)
        # checks a value is returned for total current val is greater then the default 0
        self.assertTrue(returned[2] > 0)
        # checks that the original stock is returned
        self.assertIn(returned[0][0].stock_symbol, self.u_stock.stock_symbol)
Ejemplo n.º 2
0
    def test_get_users_stocks_invalidID(self):
        """tests that get_user_stocks function returns a tuple with flaskSQL object, value for current val and initial val"""

        returned = User_Stock.get_users_stocks(123555)
        # checks a value is returned for total initial val is greater then the default 0
        self.assertTrue(returned[1] == 0)
        # checks a value is returned for total current val is greater then the default 0
        self.assertTrue(returned[2] == 0)
        # checks that an index error is returned if a user can't be found
        with self.assertRaises(IndexError):
            returned[0][0]
Ejemplo n.º 3
0
def portfolio():
    """user portfolio page"""

    # newStockForm is displayed as a Modal in the html
    form = NewStockForm()
    # editStockForm is displayed as a Modal in the html
    edit_stock_form = EditStock()
    # used to fill table
    stock_details = User_Stock.get_users_stocks(current_user.id)

    return render_template('user/portfolio.html', form=form, stock_details=stock_details, edit_stock_form=edit_stock_form)
Ejemplo n.º 4
0
def send_portfolio():
    """send portfolio via email route"""

    # get details to send
    stock_details = User_Stock.get_users_stocks(current_user.id)

    # craft message
    msg = Message('Portfolio SnapShot', sender=MAIL_USER, recipients=[current_user.email])
    msg.html = render_template(
        'user/_portfolio_summary.html', stock_details=stock_details)
    # send message with flask-mail
    mail.send(msg)
    flash(f"Portfolio Snap Shot Sent", "success")

    return redirect(url_for('portfolio'))
Ejemplo n.º 5
0
def company_details(stock_symbol):
    """generate company details route"""
    # check user stocks
    stock_arr = []
    if (current_user.is_authenticated):
        stock_details = User_Stock.get_users_stocks(current_user.id)
        
        for details in stock_details[0]:
            stock_arr.append(details.stock_symbol)
    
    # newStockForm is displayed as a Modal in the html
    form = NewStockForm()

    # check DB for stock
    returned_stock_details = Stock.query.get(stock_symbol)
    if returned_stock_details:
        company_name = returned_stock_details.stock_name
        # render template
        return render_template('/stock/detailed_stock_view.html', stock_symbol=stock_symbol, company_name=company_name, stock_arr=stock_arr, form=form)
    
    # if company was not found in DB - search API for stock symbol
    returned_stock_details = User_Stock.add_stock_symbol(stock_symbol)
    # if stock symbol returned true (stock found and added to our DB)
    if returned_stock_details:
        # add stock basic details to DB
        returned_stock_details = Stock.add_stock_details(stock_symbol)
        company_name = returned_stock_details.stock_name
        # render template
        return render_template('/stock/detailed_stock_view.html', stock_symbol=stock_symbol, company_name=company_name, stock_arr=stock_arr, form=form)

    # if stock symbol returned false (stock not found in API)
    flash('Stock was not found', 'warning')
    
    db.session.rollback()
    if not (current_user.is_active):
        return redirect(url_for('homepage'))

    return redirect(url_for('portfolio'))