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
|
@ -59,8 +59,8 @@ class TestForm(TestCase):
|
|||
def tearDown(self):
|
||||
testing.tearDown()
|
||||
|
||||
def make_form(self, request=None, **kwargs):
|
||||
return base.Form(request or self.request, **kwargs)
|
||||
def make_form(self, **kwargs):
|
||||
return base.Form(self.request, **kwargs)
|
||||
|
||||
def make_schema(self):
|
||||
schema = colander.Schema(children=[
|
||||
|
@ -124,19 +124,33 @@ class TestForm(TestCase):
|
|||
self.assertIs(form.schema, schema)
|
||||
self.assertIs(form.get_schema(), schema)
|
||||
|
||||
# auto-generating schema not yet supported
|
||||
# schema is auto-generated if fields provided
|
||||
form = self.make_form(fields=['foo', 'bar'])
|
||||
schema = form.get_schema()
|
||||
self.assertEqual(len(schema.children), 2)
|
||||
self.assertEqual(schema['foo'].name, 'foo')
|
||||
|
||||
# but auto-generating without fields is not supported
|
||||
form = self.make_form()
|
||||
self.assertIsNone(form.schema)
|
||||
self.assertRaises(NotImplementedError, form.get_schema)
|
||||
|
||||
def test_get_deform(self):
|
||||
schema = self.make_schema()
|
||||
|
||||
# basic
|
||||
form = self.make_form(schema=schema)
|
||||
self.assertFalse(hasattr(form, 'deform_form'))
|
||||
dform = form.get_deform()
|
||||
self.assertIsInstance(dform, deform.Form)
|
||||
self.assertIs(form.deform_form, dform)
|
||||
|
||||
# with model instance / cstruct
|
||||
myobj = {'foo': 'one', 'bar': 'two'}
|
||||
form = self.make_form(schema=schema, model_instance=myobj)
|
||||
dform = form.get_deform()
|
||||
self.assertEqual(dform.cstruct, myobj)
|
||||
|
||||
def test_get_label(self):
|
||||
form = self.make_form(fields=['foo', 'bar'])
|
||||
self.assertEqual(form.get_label('foo'), "Foo")
|
||||
|
@ -193,6 +207,13 @@ class TestForm(TestCase):
|
|||
# nb. no error message
|
||||
self.assertNotIn('message', html)
|
||||
|
||||
# readonly
|
||||
html = form.render_vue_field('foo', readonly=True)
|
||||
self.assertIn('<b-field :horizontal="true" label="Foo">', html)
|
||||
self.assertNotIn('<b-input name="foo"', html)
|
||||
# nb. no error message
|
||||
self.assertNotIn('message', html)
|
||||
|
||||
# with single "static" error
|
||||
dform['foo'].error = MagicMock(msg="something is wrong")
|
||||
html = form.render_vue_field('foo')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue