def test_19_add_update_delete_eventhandler(self): # Bind the module "usernotice" to the enroll event event = "enroll" event_update = "init" handlermodule = "usernotice" action = "email" condition = "always" options = {"mailserver": "blafoo", "option2": "value2"} conditions = {"user_type": "admin"} eh1 = EventHandler("ev1", event, handlermodule=handlermodule, action=action, condition=condition, options=options, conditions=conditions) self.assertTrue(eh1) self.assertEqual(eh1.event, event) self.assertEqual(eh1.handlermodule, handlermodule) self.assertEqual(eh1.action, action) self.assertEqual(eh1.condition, condition) self.assertEqual(eh1.option_list[0].Key, "mailserver") self.assertEqual(eh1.option_list[0].Value, "blafoo") self.assertEqual(eh1.option_list[1].Key, "option2") self.assertEqual(eh1.option_list[1].Value, "value2") self.assertEqual(eh1.condition_list[0].Key, "user_type") self.assertEqual(eh1.condition_list[0].Value, "admin") id = eh1.id # update eventhandler eh2 = EventHandler("ev1", event_update, handlermodule=handlermodule, action=action, condition=condition, options=options, ordering=0, id=id) self.assertEqual(eh1.event, event_update) # Update option value EventHandlerOption(id, Key="mailserver", Value="mailserver") self.assertEqual(eh1.option_list[0].Value, "mailserver") # Add Option EventHandlerOption(id, Key="option3", Value="value3") self.assertEqual(eh1.option_list[2].Key, "option3") self.assertEqual(eh1.option_list[2].Value, "value3") # Update condition value EventHandlerCondition(id, Key="user_type", Value="user") self.assertEqual(eh1.condition_list[0].Value, "user") # Add condition EventHandlerCondition(id, Key="result_value", Value="True") self.assertEqual(eh1.condition_list[0].Key, "result_value") self.assertEqual(eh1.condition_list[0].Value, "True") self.assertEqual(eh1.condition_list[1].Key, "user_type") self.assertEqual(eh1.condition_list[1].Value, "user") # Delete event handler eh1.delete()
def set_event(event, handlermodule, action, conditions=None, ordering=0, options=None, id=None): """ Set and event handling conifugration. This writes an entry to the database eventhandler. :param event: The name of the event to react on. Can be a single event or a comma separated list. :type event: basestring :param handlermodule: The identifier of the event handler module. This is an identifier string like "UserNotification" :type handlermodule: basestring :param action: The action to perform. This is an action defined by the handler module :type action: basestring :param conditions: A condition. Only if this condition is met, the action is performed. :type conditions: dict :param ordering: An optional ordering of the event definitions. :type ordering: integer :param options: Additional options, that are needed as parameters for the action :type options: dict :param id: The DB id of the event. If the id is given, the event is updated. Otherwiese a new entry is generated. :type id: int :return: The id of the event. """ conditions = conditions or {} if id: id = int(id) event = EventHandler(event, handlermodule, action, conditions=conditions, ordering=ordering, options=options, id=id) return event.id
def set_event(name=None, event=None, handlermodule=None, action=None, conditions=None, ordering=0, options=None, id=None, active=True, position="post"): """ Set an event handling configuration. This writes an entry to the database eventhandler. :param name: The name of the event definition :param event: The name of the event to react on. Can be a single event or a comma separated list. :type event: basestring :param handlermodule: The identifier of the event handler module. This is an identifier string like "UserNotification" :type handlermodule: basestring :param action: The action to perform. This is an action defined by the handler module :type action: basestring :param conditions: A condition. Only if this condition is met, the action is performed. :type conditions: dict :param ordering: An optional ordering of the event definitions. :type ordering: integer :param options: Additional options, that are needed as parameters for the action :type options: dict :param id: The DB id of the event. If the id is given, the event is updated. Otherwise a new entry is generated. :type id: int :param position: The position of the event handler being "post" or "pre" :type position: basestring :return: The id of the event. """ if type(event) == list: event = ",".join(event) conditions = conditions or {} if id: id = int(id) event = EventHandler(name, event, handlermodule, action, conditions=conditions, ordering=ordering, options=options, id=id, active=active, position=position) return event.id