def create_app(): """This function initializes the app. The app will be as a [Flask](https://palletsprojects.com/p/flask/) app initialized. In addition all the api routes and databases will be initialized here. The list of routes and the initialization method for them can be found here: `api.resources` The database initialization methods can be found here: `api.db` """ app = Flask(__name__) init_resources(app) config = ProductionConfig if app.config['ENV'] == 'development': config = DevelopmentConfig elif app.config['ENV'] == 'testing': config = TestingConfig app.config.from_object(config) if app.config['ENV'] == 'testing': from api.db import init_db_mock init_db_mock(app) else: from api.db import init_db init_db(app) return app
def run_database_update(): # Create a temporary application # Init the database init_db(context=False) # # Load factory tables # # Run known ingest jobs = [ ('milestone', factory_milestones, {} ), ('country', factory_countries, {} ), ('product', 'https://raw.githubusercontent.com/c19-rnd-dashboard/py-api-vac-rnd-dash/master/data/vaccines/vaccineworkfile4.csv', {'loader': "unfiltered_csv"} ), ('trial', 'https://raw.githubusercontent.com/ebmdatalab/covid_trials_tracker-covid/master/notebooks/processed_data_sets/trial_list_2020-05-26.csv', {} ), ] for job in jobs: run_ingest(category=job[0], source=job[1], **job[2])
def app(): """Fixture to return an app instance from the factory.""" db_fd, db_path = tempfile.mkstemp() app = create_app({ 'TESTING': True, 'DATABASE': db_path, }) with app.app_context(): init_db() yield app os.close(db_fd) os.unlink(db_path)
from api.db import init_db from endpoints import app init_db() app.run()
if txn is None: return if exception: db.session.rollback() else: db.session.commit() @app.route('/') def hello_world(): return 'Hello World!' todo_view = views.TodoApi.as_view('todo_api') app.add_url_rule('/todos/', defaults={'todo_id': None}, view_func=todo_view, methods=[ 'GET', ]) app.add_url_rule('/todos/', view_func=todo_view, methods=[ 'POST', ]) app.add_url_rule('/todos/<int:todo_id>', view_func=todo_view, methods=['GET', 'PUT', 'DELETE']) if not db.session: db.init_db()
from api import views, db, server import unittest import sys db.init_db('todo_test') db.Base.metadata.create_all(bind=db.engine) server.app.debug = True
import api from api.db import init_db from api.utils.ingest import run_ingest init_db(context=False) source = 'https://raw.githubusercontent.com/c19-rnd-dashboard/py-api-vac-rnd-dash/master/data/vaccines/vaccineworkfile2.csv' params = {'loader': "unfiltered_csv"} run_ingest(category='product', source=source, **params)
def test_init_db_command(self): out = StringIO() init_db(out) output = out.getvalue().strip() print('init-db output: ', output) self.assertIn('init', output)