Ejemplo n.º 1
0
 def setUp(self):
     if os.path.exists(Account.filepath):
         os.unlink(Account.filepath)
     greg = Account("Greg")
     greg.balance = 10.50
     greg.pin = "1234"
     greg.save()
Ejemplo n.º 2
0
def login_menu():
    while True:
        try:
            user_input = view.login_menu()
            if int(user_input) == 3:
                view.program_end()
                sys.exit()
            elif int(user_input) == 2:
                username = view.username_inpt()
                pwd = util.hash_pass(view.password_inpt())
                user = Account.login(username, pwd)
                if user == None:
                    view.invalid_info()
                    return login_menu()
                return user
            elif int(user_input) == 1:
                user = Account()
                user.username = view.username_inpt()
                user.set_password(util.hash_pass(view.set_password_inpt()))
                user.balance = view.deposit_inpt()
                user.save()
                view.acc_created(user.username)
                return user
        except ValueError:
            view.choose_valid()
Ejemplo n.º 3
0
    def test_user_can_withdraw_amount_not_in_account(self):
        # Arrange
        account = Account("Alan", "33")
        account.balance = 100
        expected_result = "Sorry insufficent funds"

        # Act
        observed = account.withdraw(101)

        # Assert
        self.assertEqual(observed, expected_result)
Ejemplo n.º 4
0
    def test_user_can_withdraw_amount_in_account(self):
        # Arrange
        account = Account("Alan", "33")
        account.balance = 200
        expected_result = 100

        # Act
        account.withdraw(100)
        observed = account.balance

        # Assert
        self.assertEqual(observed, expected_result)
Ejemplo n.º 5
0
def create_account_selection():
    while True:
        newuser = Account()
        view.enter_user_name()
        username = input()
        newuser.username = username
        view.enter_password()
        password = getpass.getpass()
        newuser.origpassword = password
        newuser.set_password(password)
        #newuser.apikey=20
        newuser.set_apikey()
        newuser.balance = 0.00
        newuser.save()
        view.account_success_message()
        return newuser
Ejemplo n.º 6
0
def main_loop():
    while True:
        choice = user_menu()
        if choice is None: # incorrect selection
            bad_input('Please select option')
        elif choice == '4': # exit
            goodbye()
            break

        elif choice == '1':
            login_input = login_username_pw()
            verified_account = Account.login(login_input)
            if verified_account:
                db_password_hash = verified_account[2]
                password_verify = checkpw(login_input[1].encode(),
                    db_password_hash)
                if password_verify:
                    account = Account(account_id = verified_account[0])
                    account.username = verified_account[1]
                    account.balance = int(verified_account[3])
                    while True:
                        choice = main_menu()
                        if choice is None:
                            bad_input('Please select option')
                        elif choice == '1': # view account balance
                            display_balance(account.balance)
                        elif choice == '2': # deposit funds
                            account.balance += deposit()
                            Account.update_balance(account)
                        elif choice == '3': # buy stock
                            buy_stock = trade_stock()
                            account.buy(buy_stock[0], buy_stock[1])
                        elif choice == '4': #sell stock
                            buy_stock = trade_stock()
                            account.sell(buy_stock[0], buy_stock[1])
                        elif choice == '5': # view positions
                            display_positions(Account.get_positions(account))
                        elif choice == '6': # view trades
                            display_trade_history(Account.get_trades(account))
                        elif choice == '7': # lookup price of stock
                            ticker = view.lookup_ticker()
                            print("Ticker: {} is currently: ${}".format(ticker, get_price(ticker)))
                        elif choice == '8': # See API Keys
                            display_api(Account.retrieve_api_key(account))
                        elif choice == '9': # logout
                            goodbye()
                        else:
                            bad_input('Retry')
                else:
                    bad_input('Incorrect password')
            else:
                bad_input('Incorrect username')
        elif choice == '2': # login with api
            user_api_key = login_api_key()
            # print(user_api_key)
            user = Account.api_authenticate(user_api_key)
            display_user_from_api_key(user)
        elif choice == '3': # create new account
            account_details[0] = "mark"
            account_details[1] = "1234"
            account_details[2] = 1000
            account_details = create_account()
            account = Account()
            account.username = account_details[0]
            account.password_hash = account_details[1]
            account.balance = account_details[2]
            account.api_key = account.generate_api_key()
            Account.save(account)
Ejemplo n.º 7
0
 def testSave(self):
     greg = Account("Greg")
     greg.balance = 10000.90
     greg.save()
     newgreg = Account("Greg")
     self.assertEqual(newgreg.balance, 10000.90)
Ejemplo n.º 8
0
 def testDeposit(self):
     greg = Account("Greg")
     greg.balance = 5002.00
     greg.deposit(5000.00)
     self.assertEqual(greg.balance, 10002.00)
Ejemplo n.º 9
0
 def testWithdraw(self):
     greg = Account("Greg")
     greg.balance = 5002.00
     greg.withdraw(5000.00)
     self.assertEqual(greg.balance, 2.00)