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 upgrade(): bind = op.get_bind() session = orm.Session(bind=bind) try: for row in session.query(EventHandlerOption).filter( EventHandlerOption.Key == 'reply_to'): evh_id = row.eventhandler_id check = session.query(EventHandlerOption).filter( and_(EventHandlerOption.Key.like('reply_to %'), EventHandlerOption.eventhandler_id == evh_id)).first() if not check: reply_email = row.Value row.Value = NOTIFY_TYPE.EMAIL row.save() EventHandlerOption(evh_id, 'reply_to email', reply_email).save() else: continue except Exception as e: session.rollback() print(e) finally: session.commit()