f"No record for variable {repr(abbr)} found.") try: db.session.delete(description) db.session.commit() except Exception: db.session.rollback() raise CustomError400("Error on deleting.") # 'pragma: no cover' exludes code block from coverage if __name__ == '__main__': # pragma: no cover from db import create_app from db.api.views import api # create test app app = create_app('config.DevelopmentConfig') app.register_blueprint(api) # EP: works without db creation after done once db.create_all(app=create_app('config.DevelopmentConfig')) with app.app_context(): dr = DateRange('q', 'GDP_yoy') print(dr.min) # delete_datapoints("a", None, None, None) q = DatapointOperations.select(freq='d', name=None, start_date=None, end_date=None) print(q.count())
from db import create_app from db.api.views import api as api_module from db.custom_api.views import custom_api_bp as custom_api_module if __name__ == '__main__': app = create_app('config.ProductionConfig') app.register_blueprint(api_module) app.register_blueprint(custom_api_module) app.run(host="0.0.0.0", port=int(app.config['PORT']))
# db = SQLAlchemy(app) # -------------------------------------- # EP: once we are importing db from db.__init__ we have a SQLAlchemy(app) instance in this module from db import db from db import create_app # EP: we need to import models here explicitly, otherwise the tables created will be empty from db.api import models from db.api.views import api from db.api.utils import to_date # EP: this creates tables specified in db.api.models # EP: the tables will be created in config.DevelopmentConfig.SQLALCHEMY_DATABASE_URI # create app app = create_app('config.DevelopmentConfig') app.register_blueprint(api) # create tables for models db.create_all(app=app) # populate database from pathlib import Path p = Path(__file__).parent / 'tests' / 'test_data_2016H2.json' data = json.loads(p.read_text()) for datapoint in data: datapoint['date'] = to_date(datapoint['date']) with app.app_context(): db.session.bulk_insert_mappings(models.Datapoint, data) db.session.commit()
from ressources.register import Register from ressources.send_files import Send from ressources.manage_file import Manage from ressources.unregister import Unregister from db import recreate_database, create_app from db import app, api # api.add_resource(Queue, '/') api.add_resource(Register, '/register') api.add_resource(Send, '/send') api.add_resource(Manage, '/manage') api.add_resource(Unregister, '/unregister') if __name__ == '__main__': create_app() recreate_database() app.run(host='0.0.0.0', port=5001)