def test_xact_model(self): # new xacts can be added acct_id = Acct.by_user_id(1)[0].id count = len(Xact.by_filter('')) xact_id = Xact.new(acct_id, 'test transaction', 1.00) self.assertEqual(xact_id, count + 1)
def test_register_user(self): # create new user user_id = User.new('username', 'password') # validate user receives one account accts = Acct.by_user_id(user_id) self.assertEqual(len(accts), 1) # validate user's account starts with 2 transactions # 1. Starting Balance 0.00 # 2. New Account Offer 1337.00 xacts = Xact.by_acct_id(accts[0].id) self.assertEqual(len(xacts), 2)
def index(): acct = None xacts = None u = User.by_id(current_user.get_id()) if u is not None: acct = Acct.by_user_id(u.id)[0] xacts = Xact.by_acct_id(acct.id) # calculate running balance balance = acct.balance for i, x in enumerate(xacts): x.balance = balance balance -= x.amount return render_template("index.html", acct=acct, xacts=xacts)
def admin(): if not current_user.is_admin(): flash( "Access Denied - This infraction has been reported to the cyber police.", "failure") return redirect(url_for(".index")) users = User.by_filter('') accts = Acct.by_filter('') for a in accts: u = User.by_id(a.user) a.user_name = u.name xacts = Xact.by_acct_id(a.id) a.count = len(xacts) return render_template("admin.html", user=current_user, users=users, accts=accts)
def acct(acct_id): if acct_id == '': acct = Acct.by_user_id(current_user.id)[0] else: try: q = "SELECT * from accts WHERE acct_id = '%s'" % acct_id row = db.get(q) if row is None: return 'sql: no rows in result set' acct = Acct._from_row(row) except Exception as e: err = { 'query': q, 'error': repr(e), } return jsonify(err) xacts = Xact.by_acct_id(acct.id) data = [u.__dict__ for u in xacts] return jsonify(data)
def test_transfer_success(self): self.login(userName, userPass) # Click 'Transfer' self.driver.find_element_by_id("btnTransfer").click() time.sleep(loadWait) # Assert that browser redirects to edit page assert url_for('.xfer') in self.driver.current_url # Transfer details xferMemo = 'wubba lubba dub dub!' xferAmount = '9447.00' # Perform the transfer acct_id = self.transfer(2, xferMemo, xferAmount) # Validate transaction appears on index page. assert xferMemo in self.driver.find_element_by_id("xfer-table").text # Validate transaction appears in other user's account. xacts = Xact.by_acct_id(acct_id) assert xacts[0].memo == xferMemo and xacts[0].amount == float( xferAmount)