def add_accounts(ccy):
    accts = [
        Account(name="Laser" + ccy.code, ccy=ccy),
        Account(name="Mate" + ccy.code, ccy=ccy)
    ]
    [db.session.add(acct) for acct in accts]
    db.session.commit()
Esempio n. 2
0
def test_bad_formed_account():

    with pytest.raises(ValidateError):
        acct = Account(name="test", ccy_id="test")

    with pytest.raises(ValidateError):
        acct = Account(name=124, ccy_id=1234)

    with pytest.raises(ValidateError):
        acct = Account(name=None, ccy_id=1234)

    with pytest.raises(ValidateError):
        acct = Account(name="test", ccy_id=None)
Esempio n. 3
0
def model_objects():
    objects = {
        'u1': User(id=1, username="******", email="*****@*****.**"),
        'u2': User(id=2, username="******", email="*****@*****.**"),
        'u3': User(id=3, username="******", email="*****@*****.**"),
        'u4': User(id=4, username="******", email="*****@*****.**"),
        'usd': Currency(id=1, code="USD", name="US Dollar"),
        'btc': Currency(id=2, code="BTC", name="Bitcoin"),
        'acct1': Account(id=1, ccy_id=1, name="USD Credits"),
        'acct2': Account(id=2, ccy_id=1, name="USD Debits"),
        'acct3': Account(id=3, ccy_id=2, name="BTC Wallet"),
    }

    return objects
Esempio n. 4
0
def new_project():
    """ Return a page to create a new project """

    if request.method == "POST":
        goal = int(request.form['goal'])
        ccy_code = request.form['ccy']
        desc = request.form['desc']
        project_name = request.form['project_name']

        ccy = db.session.query(Currency).filter_by(code=ccy_code).one()
        acct = Account(name="{}_{}_acct".format(project_name, ccy_code),
                       ccy=ccy)

        project = Project(name=project_name, desc=desc, goal=goal)
        project.accounts = [acct]

        db.session.add(project)
        db.session.commit()

        # TODO: send the new project to the database
        return (render_template('new_project_created.html',
                                title=project_name,
                                project=project))
    else:
        return render_template('new_project.html',
                               data={
                                   'git_sha': git_sha,
                                   'repo_path': repo_path
                               })
Esempio n. 5
0
def new_project(project_name):
    if request.method == "POST":
        goal = request.form['goal']
        ccy_code = request.form['ccy']
        desc = request.form['desc']

        acct = Account(
            name="{}_{}_acct".format(project_name, ccy_code),
            ccy=db.session.query('Currency').filter(code=ccy_code).one())

        project = Project(name=project_name,
                          desc=desc,
                          goal=goal,
                          accounts=[acct])

        db.session.add(project)
        db.session.commit()

        # TODO: send the new project to the database
        return (render_template('new_project_created.html',
                                title=project_name,
                                project=project))
    else:
        return (render_template('new_project.html',
                                title=project_name,
                                project=project))
Esempio n. 6
0
def test_new_account(model_objects):

    # usd = db.session.query(Currency).filter(Currency.code == "USD").one()
    usd = model_objects['usd']
    acct = Account(ccy_id=usd.id, name="Credits")

    assert acct.ccy_id == usd.id
    assert acct.name == "Credits"
def add_projects(ccy):

    fire_drill_acct = Account(name="Fire Drill", ccy=ccy)
    gnar_acct = Account(name="gnar", ccy=ccy)
    ngalac_acct = Account(name="NGALAC", ccy=ccy)

    db.session.add(fire_drill_acct)
    db.session.add(gnar_acct)
    db.session.add(ngalac_acct)

    db.session.commit()

    fire = Project(name="Fire Drill",
                   goal=4000000,
                   account_id=fire_drill_acct.id)
    gnar = Project(name="gnar", goal=1337, account_id=gnar_acct.id)
    ngal = Project(name="NGALAC", goal=12345, account_id=ngalac_acct.id)

    db.session.add(fire)
    db.session.add(gnar)
    db.session.add(ngal)

    db.session.commit()
Esempio n. 8
0
def test_db_project(db):
    proj_name = "Test Proj"
    proj_desc = "A project for testing"
    proj_goal = 100
    ccy_name = "USD Dollar"
    ccy_code = "USD"
    acct_name = "{}_{}_acct".format(proj_name, ccy_code)

    ccy = Currency(name=ccy_name, code=ccy_code)
    account = Account(name=acct_name, ccy=ccy)
    proj = Project(name=proj_name, desc=proj_desc, goal=proj_goal)
    proj.accounts = [account]

    db.session.add(proj)
    db.session.commit()
Esempio n. 9
0
def test_insert_account(model_objects):

    # btc = db.session.query(Currency). \
    #     filter(Currency.code == "BTC"). \
    #     one()

    btc = model_objects['btc']
    acct = Account(ccy_id=btc.id, name="Crypto")
    db.session.add(acct)
    db.session.commit()

    retrieved_acct = db.session.query(Account). \
        filter(Account.name == "Crypto"). \
        one()

    assert retrieved_acct == acct
Esempio n. 10
0
def model_stripe_data(req_data):
    app.logger.info("Modelling stripe data")

    if app.config['SINGLE_CCY']:
        ccy_name = "USD"  # FIXME more generic...i mean..maybe

    to_proj = req_data['project_select']
    from_acc_name = req_data['email']
    amount = int(round(float(req_data['charge']), 2) * 100)

    # These will raise errors if not found or more than one found.  They
    # should bubble up to the route.
    project = get_one(Project, {'name': to_proj})
    ccy = get_one(Currency, {'code': ccy_name})

    # Check for user account (e.g. the account from which the spice will flow)
    app.logger.info("Finding account {}.".format(from_acc_name))
    try:
        from_acct = get_one(Account, {'name': from_acc_name, 'ccy': ccy})
    # if it doesn't exist, make it.
    except NoResultFound:
        app.logger.info("Customer Account not found, creating account"
                        " for new customer {}".format(from_acc_name))
        from_acct = Account(name=from_acc_name, ccy=ccy)

    for project_account in project.accounts:
        if project_account.ccy.code == ccy_name:
            to_acct = project_account

    try:
        to_acct
    except NameError:
        app.logger.error("No account with ccy {} "
                         "on project {}".format(ccy_name, to_proj))
        raise NoResultFound

    tx = Transaction(amount=amount, ccy=ccy, payer=from_acct, recvr=to_acct)

    return tx
def init():
    '''Adds the initial currency, account, and project for the General Fund.'''

    ccy = Currency(code="USD", name="US Dollar")
    acct = Account(name="General Fund Account", ccy=ccy)
    project = Project(name="General Fund",
                      desc="Noisebridge's account of record",
                      goal=0,
                      accounts=[acct])

    session = create_session()

    donate_config = DonateConfiguration(key="INIT",
                                        type="string",
                                        value="true")
    try:
        session.add(project)  # Includes the ccy and acct of the project
        session.add(donate_config)
        session.commit()
    except Exception as e:
        session.rollback()
        raise e