Exemple #1
0
def _init_db_path_sqlite(tmpdir_factory):
    """
    Initializes a SQLite database for testing by populating it from scratch and placing it into a
    temp directory file.
    """
    sqlitedbfile = str(tmpdir_factory.mktemp("data").join("test.db"))
    sqlitedb = "sqlite:///{0}".format(sqlitedbfile)
    conf = {
        "TESTING": True,
        "DEBUG": True,
        "SECRET_KEY": "superdupersecret!!!1",
        "DATABASE_SECRET_KEY": "anothercrazykey!",
        "DB_URI": sqlitedb,
    }
    os.environ["DB_URI"] = str(sqlitedb)
    db.initialize(SqliteDatabase(sqlitedbfile))
    application.config.update(conf)
    application.config.update({"DB_URI": sqlitedb})
    initialize_database()

    db.obj.execute_sql("PRAGMA foreign_keys = ON;")
    db.obj.execute_sql('PRAGMA encoding="UTF-8";')

    populate_database()
    close_db_filter(None)
    return str(sqlitedbfile)
def addfood():
    result = request.form
    engine = initdb.initialize_database()
    initdb.insert_new_food(engine,
                           result['name'],
                           result['calories'],
                           result['cuisine'],
                           result['is_vegetarian'],
                           result['is_gluten_free'])
    message = 'New food added'
    return render_template('result.html', message=message)
def search():
    name = request.args.get('name')
    engine = initdb.initialize_database()
    results = initdb.get_favorite_food(engine, name)
    return json.dumps([(dict(row.items())) for row in results])
def favorite():
    engine = initdb.initialize_database()
    results = initdb.get_favorite_food(engine, 'pizza')
    return json.dumps([(dict(row.items())) for row in results])
Exemple #5
0
 def setUp(self):
     self.transaction_factory = app.config["DB_TRANSACTION_FACTORY"]
     self.queue = AutoUpdatingQueue(WorkQueue(QUEUE_NAME, self.transaction_factory))
     wipe_database()
     initialize_database()
     populate_database()