fix: exclude FK fields by default, for model forms
e.g. `person_uuid` and such
This commit is contained in:
parent
c800ebf4e4
commit
c4fe90834e
2 changed files with 50 additions and 12 deletions
|
@ -11,6 +11,8 @@ from fanstatic import Library, Resource
|
|||
from pyramid import testing
|
||||
|
||||
from wuttjamaican.conf import WuttaConfig
|
||||
from wuttjamaican.testing import ConfigTestCase
|
||||
|
||||
from wuttaweb import util as mod
|
||||
|
||||
|
||||
|
@ -463,14 +465,10 @@ class TestGetFormData(TestCase):
|
|||
self.assertEqual(data, {'foo2': 'baz'})
|
||||
|
||||
|
||||
class TestGetModelFields(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = WuttaConfig()
|
||||
self.app = self.config.get_app()
|
||||
class TestGetModelFields(ConfigTestCase):
|
||||
|
||||
def test_empty_model_class(self):
|
||||
fields = mod.get_model_fields(self.config)
|
||||
fields = mod.get_model_fields(self.config, None)
|
||||
self.assertIsNone(fields)
|
||||
|
||||
def test_unknown_model_class(self):
|
||||
|
@ -482,6 +480,19 @@ class TestGetModelFields(TestCase):
|
|||
fields = mod.get_model_fields(self.config, model.Setting)
|
||||
self.assertEqual(fields, ['name', 'value'])
|
||||
|
||||
def test_include_fk(self):
|
||||
model = self.app.model
|
||||
|
||||
# fk excluded by default
|
||||
fields = mod.get_model_fields(self.config, model.User)
|
||||
self.assertNotIn('person_uuid', fields)
|
||||
self.assertIn('person', fields)
|
||||
|
||||
# fk can be included
|
||||
fields = mod.get_model_fields(self.config, model.User, include_fk=True)
|
||||
self.assertIn('person_uuid', fields)
|
||||
self.assertIn('person', fields)
|
||||
|
||||
def test_avoid_versions(self):
|
||||
model = self.app.model
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue