Exemple #1
0
    def testCreate_account_and_admin_login(self):
        print("""\n=========================
UNIT TEST
testCreate_account_and_admin_login()
!!!Wait for menu to load first!!!...
<<Press 8: ACCOUNT POSITIONS>> and then
<<Press 9: GRANT ADMIN ACCESS to username "ms2020">> and then
<<Press 7 and 3 to quit>> and proceed to next test
!!!Wait for menu to load first!!!...\n""")

        account_data = Account(username="******",
                               balance=20000000,
                               first_name="John",
                               last_name="Smith",
                               email_address="*****@*****.**",
                               admin=1)
        account_data.set_password_hash("password")
        account_data.save()

        account_data2 = Account(username="******",
                                balance=20000000,
                                first_name="Mary",
                                last_name="Sue",
                                email_address="*****@*****.**",
                                admin=0)
        account_data2.set_password_hash("password")
        account_data2.save()

        account_data.buy("STOK", 100)
        account_data.buy("A33A", 300)
        account_data.sell("STOK", 50)
        account_data.buy("AAPL", 999)

        account_data2.buy("AAPL", 100)
        account_data2.sell("AAPL", 100)
        account_data2.buy("GS", 200)
        account_data2.sell("GS", 100)
        account_data2.buy("MS", 200)
        account_data2.sell("MS", 100)

        js2020 = Account.get_from_username("js2020")
        account_data = Account.login(js2020.username, "password")
        self.assertIsNotNone(account_data,
                             msg="login() should return account data")
        controller.main_menu(account_data)

        ms2020 = Account.get_from_username("ms2020")
        account_data2 = Account.login(ms2020.username, "password")
        self.assertEqual(account_data2.admin,
                         1,
                         msg="control should make this account an admin")
Exemple #2
0
def get_api_key():
    username = request.json['username']
    password = util.hash_pass(request.json['password'])
    account = Account.login(username, password)
    if not account:
        return jsonify(UNAUTHORIZED), 401
    return jsonify({"api_key": account.api_key, "username": account.username})
def viewapikey():
    if not request.json or 'username' not in request.json or 'password' not in request.json:
        print(request.json)
        return jsonify(BADREQUEST), 400

    r = request.json
    account = Account.login(r['username'], r['password'])
    return jsonify({"username": account.username, "apikey": account.api_key})
def getkey():
    if not request.json or 'username' not in request.json or 'password' not in request.json:
        return jsonify(BAD_REQUEST), 401
    account = Account.login(request.json['username'], request.json['password'])
    if not account:
        return jsonify(UNAUTHORIZED), 401
    rdict = {'api_key': account.api_key, 'username': account.username}
    print(rdict)
    return jsonify(rdict)
Exemple #5
0
def login():
    if not request.json or 'username' not in request.json or 'password' not in request.json:
        return jsonify(BAD_REQUEST), 401
    account = Account.login(request.json['username'], request.json['password'])
    if not account:
        return jsonify(UNAUTHORIZED), 401
    token = encodeAuthToken(account.pk)
    return jsonify({
        'status': 'success',
        'auth_token': str(token),
        'api_key': account.api_key
    })
Exemple #6
0
def login():
    if request.method == 'GET':
        return render_template('login.html')
    elif request.method == 'POST':
        session['username'] = request.form['uname']
        session['password'] = util.hash_pass(request.form['pword'])
        account = Account.login(session['username'], session['password'])
        if account == None:
            return render_template('login.html', error=view.invalid_info())
        else:
            session['api_key'] = account.api_key
            return render_template('dashboard.html', Username=session['username'])
Exemple #7
0
    def testCreate_account_and_nonadmin_login(self):
        print("""\n=========================
UNIT TEST
testCreate_account_and_nonadmin_login()
<<Press 7 and 3 to quit>> and proceed to next test\n""")

        account_data = Account(username="******",
                               balance=20000000,
                               first_name="John",
                               last_name="Smith",
                               email_address="*****@*****.**",
                               admin=0)
        account_data.set_password_hash("password")
        account_data.save()

        js2020 = Account.get_from_username("js2020")
        account_data = Account.login(js2020.username, "password")
        print("TRCR test_controller.py account_data\n", account_data)
        self.assertIsNotNone(account_data,
                             msg="login() should return account data")
        controller.main_menu(account_data)
Exemple #8
0
 def test_login(self):
     mike_bloom = Account.login("mike_bloom", 'password')
     self.assertIsNotNone(mike_bloom, "account and password find data")
     self.assertIsInstance(mike_bloom, Account,
                           "login returns Account object")
     self.assertEqual(mike_bloom.balance, 10000.00)
 def test_login(self):
     mike = Account.login("mike_bloom", "password")
     self.assertIsNotNone(mike, "account and password find data")
     self.assertIsInstance(mike, Account)
     self.assertEqual(mike.balance, 10000.00)
    def test_login(self):
        mike_bloom = Account.login('mike_bloom', 'password')

        self.assertIsNotNone(mike_bloom, "account & password find row")

        self.assertIsInstance(mike_bloom, Account, "login returns an account")