def app(): # for now we test over sqlite in memory, so no empty db needed test_app = create_app('TESTING_MEMORY') db.init_app(test_app) with test_app.test_request_context(): db.create_all() return test_app
def app(request): # for now we test over sqlite in memory, so no empty db needed test_app = create_app('TESTING_MEMORY') db.init_app(test_app) with test_app.test_request_context(): # test that the database on we are testing it's ended with '_test' # to avoid data corruption and/or deletion db_uri = test_app.config['SQLALCHEMY_DATABASE_URI'] if not (db_uri.endswith('_test') or db_uri == 'sqlite:///:memory:'): pytest.skip(msg="Testing over a none '_test' database. Skipping") try: # Start the database clean. db.drop_all() db.create_all() except OperationalError: pytest.fail(msg="The tables can't be created. Maybe the db don't exists or it didn't have access") def teardown(): with test_app.test_request_context(): db.drop_all() request.addfinalizer(teardown) return test_app
from autoconstruccion import create_app, create_db application = create_app() # Create database create_db() if __name__ == "__main__": application.run()
def setUp(self): self.fixture = self.getUser() app = create_app() app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.app_context().push()
def setUp(self): self.app = create_app('DEVELOPMENT') self.client = self.app.test_client(False)
# from os.path import abspath, dirname # sys.path.insert(0, dirname(dirname(abspath(__file__)))) # import flask configurations: app, db from autoconstruccion import create_app, db from autoconstruccion.models import * # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) # obtain db url and metadata from flask app app = create_app() config.set_main_option("sqlalchemy.url", app.config["SQLALCHEMY_DATABASE_URI"]) sqlalchemy_url = app.config['SQLALCHEMY_DATABASE_URI'] with app.app_context(): target_metadata = db.metadata def run_migrations_offline(): """Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the
def setUp(self): self.app = create_app() self.client = self.app.test_client(False)
from autoconstruccion import create_app application = create_app(config_name='DEVELOPMENT') if __name__ == '__main__': application.run()