Esempio n. 1
0
    def test_acct_model(self):

        # new accounts can be added
        count = len(Acct.by_filter(''))
        Acct.new(0)
        new_count = len(Acct.by_filter(''))
        self.assertEqual(new_count, count + 1)
Esempio n. 2
0
    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)
Esempio n. 3
0
    def transfer(self, user_id, memo, amount):

        # Assert that browser redirects to edit page
        assert url_for('.xfer') in self.driver.current_url

        # Transfer details
        acct_id = Acct.by_user_id(user_id)[0].id

        # Fill in transfer form
        self.driver.find_element_by_id("dst").clear()
        self.driver.find_element_by_id("dst").send_keys(acct_id)
        self.driver.find_element_by_id("memo").clear()
        self.driver.find_element_by_id("memo").send_keys(memo)
        self.driver.find_element_by_id("amount").clear()
        self.driver.find_element_by_id("amount").send_keys(amount)
        self.driver.find_element_by_id("submit").click()
        time.sleep(loadWait)

        # Assert that browser redirects to index page
        assert url_for('.index') in self.driver.current_url

        # Assert success message is shown
        msg = self.driver.find_element_by_class_name("alert").text
        assert "Funds transferred successfully." in msg

        return acct_id
Esempio n. 4
0
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)
Esempio n. 5
0
    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)
Esempio n. 6
0
def xfer():

    acct = Acct.by_user_id(current_user.id)[0]
    form = XferForm(
        dst='',
        amount=0.00,
        memo='Enter description...',
    )
    form.src.data = acct.id

    if request.method == 'POST' and form.validate_on_submit():
        msg = do_transfer(acct.id, form.dst.data, form.amount.data,
                          form.memo.data)
        flash(msg)
        return redirect(url_for(".index"))

    return render_template("xfer.html", form=form, avail=acct.balance)
Esempio n. 7
0
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)
Esempio n. 8
0
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)