Skip to content

Commit

Permalink
Merge pull request #2326 from cjmayo/init_app
Browse files Browse the repository at this point in the history
Use SQLAlchemy.init_app() in tests and document
  • Loading branch information
mrjoes committed Jan 31, 2023
2 parents fd0166f + 6a9a19b commit d98dc39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion doc/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ from the GeoAlchemy backend, rather than the usual SQLAlchemy backend::
from flask_admin.contrib.geoa import ModelView

# .. flask initialization
db = SQLAlchemy(app)
db = SQLAlchemy()
db.init_app(app)

class Location(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand Down
5 changes: 4 additions & 1 deletion flask_admin/tests/geoa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ def setup():
app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
db = SQLAlchemy()
db.init_app(app)
admin = Admin(app)

app.app_context().push()

return app, db, admin
8 changes: 4 additions & 4 deletions flask_admin/tests/geoa/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ class GeoModel(db.Model):
def __unicode__(self):
return self.name

db.create_all()

return GeoModel


def test_model():
app, db, admin = setup()
GeoModel = create_models(db)
db.create_all()
with app.app_context():
db.create_all()
GeoModel.query.delete()
db.session.commit()

Expand Down Expand Up @@ -130,7 +129,8 @@ def test_model():
def test_none():
app, db, admin = setup()
GeoModel = create_models(db)
db.create_all()
with app.app_context():
db.create_all()
GeoModel.query.delete()
db.session.commit()

Expand Down
6 changes: 4 additions & 2 deletions flask_admin/tests/sqla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def setup():
app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
db = SQLAlchemy()
db.init_app(app)
admin = Admin(app)

return app, db, admin
Expand All @@ -25,7 +26,8 @@ def setup_postgres():
app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
db = SQLAlchemy()
db.init_app(app)
admin = Admin(app)

return app, db, admin

0 comments on commit d98dc39

Please sign in to comment.