3
0
Fork 0

feat: add form/grid label auto-overrides for master view

This commit is contained in:
Lance Edgar 2024-08-15 20:51:36 -05:00
parent c1afc3b3e3
commit cd706821b2
7 changed files with 179 additions and 11 deletions

View file

@ -10,6 +10,7 @@ from pyramid.httpexceptions import HTTPNotFound
from wuttjamaican.conf import WuttaConfig
from wuttaweb.views import master
from wuttaweb.views import View
from wuttaweb.subscribers import new_request_set_user
from tests.util import WebTestCase
@ -331,6 +332,14 @@ class TestMasterView(WebTestCase):
# support methods
##############################
def test_get_class_hierarchy(self):
class MyView(master.MasterView):
pass
view = MyView(self.request)
classes = view.get_class_hierarchy()
self.assertEqual(classes, [View, master.MasterView, MyView])
def test_has_perm(self):
model = self.app.model
auth = self.app.get_auth_handler()
@ -428,6 +437,36 @@ class TestMasterView(WebTestCase):
self.assertEqual(view.get_index_title(), "Wutta Widgets")
del master.MasterView.model_title_plural
def test_collect_labels(self):
# no labels by default
view = self.make_view()
labels = view.collect_labels()
self.assertEqual(labels, {})
# labels come from all classes; subclass wins
with patch.object(View, 'labels', new={'foo': "Foo", 'bar': "Bar"}, create=True):
with patch.object(master.MasterView, 'labels', new={'foo': "FOO FIGHTERS"}, create=True):
view = self.make_view()
labels = view.collect_labels()
self.assertEqual(labels, {'foo': "FOO FIGHTERS", 'bar': "Bar"})
def test_set_labels(self):
model = self.app.model
with patch.object(master.MasterView, 'model_class', new=model.Setting, create=True):
# no labels by default
view = self.make_view()
grid = view.make_model_grid(session=self.session)
view.set_labels(grid)
self.assertEqual(grid.labels, {})
# labels come from all classes; subclass wins
with patch.object(master.MasterView, 'labels', new={'name': "SETTING NAME"}, create=True):
view = self.make_view()
view.set_labels(grid)
self.assertEqual(grid.labels, {'name': "SETTING NAME"})
def test_make_model_grid(self):
model = self.app.model