def test_db_url_environ(monkeypatch): """ Test DATABASE_URL environment variable. """ monkeypatch.setenv("DATABASE_URL", "sqlite:///environ") app = create_app() assert app.config["SQLALCHEMY_DATABASE_URI"] == "sqlite:///environ"
def app(): """Create and configure a new app instance for each test.""" # create the app with common test config app = create_app({ "TESTING": True, "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:", "PERIODIC_TASK_PERIOD": 240, }) # create the database and load test data with app.app_context(): init_db(real_data=False) for sql_insert in _data_sql.split(";"): db.session.execute(sql_insert) db.session.commit() # update the records as been created in this moment db.session.query(ConversionRate).filter().update( {"created": datetime.utcnow()}) db.session.commit() cache.invalidate_all() yield app
def test_db_url_environ_absent(monkeypatch): """ Test absence of DATABASE_URL environment variable. """ try: monkeypatch.delenv("DATABASE_URL") except: pass app = create_app() assert "currency_convertor.sqlite" in app.config["SQLALCHEMY_DATABASE_URI"]
def create_celery(app=None): app = app or create_app() celery = Celery(app.import_name) celery.conf.update(app.config) class ContextTask(celery.Task): def __call__(self, *args, **kwargs): with app.app_context(): return self.run(*args, **kwargs) celery.Task = ContextTask return celery
def appwsgi(): """Create and configure a new app instance for each test.""" from currency_convertor.wsgi import app as wsgiapp # create the app with common test config wsgiapp = create_app({ "TESTING": True, "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:" }) # create the database and load test data with wsgiapp.app_context(): init_db(real_data=False) for sql_insert in _data_sql.split(";"): db.session.execute(sql_insert) db.session.commit() cache.invalidate_all() yield wsgiapp
from currency_convertor import create_app app = create_app()
def test_config(): """ Test create_app without passing test config. """ assert not create_app().testing assert create_app({"TESTING": True}).testing