feat: add MasterView registry/discovery mechanism
and show related MasterView link buttons when viewing App Table also show some more info about model class when viewing table
This commit is contained in:
parent
0619f070c7
commit
484e1f810a
8 changed files with 225 additions and 16 deletions
61
tests/test_conf.py
Normal file
61
tests/test_conf.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from wuttjamaican.db.model import User
|
||||
from wuttjamaican.testing import ConfigTestCase
|
||||
|
||||
from wuttaweb import conf as mod
|
||||
from wuttaweb.testing import WebTestCase
|
||||
from wuttaweb.views import MasterView
|
||||
|
||||
|
||||
class TestWuttaWebConfigExtension(ConfigTestCase):
|
||||
|
||||
def test_basic(self):
|
||||
|
||||
# continuum plugin not set yet (b/c config was not extended)
|
||||
self.assertIsNone(self.config.get("wutta_continuum.wutta_plugin_spec"))
|
||||
|
||||
# so let's extend it
|
||||
extension = mod.WuttaWebConfigExtension()
|
||||
extension.configure(self.config)
|
||||
self.assertEqual(
|
||||
self.config.get("wutta_continuum.wutta_plugin_spec"),
|
||||
"wuttaweb.db.continuum:WuttaWebContinuumPlugin",
|
||||
)
|
||||
|
||||
|
||||
class MasterWithClass(MasterView):
|
||||
model_class = User
|
||||
|
||||
|
||||
class MasterWithName(MasterView):
|
||||
model_class = "Widget"
|
||||
|
||||
|
||||
class TestAddMasterView(WebTestCase):
|
||||
|
||||
def test_master_with_class(self):
|
||||
model = self.app.model
|
||||
|
||||
# nb. due to minimal test bootstrapping, no master views are
|
||||
# registered by default at this point
|
||||
self.assertNotIn("wuttaweb_master_views", self.request.registry.settings)
|
||||
|
||||
self.pyramid_config.add_wutta_master_view(MasterWithClass)
|
||||
self.assertIn("wuttaweb_master_views", self.request.registry.settings)
|
||||
master_views = self.request.registry.settings["wuttaweb_master_views"]
|
||||
self.assertIn(model.User, master_views)
|
||||
self.assertEqual(master_views[model.User], [MasterWithClass])
|
||||
|
||||
def test_master_with_name(self):
|
||||
model = self.app.model
|
||||
|
||||
# nb. due to minimal test bootstrapping, no master views are
|
||||
# registered by default at this point
|
||||
self.assertNotIn("wuttaweb_master_views", self.request.registry.settings)
|
||||
|
||||
self.pyramid_config.add_wutta_master_view(MasterWithName)
|
||||
self.assertIn("wuttaweb_master_views", self.request.registry.settings)
|
||||
master_views = self.request.registry.settings["wuttaweb_master_views"]
|
||||
self.assertIn("Widget", master_views)
|
||||
self.assertEqual(master_views["Widget"], [MasterWithName])
|
||||
|
|
@ -9,6 +9,7 @@ from wuttjamaican.db.conf import check_alembic_current, make_alembic_config
|
|||
|
||||
from wuttaweb.testing import WebTestCase
|
||||
from wuttaweb.views import tables as mod
|
||||
from wuttaweb.views.users import UserView
|
||||
|
||||
|
||||
class TestAppTableView(WebTestCase):
|
||||
|
|
@ -75,6 +76,34 @@ version_locations = wuttjamaican.db:alembic/versions
|
|||
table = {"name": "poser_foo"}
|
||||
self.assertEqual(view.get_instance_title(table), "poser_foo")
|
||||
|
||||
def test_configure_form(self):
|
||||
view = self.make_view()
|
||||
table = {"name": "user", "description": "Represents a user"}
|
||||
|
||||
# no description widget by default
|
||||
form = view.make_form(model_instance=table, fields=["name", "description"])
|
||||
self.assertNotIn("description", form.widgets)
|
||||
|
||||
# but it gets added when configuring
|
||||
view.configure_form(form)
|
||||
self.assertIn("description", form.widgets)
|
||||
|
||||
def test_get_xref_buttons(self):
|
||||
self.pyramid_config.add_route("users", "/users/")
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
# nb. must add this first
|
||||
self.pyramid_config.add_wutta_master_view(UserView)
|
||||
|
||||
# now xref button should work
|
||||
table = {"name": "person", "model_class": model.User}
|
||||
buttons = view.get_xref_buttons(table)
|
||||
self.assertEqual(len(buttons), 1)
|
||||
button = buttons[0]
|
||||
self.assertIn("Users", button)
|
||||
self.assertIn("http://example.com/users/", button)
|
||||
|
||||
def test_get_row_grid_data(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue