def test_hook_updated(self, settings_util): section = 'hooks' key = 'test_key' settings_util.create_rhodecode_ui(section, 'old value', key=key) model = SettingsModel() value = 'test value' model.create_or_update_hook(key, value) Session().commit() setting = model.get_ui_by_section_and_key('hooks', key) assert setting.ui_value == value
def settings_hooks_update(self): """POST or DELETE /admin/settings/hooks: All items in the collection""" # url('admin_settings_hooks') c.active = 'hooks' if c.visual.allow_custom_hooks_settings: ui_key = request.POST.get('new_hook_ui_key') ui_value = request.POST.get('new_hook_ui_value') hook_id = request.POST.get('hook_id') new_hook = False model = SettingsModel() try: if ui_value and ui_key: model.create_or_update_hook(ui_key, ui_value) h.flash(_('Added new hook'), category='success') new_hook = True elif hook_id: RhodeCodeUi.delete(hook_id) Session().commit() # check for edits update = False _d = request.POST.dict_of_lists() for k, v in zip(_d.get('hook_ui_key', []), _d.get('hook_ui_value_new', [])): model.create_or_update_hook(k, v) update = True if update and not new_hook: h.flash(_('Updated hooks'), category='success') Session().commit() except Exception: log.exception("Exception during hook creation") h.flash(_('Error occurred during hook creation'), category='error') return redirect(url('admin_settings_hooks'))
def test_hook_created(self): model = SettingsModel() key = 'test_key' value = 'test value' result = model.create_or_update_hook(key, value) Session().commit() setting = model.get_ui_by_section_and_key('hooks', key) try: assert setting == result assert isinstance(setting, RhodeCodeUi) finally: Session().delete(result) Session().commit()