feat: add basic support for "view" part of CRUD
still no SQLAlchemy yet, view must be explicit about data/model. but should support simple dict records, which will be needed in a few places anyway
This commit is contained in:
parent
754e0989e4
commit
4c467f5267
14 changed files with 745 additions and 82 deletions
|
@ -75,3 +75,76 @@ class TestGrid(TestCase):
|
|||
first = columns[0]
|
||||
self.assertEqual(first['field'], 'foo')
|
||||
self.assertEqual(first['label'], 'Foo')
|
||||
|
||||
def test_get_vue_data(self):
|
||||
|
||||
# null by default
|
||||
grid = self.make_grid()
|
||||
data = grid.get_vue_data()
|
||||
self.assertIsNone(data)
|
||||
|
||||
# is usually a list
|
||||
mydata = [
|
||||
{'foo': 'bar'},
|
||||
]
|
||||
grid = self.make_grid(data=mydata)
|
||||
data = grid.get_vue_data()
|
||||
self.assertIs(data, mydata)
|
||||
self.assertEqual(data, [{'foo': 'bar'}])
|
||||
|
||||
# if grid has actions, that list may be supplemented
|
||||
grid.actions.append(base.GridAction(self.request, 'view', url='/blarg'))
|
||||
data = grid.get_vue_data()
|
||||
self.assertIsNot(data, mydata)
|
||||
self.assertEqual(data, [{'foo': 'bar', '_action_url_view': '/blarg'}])
|
||||
|
||||
|
||||
class TestGridAction(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = WuttaConfig()
|
||||
self.request = testing.DummyRequest(wutta_config=self.config, use_oruga=False)
|
||||
|
||||
def make_action(self, key, **kwargs):
|
||||
return base.GridAction(self.request, key, **kwargs)
|
||||
|
||||
def test_render_icon(self):
|
||||
|
||||
# icon is derived from key by default
|
||||
action = self.make_action('blarg')
|
||||
html = action.render_icon()
|
||||
self.assertIn('<i class="fas fa-blarg">', html)
|
||||
|
||||
# oruga not yet supported
|
||||
self.request.use_oruga = True
|
||||
self.assertRaises(NotImplementedError, action.render_icon)
|
||||
|
||||
def test_render_label(self):
|
||||
|
||||
# label is derived from key by default
|
||||
action = self.make_action('blarg')
|
||||
label = action.render_label()
|
||||
self.assertEqual(label, "Blarg")
|
||||
|
||||
# otherwise use what caller provides
|
||||
action = self.make_action('foo', label="Bar")
|
||||
label = action.render_label()
|
||||
self.assertEqual(label, "Bar")
|
||||
|
||||
def test_get_url(self):
|
||||
obj = {'foo': 'bar'}
|
||||
|
||||
# null by default
|
||||
action = self.make_action('blarg')
|
||||
url = action.get_url(obj)
|
||||
self.assertIsNone(url)
|
||||
|
||||
# or can be "static"
|
||||
action = self.make_action('blarg', url='/foo')
|
||||
url = action.get_url(obj)
|
||||
self.assertEqual(url, '/foo')
|
||||
|
||||
# or can be "dynamic"
|
||||
action = self.make_action('blarg', url=lambda o, i: '/yeehaw')
|
||||
url = action.get_url(obj)
|
||||
self.assertEqual(url, '/yeehaw')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue