def testStructureParams(self): source = DummySource() model = DummyModel(source) action = yield TestAction2.create(model) res = yield action.perform(struc=dict(field1=444)) self.assertEqual('444', res) # now test errors try: yield action.perform( struc=dict(field1='not integer')) except InvalidParameters, e: self.assertEqual(('struc.field1', ), e.parameters)
def perform(action): if action is None: raise NotSupported("Attribute %s not deletable" % self.name) return action.perform()
def testSubAction(self): source = DummySource() model = DummyModel(source) action = yield TestSubAction.create(model) self.assertTrue(IModelAction.providedBy(action)) self.assertEqual(action.name, None) self.assertEqual(action.label, u"Sub Action") self.assertTrue(isinstance(action.label, unicode)) self.assertEqual(action.desc, u"Some sub action") self.assertTrue(isinstance(action.desc, unicode)) self.assertTrue(IValueInfo.providedBy(action.result_info)) enabled = yield action.fetch_enabled() self.assertTrue(enabled) self.assertEqual(len(action.parameters), 5) params = dict([(p.name, p) for p in action.parameters]) param = params[u"value"] self.assertTrue(IActionParam.providedBy(param)) param = params[u"toto"] self.assertTrue(IActionParam.providedBy(param)) param = params[u"titi"] self.assertTrue(IActionParam.providedBy(param)) param = params[u"tata"] self.assertTrue(IActionParam.providedBy(param)) param = params["delim"] self.assertTrue(IActionParam.providedBy(param)) self.assertEqual(param.name, "delim") self.assertTrue(isinstance(param.name, unicode)) self.assertTrue(IValueInfo.providedBy(param.value_info)) self.assertEqual(param.label, u"Delimiter") self.assertTrue(isinstance(param.label, unicode)) self.assertEqual(param.desc, u"Delimiter parameter") self.assertTrue(isinstance(param.desc, unicode)) self.assertFalse(param.is_required) self.assertEqual(model.value, None) res = yield action.perform(33, toto=66) # 33 + 66 - 3 self.assertEqual(res, 96) self.assertTrue(isinstance(res, int)) self.assertEqual(model.value, "96 foo") self.assertTrue(isinstance(model.value, str)) res = yield action.perform(12, toto=66, titi=45) # 12 + 66 - 45 self.assertEqual(res, 33) self.assertEqual(model.value, u"33 foo") res = yield action.perform(77, toto=22, tata="bar") # 77 + 22 - 3 self.assertEqual(res, 96) self.assertEqual(model.value, "96 bar") res = yield action.perform("12", toto="3", titi="5") # 12 + 3 - 5 self.assertEqual(res, 10) self.assertEqual(model.value, "10 foo") yield self.asyncRaises(ValueError, action.perform, 42, toto=12, delim="@") res = yield action.perform(42, toto=12, delim="@", tata="@ bar") self.assertEqual(res, 51) self.assertEqual(model.value, "51 @ bar")
def testBaseAction(self): source = DummySource() model = DummyModel(source) aspect = DummyAspect(u"test", u"label", u"desc") action = yield TestAction.create(model, aspect) self.assertTrue(IModelAction.providedBy(action)) self.assertEqual(action.name, u"test") self.assertTrue(isinstance(action.name, unicode)) self.assertEqual(action.label, u"label") self.assertTrue(isinstance(action.label, unicode)) self.assertEqual(action.desc, u"desc") self.assertTrue(isinstance(action.desc, unicode)) self.assertTrue(IValueInfo.providedBy(action.result_info)) enabled = yield action.fetch_enabled() self.assertTrue(enabled) self.assertEqual(len(action.parameters), 4) params = dict([(p.name, p) for p in action.parameters]) param = params["value"] self.assertTrue(IActionParam.providedBy(param)) self.assertEqual(param.name, "value") self.assertTrue(isinstance(param.name, unicode)) self.assertTrue(IValueInfo.providedBy(param.value_info)) self.assertEqual(param.label, u"Value") self.assertTrue(isinstance(param.label, unicode)) self.assertEqual(param.desc, u"Value description") self.assertTrue(isinstance(param.desc, unicode)) self.assertTrue(param.is_required) param = params["toto"] self.assertTrue(IActionParam.providedBy(param)) self.assertEqual(param.name, "toto") self.assertTrue(isinstance(param.name, unicode)) self.assertTrue(IValueInfo.providedBy(param.value_info)) self.assertEqual(param.label, u"Int") self.assertTrue(isinstance(param.label, unicode)) self.assertEqual(param.desc, u"Some integer") self.assertTrue(isinstance(param.desc, unicode)) self.assertTrue(param.is_required) param = params["titi"] self.assertTrue(IActionParam.providedBy(param)) self.assertEqual(param.name, "titi") self.assertTrue(isinstance(param.name, unicode)) self.assertTrue(IValueInfo.providedBy(param.value_info)) self.assertEqual(param.label, None) self.assertEqual(param.desc, None) self.assertFalse(param.is_required) param = params["tata"] self.assertTrue(IActionParam.providedBy(param)) self.assertEqual(param.name, "tata") self.assertTrue(isinstance(param.name, unicode)) self.assertTrue(IValueInfo.providedBy(param.value_info)) self.assertEqual(param.label, None) self.assertEqual(param.desc, None) self.assertFalse(param.is_required) self.assertEqual(model.value, None) res = yield action.perform(33, toto=66) # 33 + 66 - 3 self.assertEqual(res, u"96 foo") self.assertTrue(isinstance(res, unicode)) self.assertEqual(model.value, 96) res = yield action.perform(12, toto=66, titi=45) # 12 + 66 - 45 self.assertEqual(res, u"33 foo") self.assertEqual(model.value, 33) res = yield action.perform(77, toto=22, tata="bar") # 77 + 22 - 3 self.assertEqual(res, u"96 bar") self.assertEqual(model.value, 96) res = yield action.perform("12", toto="3", titi="5") # 12 + 3 - 5 self.assertEqual(res, u"10 foo") self.assertEqual(model.value, 10)
action = yield TestAction2.create(model) res = yield action.perform(struc=dict(field1=444)) self.assertEqual('444', res) # now test errors try: yield action.perform( struc=dict(field1='not integer')) except InvalidParameters, e: self.assertEqual(('struc.field1', ), e.parameters) else: self.fail("Didn't raise!") try: yield action.perform( struc=dict(field1=2, unknown='a')) except UnknownParameters, e: self.assertEqual(('struc.unknown', ), e.parameters) else: self.fail("Didn't raise!") try: yield action.perform( struc=dict()) except MissingParameters, e: self.assertEqual(('struc.field1', ), e.parameters) else: self.fail("Didn't raise!") @defer.inlineCallbacks def testSubAction(self):