3
0
Fork 0

tests: fix test per appinfo/configure changes

This commit is contained in:
Lance Edgar 2025-01-13 13:28:34 -06:00
parent 2b3d69a379
commit 013d921772

View file

@ -1528,42 +1528,50 @@ class TestMasterView(WebTestCase):
get_index_url=MagicMock(return_value='/appinfo/'), get_index_url=MagicMock(return_value='/appinfo/'),
configure_get_simple_settings=MagicMock(return_value=settings)): configure_get_simple_settings=MagicMock(return_value=settings)):
# get the form page # nb. appinfo/configure template requires menu_handlers
response = view.configure(session=self.session) original_context = view.configure_get_context
self.assertIsInstance(response, Response) def get_context(**kw):
kw = original_context(**kw)
kw['menu_handlers'] = []
return kw
with patch.object(view, 'configure_get_context', new=get_context):
# post request to save settings # get the form page
self.request.method = 'POST' response = view.configure(session=self.session)
self.request.POST = { self.assertIsInstance(response, Response)
'wutta.app_title': 'Wutta',
'wutta.foo': 'bar',
'wutta.flag': 'true',
}
response = view.configure(session=self.session)
# nb. should get redirect back to configure page
self.assertEqual(response.status_code, 302)
# should now have 5 settings # post request to save settings
count = self.session.query(model.Setting).count() self.request.method = 'POST'
self.assertEqual(count, 5) self.request.POST = {
get_setting = functools.partial(self.app.get_setting, self.session) 'wutta.app_title': 'Wutta',
self.assertEqual(get_setting('wutta.app_title'), 'Wutta') 'wutta.foo': 'bar',
self.assertEqual(get_setting('wutta.foo'), 'bar') 'wutta.flag': 'true',
self.assertEqual(get_setting('wutta.flag'), 'true') }
self.assertEqual(get_setting('wutta.number'), '42') response = view.configure(session=self.session)
self.assertEqual(get_setting('wutta.value1'), '') # nb. should get redirect back to configure page
self.assertEqual(get_setting('wutta.value2'), None) self.assertEqual(response.status_code, 302)
# post request to remove settings # should now have 5 settings
self.request.method = 'POST' count = self.session.query(model.Setting).count()
self.request.POST = {'remove_settings': '1'} self.assertEqual(count, 5)
response = view.configure(session=self.session) get_setting = functools.partial(self.app.get_setting, self.session)
# nb. should get redirect back to configure page self.assertEqual(get_setting('wutta.app_title'), 'Wutta')
self.assertEqual(response.status_code, 302) self.assertEqual(get_setting('wutta.foo'), 'bar')
self.assertEqual(get_setting('wutta.flag'), 'true')
self.assertEqual(get_setting('wutta.number'), '42')
self.assertEqual(get_setting('wutta.value1'), '')
self.assertEqual(get_setting('wutta.value2'), None)
# should now have 0 settings # post request to remove settings
count = self.session.query(model.Setting).count() self.request.method = 'POST'
self.assertEqual(count, 0) self.request.POST = {'remove_settings': '1'}
response = view.configure(session=self.session)
# nb. should get redirect back to configure page
self.assertEqual(response.status_code, 302)
# should now have 0 settings
count = self.session.query(model.Setting).count()
self.assertEqual(count, 0)
def test_configure_gather_settings(self): def test_configure_gather_settings(self):
view = self.make_view() view = self.make_view()