3
0
Fork 0

fix: improve support for random objects with grid, master view

thus far we expected either dict or "native" ORM object which can
essentially behave like a dict when needed.  but a "non-native" object
may not behave like a dict and this hopefully fixes the logic to allow
for those anyway..
This commit is contained in:
Lance Edgar 2024-11-25 19:11:41 -06:00
parent ba9021c990
commit dcdc0e7dab
4 changed files with 70 additions and 3 deletions

View file

@ -734,6 +734,41 @@ class TestMasterView(WebTestCase):
self.request.matchdict = {'name': 'blarg'}
self.assertRaises(HTTPNotFound, view.get_instance, session=self.session)
def test_get_action_url_for_dict(self):
model = self.app.model
setting = {'name': 'foo', 'value': 'bar'}
with patch.multiple(mod.MasterView, create=True,
model_class=model.Setting):
mod.MasterView.defaults(self.pyramid_config)
view = self.make_view()
url = view.get_action_url_view(setting, 0)
self.assertEqual(url, self.request.route_url('settings.view', name='foo'))
def test_get_action_url_for_orm_object(self):
model = self.app.model
setting = model.Setting(name='foo', value='bar')
self.session.add(setting)
self.session.commit()
with patch.multiple(mod.MasterView, create=True,
model_class=model.Setting):
mod.MasterView.defaults(self.pyramid_config)
view = self.make_view()
url = view.get_action_url_view(setting, 0)
self.assertEqual(url, self.request.route_url('settings.view', name='foo'))
def test_get_action_url_for_adhoc_object(self):
model = self.app.model
class MockSetting:
def __init__(self, **kw):
self.__dict__.update(kw)
setting = MockSetting(name='foo', value='bar')
with patch.multiple(mod.MasterView, create=True,
model_class=model.Setting):
mod.MasterView.defaults(self.pyramid_config)
view = self.make_view()
url = view.get_action_url_view(setting, 0)
self.assertEqual(url, self.request.route_url('settings.view', name='foo'))
def test_get_action_url_view(self):
model = self.app.model
setting = model.Setting(name='foo', value='bar')