From 45cdc3433e37009ec16274e4c5a9b636b3e3a127 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Apr 28 2016 18:39:19 +0000 Subject: Added exception for repo not found --- diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index b3aeb54..fc446f5 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -13,6 +13,7 @@ import shutil import wtforms import flask +from pagure.exceptions import FileNotFoundException from pagure import APP, get_repo_path @@ -85,8 +86,7 @@ class BaseHook(object): ''' for repopath in repopaths: if not os.path.exists(repopath): - APP.logger.debug('Hook install repo %s not found', repopath) - flask.abort(404, 'No git repo found') + raise FileNotFoundException('Repo %s not found' % repopath) hook_files = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'files') @@ -116,8 +116,7 @@ class BaseHook(object): ''' for repopath in repopaths: if not os.path.exists(repopath): - APP.logger.debug('Hook remove repo %s not found', repopath) - flask.abort(404, 'No git repo found') + raise FileNotFoundException('Repo %s not found' % repopath) hook_path = os.path.join(repopath, 'hooks', cls.hook_type + '.' + hook_name) diff --git a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py index a821bae..26931f9 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py @@ -17,8 +17,10 @@ import shutil import sys import os + import pygit2 from mock import patch +from pagure.exceptions import FileNotFoundException sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) @@ -85,8 +87,7 @@ class PagureFlaskPluginPagureRequestHooktests(tests.Modeltests): data['csrf_token'] = csrf_token # No git found - output = self.app.post('/test/settings/Pagure requests', data=data) - self.assertEqual(output.status_code, 404) + self.assertRaises(pagure.exceptions.FileNotFoundException) # Create both the requests repo tests.create_projects_git(os.path.join(tests.HERE, 'requests')) diff --git a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py index fcd8baa..125f076 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py @@ -19,6 +19,7 @@ import os import pygit2 from mock import patch +from pagure.exceptions import FileNotFoundException sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) @@ -85,8 +86,7 @@ class PagureFlaskPluginPagureTicketHooktests(tests.Modeltests): data['csrf_token'] = csrf_token # No git found - output = self.app.post('/test/settings/Pagure tickets', data=data) - self.assertEqual(output.status_code, 404) + self.assertRaises(pagure.exceptions.FileNotFoundException) # Create both the tickets repo tests.create_projects_git(os.path.join(tests.HERE, 'tickets'))