def populate(bulk_data, test_data, posts, topics, force, initdb): """Creates the necessary tables and groups for FlaskBB.""" if force: click.secho("[+] Recreating database...", fg="cyan") drop_database(db.engine.url) # do not initialize the db if -i is passed if not initdb: upgrade_database() if initdb: click.secho("[+] Initializing database...", fg="cyan") upgrade_database() if test_data: click.secho("[+] Adding some test data...", fg="cyan") create_test_data() if bulk_data: timer = time.time() topic_count, post_count = insert_bulk_data(int(topics), int(posts)) elapsed = time.time() - timer click.secho("[+] It took {} seconds to create {} topics and {} posts" .format(elapsed, topic_count, post_count), fg="cyan") # this just makes the most sense for the command name; use -i to # init the db as well if not test_data: click.secho("[+] Populating the database with some defaults...", fg="cyan") create_default_groups() create_default_settings()
def populate(bulk_data, test_data, posts, topics, force, initdb): """Creates the necessary tables and groups for FlaskBB.""" if force: click.secho("[+] Recreating database...", fg="cyan") db.drop_all() # do not initialize the db if -i is passed if not initdb: create_latest_db() if initdb: click.secho("[+] Initializing database...", fg="cyan") create_latest_db() if test_data: click.secho("[+] Adding some test data...", fg="cyan") create_test_data() if bulk_data: timer = time.time() topic_count, post_count = insert_bulk_data(int(topics), int(posts)) elapsed = time.time() - timer click.secho( "[+] It took {} seconds to create {} topics and {} posts".format( elapsed, topic_count, post_count), fg="cyan") # this just makes the most sense for the command name; use -i to # init the db as well if not test_data: click.secho("[+] Populating the database with some defaults...", fg="cyan") create_default_groups() create_default_settings()
def test_insert_bulk_data(database): assert not insert_bulk_data(topic_count=1, post_count=1) create_test_data(categories=1, forums=1, topics=0) assert Topic.query.count() == 0 topics, posts = insert_bulk_data(topic_count=1, post_count=1) assert Topic.query.count() == topics # -1 bc the topic post also counts as post assert Post.query.count() - 1 == posts
def createall(): """ Creates the database with some example content. """ # Just for testing purposes db.drop_all() db.create_all() create_test_data()
def populate(dropdb=False, createdb=False): """Creates the database with some default data. To drop or create the databse use the '-d' or '-c' options. """ if dropdb: print("Dropping database...") db.drop_all() if createdb: print("Creating database...") upgrade() print("Creating test data...") create_test_data()
def populate(dropdb=False, createdb=False): """Creates the database with some default data. If you do not want to drop or create the db add '-c' (to not create the db) and '-d' (to not drop the db) """ if not dropdb: print("Dropping database...") db.drop_all() if not createdb: print("Creating database...") upgrade() app.logger.info("Creating test data...") create_test_data()
def createall(dropdb=False, createdb=False): """Creates the database with some testing content. If you do not want to drop or create the db add '-c' (to not create the db) and '-d' (to not drop the db) """ if not dropdb: app.logger.info("Dropping database...") db.drop_all() if not createdb: app.logger.info("Creating database...") db.create_all() app.logger.info("Creating test data...") create_test_data()
def populate(dropdb=False, createdb=False): """Creates the database with some default data. If you do not want to drop or create the db add '-c' (to not create the db) and '-d' (to not drop the db) """ if dropdb: print("Dropping database...") db.drop_all() if createdb: print("Creating database...") upgrade() app.logger.info("Creating test data...") create_test_data()
def populate(bulk_data, test_data, posts, topics, force, initdb): """Creates the necessary tables and groups for FlaskBB.""" if force: click.secho("[+] Recreating database...", fg="cyan") db.drop_all() # do not initialize the db if -i is passed if not initdb: create_latest_db() if initdb: click.secho("[+] Initializing database...", fg="cyan") create_latest_db() run_plugin_migrations() if test_data: click.secho("[+] Adding some test data...", fg="cyan") create_test_data() if bulk_data: click.secho("[+] Adding a lot of test data...", fg="cyan") timer = time.time() rv = insert_bulk_data(int(topics), int(posts)) if not rv and not test_data: create_test_data() rv = insert_bulk_data(int(topics), int(posts)) elapsed = time.time() - timer click.secho("[+] It took {:.2f} seconds to create {} topics and {} " "posts.".format(elapsed, rv[0], rv[1]), fg="cyan") # this just makes the most sense for the command name; use -i to # init the db as well if not test_data and not bulk_data: click.secho("[+] Populating the database with some defaults...", fg="cyan") create_default_groups() create_default_settings()
def test_create_test_data(database): assert Category.query.count() == 0 data_created = create_test_data() assert Category.query.count() == data_created['categories']