Esempio n. 1
0
def test_dbconnect():
    localcon = dbconnect(databasename='components1.db')
    print 'Test for missing database.'
    assert localcon is False, 'Database does exist'
    localcon = dbconnect()
    print 'Test for default database.'
    assert localcon is not False, 'Default database does not exist'
    localcon.close()
    localcon = dbconnect(databasename='components1.db', readonly=False)
    print 'Test empty database create.'
    if not os.path.exists('components1.db'):
        assert False, 'Unable to create database file.'
    else:
        localcon.close()
        os.remove('components1.db')
Esempio n. 2
0
Base.metadata.bind = engine

DBSession = sessionmaker()
DBSession.bind = engine
session = DBSession()

app = Flask(__name__)

# Load default config and override config from an environment variable
app.config.update(dict(
    DATABASE=os.path.join(app.root_path, 'database/components.db'),
    DEBUG=True,
    SECRET_KEY='development key',
))
app.config.from_envvar('APP_SETTINGS', silent=True)
con = dbconnect()


@app.route('/')
def index():
    return render_template('index.html')


def create_query(filtered=1):
    '''
    Build a query object depending on whether it is a filtered query or not
    :param filtered:
    :return: orm query object
    '''
    if filtered == '1':
        query_obj = session.query(Components.ID, Components.Name, Components.CurrentStock, Components.ReorderLevel,
Esempio n. 3
0
import csv
from componentsmodule import Component, dbconnect
import pdb

#pdb.set_trace()

with dbconnect() as conn:

    with open(r'testdata.csv','r') as fp:
        component_details = csv.reader(fp)
        titles_row = component_details.next()
        for component_row in component_details:
            comp_object = Component(zip(titles_row,component_row),conn)
            print component_row