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()
def recreate_db(): """ Recreates a local database. You probably should not use this on production. """ db.drop_all() db.create_all() db.session.commit()
def create_app(): app = Flask(__name__) app.config.from_object('config.settings') db.app = app db.init_app(app) api = Api(app) api.add_resource(Register, '/register') api.add_resource(Recongization, '/recon') db.create_all() return app
def create_app(): from project.models import db from project.views import views_bp as views_blueprint environment = os.environ.get("ENVIRONMENT", "default") app = Flask(__name__) app.config.from_object(CONFIG[environment]) app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=app.config["APPLICATION_ROOT"]) db.init_app(app) if not app.config["DEBUG"]: handler = CMRESHandler(hosts=[{ 'host': '192.168.99.100', 'port': 9200 }], auth_type=CMRESHandler.AuthType.NO_AUTH, es_index_name="my_python_index", es_additional_fields={ 'App': app.config["APP_NAME"], 'Environment': ENVIRONMENT }) app.logger.addHandler(handler) SWAGGER_CONFIG["specs"][0]["route"] = SWAGGER_CONFIG["specs"][0][ "route"].format(application_root=app.config["APPLICATION_ROOT"]) SWAGGER_CONFIG["static_url_path"] = SWAGGER_CONFIG[ "static_url_path"].format( application_root=app.config["APPLICATION_ROOT"]) SWAGGER_CONFIG["specs_route"] = SWAGGER_CONFIG["specs_route"].format( application_root=app.config["APPLICATION_ROOT"]) SWAGGER_CONFIG["basePath"] = SWAGGER_CONFIG["basePath"].format( application_root=app.config["APPLICATION_ROOT"]) Swagger(app, config=SWAGGER_CONFIG) app.register_blueprint(views_blueprint) with app.test_request_context(): db.create_all() return app, db
def register_extensions(app): from project.models import db, User db.init_app(app) with app.app_context(): db.create_all(app=app) # Login manager login_manager.init_app(app) @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) # Flask uploads configure_uploads(app, avatars) # Sentry sentry.init_app(app=app, logging=True, level=logging.ERROR) # Mobility mobility.init_app(app=app) # Flask Mail mail.init_app(app=app)
admin.add_view(MTWordModelView(User, db.session)) admin.add_view(MTWordModelView(Set, db.session)) admin.add_view(MTWordModelView(Verse, db.session)) app.config.update({ "MAIL_SERVER": os.environ.get("MAIL_SERVER"), "MAIL_PORT": os.environ.get("MAIL_PORT"), "MAIL_USE_TLS": os.environ.get("MAIL_USE_TLS"), "MAIL_USE_SSL": os.environ.get("MAIL_USE_SSL"), "MAIL_USERNAME": os.environ.get("MAIL_USERNAME"), "MAIL_DEFAULT_SENDER": os.environ.get("MAIL_DEFAULT_SENDER"), "MAIL_PASSWORD": os.environ.get("MAIL_PASSWORD") }) connect_mail(app) db.create_all() app.register_blueprint(api) app.register_blueprint(homepage) app.register_blueprint(login) app.register_blueprint(sets) app.register_blueprint(users) #################################################################### # Setting up Login @login_manager.user_loader def load_user(user_id): return User.query.get(user_id)
def setup(): db.drop_all() db.create_all() return "OK", 200
def clear_bd(): db.session.remove() db.drop_all() db.session.commit() db.create_all()
def app(): app = create_app('test') with app.app_context(): db.create_all() yield app db.drop_all()
def create_db(): db.drop_all() db.create_all() db.session.commit()
def create_db(): """ Command to re-create the database """ db.drop_all() db.create_all() db.session.commit()
def setUp(self): db.create_all()
from pathlib import Path import json from project import create_app from project.models import db, Room app = create_app() db.create_all(app=app) with app.app_context(): # Agregamos la data hard-coded (Salas) curr_dir = Path(__file__).resolve().parent with open(curr_dir.joinpath('data/room_data.json')) as file: rooms = json.load(file)['rooms'] for room in rooms: new_room = Room(name=room['name'], id=room['id'], capacity=room['capacity']) db.session.add(new_room) db.session.commit()