Skip to content

Commit

Permalink
fix: custom menu option (#1884)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar authored Jul 5, 2022
1 parent cc8e359 commit 40e1e14
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flask_appbuilder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def init_app(self, app: Flask, session: SessionBase) -> None:
# Setup Menu
if _menu is not None:
menu = dynamic_class_import(_menu)
if isinstance(menu, Menu):
self.menu = menu
if menu is not None and issubclass(menu, Menu):
self.menu = menu()
else:
self.menu = self.menu or Menu()

Expand Down
1 change: 1 addition & 0 deletions flask_appbuilder/tests/templates/custom_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a custom index view.
46 changes: 46 additions & 0 deletions flask_appbuilder/tests/test_custom_indexview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import logging
import os

from flask_appbuilder import IndexView, SQLA

from .base import FABTestCase

log = logging.getLogger(__name__)


class CustomIndexView(IndexView):
index_template = "templates/custom_index.html"


class FlaskTestCase(FABTestCase):
def setUp(self):
from flask import Flask
from flask_appbuilder import AppBuilder

self.app = Flask(__name__, template_folder=".")
self.basedir = os.path.abspath(os.path.dirname(__file__))
self.app.config.from_object("flask_appbuilder.tests.config_api")
self.app.config[
"FAB_INDEX_VIEW"
] = "flask_appbuilder.tests.test_custom_indexview.CustomIndexView"

self.db = SQLA(self.app)
self.appbuilder = AppBuilder(self.app, self.db.session)

def tearDown(self):
self.appbuilder = None
self.app = None
self.db = None
log.debug("TEAR DOWN")

def test_custom_indexview(self):
"""
Test custom index view.
"""
uri = "/"
client = self.app.test_client()
rv = client.get(uri)

self.assertEqual(rv.status_code, 200)
data = rv.data.decode("utf-8")
self.assertIn("This is a custom index view.", data)

0 comments on commit 40e1e14

Please sign in to comment.