def test_iadd(self): from ptah import form btn1 = form.Button(name='test1', actionName='action') btn2 = form.Button(name='test2', actionName='action') btns1 = form.Buttons(btn1) btns2 = form.Buttons(btn2) btns = btns1 + btns2 self.assertEqual(list(btns.keys()), [btn1.name, btn2.name]) self.assertEqual(list(btns.values()), [btn1, btn2])
def test_update(self): from ptah import form request = DummyRequest() tform = DummyForm() def disabled(form): return False res = {} def action1(form): res['action1'] = True def action2(form): # pragma: no cover res['action2'] = True btn1 = form.Button(name='test1', action=action1) btn2 = form.Button(name='test2', action=action2, condition=disabled) tform.buttons = form.Buttons(btn1, btn2) actions = self._makeOne(tform, request) actions.update() self.assertEqual(list(actions.keys()), [btn1.name]) self.assertEqual(actions[btn1.name].name, 'form.buttons.test1') actions.execute() self.assertEqual(res, {}) params = {'form.buttons.test1': 'true', 'form.buttons.test2': 'true'} tform.params = params actions.update() actions.execute() self.assertEqual(res, {'action1': True})
def test_add_duplicate(self): from ptah import form btn1 = form.Button(name='test1', actionName='action') btn2 = form.Button(name='test1', actionName='action') btns = form.Buttons(btn1) self.assertRaises(ValueError, btns.add, btn2)
def test_ctor(self): from ptah import form btn1 = form.Button(name='test1', actionName='action') btn2 = form.Button(name='test2', actionName='action') btns = form.Buttons() self.assertFalse(bool(btns)) btns = form.Buttons(btn1, btn2) self.assertEqual(list(btns.keys()), [btn1.name, btn2.name]) self.assertEqual(list(btns.values()), [btn1, btn2]) btns = form.Buttons(btn1) self.assertEqual(list(btns.keys()), [btn1.name]) btns = form.Buttons(btn2, btns) self.assertEqual(list(btns.keys()), [btn2.name, btn1.name]) self.assertEqual(list(btns.values()), [btn2, btn1])
def test_add_action(self): from ptah import form btns = form.Buttons() btn1 = btns.add_action('Test action') self.assertIsInstance(btn1, form.Button) self.assertEqual(list(btns.keys()), [btn1.name]) self.assertEqual(list(btns.values()), [btn1])