def create_app(): app = Flask(__name__, instance_relative_config=True) app.config.from_pyfile('config.py', silent=True) register_extensions(app) external_stylesheets = [dbc.themes.BOOTSTRAP] meta_viewport = { 'name': 'viewport', 'content': 'width=device-width, initial-scale=1, shrink-to-fit=no' } dash_app = dash.Dash(__name__, server=app, url_base_pathname='/', external_stylesheets=external_stylesheets, meta_tags=[meta_viewport]) dash_app.config.suppress_callback_exceptions = True dash_app.layout = html.Div([ dcc.Location(id='url', refresh=False), html.Div([ dbc.NavbarSimple( children=[ dbc.NavItem(dbc.NavLink("Home", href="/")), dbc.NavItem(dbc.NavLink("Upload", href="/upload")), dbc.NavItem(dbc.NavLink("Archetypes", href="/archetypes")), dbc.NavItem(dbc.NavLink("Match", href="/match")) ], brand="Archetype Discovery", brand_href="/", color="dark", dark=True, ), html.Div(id='page-content', className='container') ]) ]) # Update the index @dash_app.callback(dash.dependencies.Output('page-content', 'children'), [dash.dependencies.Input('url', 'pathname')]) def display_page(pathname): if pathname == '/archetypes': return archetype_layout() elif pathname == '/upload': return upload_layout() elif pathname == '/match': return match_layout() else: return home_layout() with app.app_context(): dash_app.title = 'Archetype Discovery' ac_reg(dash_app) up_reg(dash_app) ma_reg(dash_app) # Create tables for our models db.create_all() return app
def my_setup(obj): """Call this function from setUp as: def setUp(self): my_setup(self) """ # This seems a bug in Flask_REST_JSONAPI # # The Flask_REST_JSONAPI does not remove the Blue Blueprint objects # stored internally when the application objects they are applied to # is destroyed. # # I found this same issue is there for Flask Restful extension as # discovered and described in the book Mastering Flask: # https://books.google.com/books?id=NdZOCwAAQBAJ&pg=PA219&lpg=PA219&dq=flask:+how+to+destroy+application+object&source=bl&ots=nx7L_UG3EM&sig=yA-DG-ZYPtM5JxKJsFiXrhSkwzQ&hl=en&sa=X&ved=0ahUKEwies8G-x-7ZAhUh_IMKHdYKDCsQ6AEIdDAG#v=onepage&q=flask%3A%20how%20to%20destroy%20application%20object&f=false # # The result is that during a 2nd test, the view routes are created # twice and this error will be thrown: # builtins.AssertionError: View function mapping is overwriting an # existing endpoint function: api.api.user_list # # Workaround is to reset them manually rest_jsonapi.resources = [] obj.app = create_app(TestConfig) # initialize the test client obj.client = obj.app.test_client obj.app_context = obj.app.app_context() obj.app_context.push() db.create_all() Role.insert_roles() User.insert_default_users() Item.insert_default_items()
def client(app): with app.test_client() as client: _db.app = app _db.create_all() yield client _db.session.rollback() _db.drop_all()
def register_extensions(app): from application.extensions import db db.app = app db.init_app(app) with app.app_context(): db.create_all()
def db(app, request): """Session-wide test database.""" def teardown(): _db.drop_all() _db.app = app _db.create_all() request.addfinalizer(teardown) return _db
def db(app, request): def teardown(): _db.drop_all() _db.app = app _db.create_all() request.addfinalizer(teardown) return _db
def create_user(email): """ One can also create a user via the API: curl -XPOST http://people.xgs.local/session -d '{"email":"[email protected]"}' -H 'Content-Type: application/json' """ db.session.execute('CREATE SCHEMA IF NOT EXISTS "%s"' % email) db.session.execute('SET search_path TO "%s"' % email) db.session.commit() with app.app_context(): db.create_all() db.session.commit()
def db(app, request): """Session-wide test database.""" if os.path.exists(app.config["TEST_DB"]): os.unlink(app.config["TEST_DB"]) def teardown(): _db.drop_all() os.unlink(app.config["TEST_DB"]) _db.app = app _db.create_all() request.addfinalizer(teardown) return _db
def init_db(): db.create_all() db.session.add(User( username="******", password=guard.hash_password("admin"), roles="admin" )) db.session.add(PortfolioImage( title="Test", category="portrait", client="Der Boi" )) db.session.add(PortfolioVideo( title="Test", category="aftermovie", client="Der Boi", video="ilusrhgiur" )) db.session.commit() yield db db.drop_all()
def create_db(): """ Create Database """ db.create_all()
def create_db(): """create tables""" db.create_all()
def createall(): """Creates database tables""" db.create_all()
def create_all(): if prompt_bool("Are you sure? You will init your database"): db.create_all()
def create(): """Creates database tables from SqlAlchemy models""" db.create_all()
def create(): """Creates database tables from sqlalchemy models""" db.create_all()
def setUpClass(cls): cls.app = create_app(TestingConfig) with cls.app.app_context(): db.create_all()