def test_add_hook(self): url = "http://this.is.a.url" prj = self._prj() hook = CodeDoubanHook.add(url, prj.id) hooked_project = CodeDoubanProject.get(hook.project_id) assert hooked_project assert hook.__dict__ == hooked_project.hooks[0].__dict__
def test_destroy_hook(self): url = "http://this.is.other.url" prj = self._prj() hook = CodeDoubanHook.add(url, prj.id) hooked_project = CodeDoubanProject.get(hook.project_id) assert len(hooked_project.hooks) == 1 hooked_project = CodeDoubanProject.get(hook.project_id) hook.destroy() assert len(hooked_project.hooks) == 0
def telchar(self, request): proj_id = self.proj_id user = request.user project = CodeDoubanProject.get(proj_id) url = TELCHAR_URL if project.is_owner(user): is_disable = request.get_form_var('close', '') if is_disable: hook = CodeDoubanHook.get_by_url(url) if hook: hook.destroy() status = 0 else: CodeDoubanHook.add(url, proj_id) status = 1 return {'r': 0, 'status': status} return {'r': 1}
def new(self, request): errors = '' project_name = self.proj_name user = request.user url = request.get_form_var('url') project = CodeDoubanProject.get_by_name(project_name) hooks = project.hooks if request.method == "POST": hook = CodeDoubanHook(0, url, project.id) exists_id = CodeDoubanHook.get_id_by_url(project.id, url) errors = hook.validate() if not project.is_owner(user): errors.append("You can't set hooks for this project") if exists_id is not None: errors.append("This hook url has exists") if not errors: CodeDoubanHook.add(hook.url, hook.project_id) return request.redirect('/%s/settings/hooks' % project_name) return st('settings/hooks.html', **locals())