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)
Exemple #2
0
def _init_db_path_real_db(db_uri):
    """ Initializes a real database for testing by populating it from scratch. Note that this does
      *not* add the tables (merely data). Callers must have migrated the database before calling
      the test suite.
  """
    configure({
        "DB_URI": db_uri,
        "SECRET_KEY": "superdupersecret!!!1",
        "DB_CONNECTION_ARGS": {
            "threadlocals": True,
            "autorollback": True,
        },
        "DB_TRANSACTION_FACTORY": _create_transaction,
        "DATABASE_SECRET_KEY": "anothercrazykey!",
    })

    populate_database()
    return db_uri
Exemple #3
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()