3
0
Fork 0

fix: improve support for composite model_key in MasterView

in particular, had a table (Catapult) with composite primary key,
where both prop keys are named differently than columns.

this also splits out the route kwargs logic for action urls, because
of another situation where i wanted to use non-primary field as model
key, but it also needed to be stripped of whitespace.  this allows for
such an override but in the end i did not pursue that method and just
wound up using default model key anyway..
This commit is contained in:
Lance Edgar 2025-01-14 11:49:47 -06:00
parent 72a663a80b
commit ecb1dce590
2 changed files with 54 additions and 10 deletions

View file

@ -750,6 +750,29 @@ class TestMasterView(WebTestCase):
self.request.matchdict = {'name': 'blarg'}
self.assertRaises(HTTPNotFound, view.get_instance, session=self.session)
def test_get_action_route_kwargs(self):
model = self.app.model
with patch.object(mod.MasterView, 'model_class', new=model.Setting, create=True):
view = self.make_view()
# dict object
setting = {'name': 'foo', 'value': 'bar'}
kw = view.get_action_route_kwargs(setting)
self.assertEqual(kw, {'name': 'foo'})
# mapped object
setting = model.Setting(name='foo', value='bar')
kw = view.get_action_route_kwargs(setting)
self.assertEqual(kw, {'name': 'foo'})
# non-standard object
class MySetting:
def __init__(self, **kw):
self.__dict__.update(kw)
setting = MySetting(name='foo', value='bar')
kw = view.get_action_route_kwargs(setting)
self.assertEqual(kw, {'name': 'foo'})
def test_get_action_url_for_dict(self):
model = self.app.model
setting = {'name': 'foo', 'value': 'bar'}