示例#1
0
    def setUpClass(cls):
        cls.test_user = {
            'username': '******',
            'password': '******',
            'first_name': 'Jim',
            'last_name': 'Johnson'
        }
        cls.app = create_minimal_app()
        cls.APP_PORT = cls.app.config["APP_PORT"]
        cls.server_process = ServerProcess()
        # wait a bit for the server to wake up
        sleep(5)

        if not cls.app.config["TESTING"]:
            sys.exit("Testing mode is not enabled. Ensure that the testing configuration is used")

        cls.test_client = cls.app.test_client()

        with cls.app.app_context():
            db.session.close()
            db.drop_all()
            db.create_all()

            user = models.User(**cls.test_user)
            db.session.add(user)
            db.session.commit()
示例#2
0
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()
示例#3
0
def test_db(test_app):
    engine = create_engine('postgresql://localhost/' + TEST_DB)

    if not database_exists(engine.url):
        create_database(engine.url)

    with test_app.app_context():

        db.init_app(test_app)
        db.create_all()

        yield db

    db.drop_all()
示例#4
0
def dropall():
    """drop all tables"""
    db.drop_all()
示例#5
0
import src.models as models
from src.app import create_minimal_app
from src.database import db

app = create_minimal_app()
test_user = {
    'username': '******',
    'password': '******',
    'first_name': 'Jim',
    'last_name': 'Johnson'
}

with app.app_context():
    db.drop_all()
    db.create_all()

    user = models.User(**test_user)
    db.session.add(user)
    db.session.commit()
示例#6
0
 def tearDown(self):
     with self.app_instance.app_context():
         db.session.remove()
         db.drop_all()
示例#7
0
 def reset_database():
     db.drop_all()
     db.create_all()
示例#8
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
示例#9
0
def db(app):
    with app.app_context():
        _db.create_all()
        yield _db
        _db.drop_all()
示例#10
0
 def drop_db_command():
     """Drop the database. """
     db.init_app(app)
     db.drop_all()
     app.logger.info("Database dropped")