示例#1
0
def app():
    app = create_app('../testing_config.cfg')
    # Push the application context for the db object to work properly
    app.app_context().push()
    # Rollback all previous session changes from the last ran tests
    db.session.rollback()
    # Delete all the tables
    db.drop_all()

    # Create all tables
    db.create_all()
    # Add a new term
    term = Term(term='term')
    # Add a new translation
    translation = Translation(translation='translation')
    # Make the dates constant
    test_date_created = datetime(2018, 1, 1)
    test_modified_date = datetime(2018, 1, 2)
    translation.date_created = test_date_created
    translation.modified_date = test_modified_date
    term.date_created = test_date_created
    # Add the translation to term translations
    term.translations.append(translation)
    # Create a new user
    user = User(username='******', password='******', email='*****@*****.**')

    # Create an author
    author = User(username='******',
                  password='******',
                  email='*****@*****.**')
    # Create an admin user
    admin = User(username='******',
                 password='******',
                 roles='admin,user',
                 email='*****@*****.**')

    # Create a term and assign it to "author"
    author_term = Term(term='author_term')
    author_term.author = author

    # Add terms and users, this also adds the translation to the session
    db.session.add(term)
    db.session.add(user)
    db.session.add(admin)
    db.session.add(author_term)

    # Create a translation and assign it to "author"
    author_translation = Translation(translation='author_translation')
    author_translation.author = author
    author_translation.term = author_term
    db.session.add(author_translation)

    db.session.commit()

    # All the code after the yield statement serves as the teardown code
    yield app

    # DB Teardown
    db.session.rollback()
    db.drop_all()
示例#2
0
def recreate_db():
    """
    Recreates a local database. You probably should not use this on
    production.
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#3
0
def setup():
    db.drop_all()
    db.create_all()
    return "OK", 200
示例#4
0
def clear_bd():
    db.session.remove()
    db.drop_all()
    db.session.commit()
    db.create_all()
示例#5
0
def app():
    app = create_app('test')
    with app.app_context():
        db.create_all()
        yield app
        db.drop_all()
示例#6
0
文件: seed.py 项目: d-lee84/MTWord
from project.models import db, User, Set, Verse

from flask_bcrypt import Bcrypt

bcrypt = Bcrypt()

db.drop_all()
db.create_all()

hashed = bcrypt.generate_password_hash("testing").decode('utf8')

user = User(username="******",
            password=hashed,
            email="*****@*****.**",
            first_name="David",
            last_name="Lee",
            is_admin=True)

db.session.add(user)
db.session.commit()

verse1 = Verse(reference="John 3:16",
               verse='“For God so loved the world, that he gave his only Son, \
        that whoever believes in him should not perish but have eternal life.')

verse2 = Verse(
    reference="Romans 5:8",
    verse="but God shows his love for us in that while we were still sinners, \
        Christ died for us.")

db.session.add(verse1)
示例#7
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#8
0
def create_db():
    """ Command to re-create the database """
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#9
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()