diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index fc446f5..b44cbed 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -11,7 +11,6 @@ import os import shutil import wtforms -import flask from pagure.exceptions import FileNotFoundException from pagure import APP, get_repo_path diff --git a/pagure/ui/plugins.py b/pagure/ui/plugins.py index 6102acd..88c9c8a 100644 --- a/pagure/ui/plugins.py +++ b/pagure/ui/plugins.py @@ -19,7 +19,7 @@ import pagure.lib import pagure.forms from pagure import APP, SESSION, login_required, is_repo_admin from pagure.lib.model import BASE - +from pagure.exceptions import FileNotFoundException # pylint: disable=E1101 @@ -127,11 +127,19 @@ def view_plugin(repo, plugin, username=None, full=True): # Set up the main script if necessary plugin.set_up(repo) # Install the plugin itself - plugin.install(repo, dbobj) - flask.flash('Hook %s activated' % plugin.name) + try: + plugin.install(repo, dbobj) + flask.flash('Hook %s activated' % plugin.name) + except FileNotFoundException as err: + pagure.APP.logger.exception(err) + flask.abort(404, 'No git repo found') else: - plugin.remove(repo) - flask.flash('Hook %s inactived' % plugin.name) + try: + plugin.remove(repo) + flask.flash('Hook %s inactived' % plugin.name) + except FileNotFoundException as err: + pagure.APP.logger.exception(err) + flask.abort(404, 'No git repo found') SESSION.commit() 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 26931f9..ec3bd34 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_request_hook.py @@ -17,7 +17,6 @@ import shutil import sys import os - import pygit2 from mock import patch from pagure.exceptions import FileNotFoundException @@ -87,7 +86,8 @@ class PagureFlaskPluginPagureRequestHooktests(tests.Modeltests): data['csrf_token'] = csrf_token # No git found - self.assertRaises(pagure.exceptions.FileNotFoundException) + output = self.app.post('/test/settings/Pagure requests', data=data) + self.assertEqual(output.status_code, 404) # 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 125f076..1cf1658 100644 --- a/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py +++ b/tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py @@ -86,7 +86,8 @@ class PagureFlaskPluginPagureTicketHooktests(tests.Modeltests): data['csrf_token'] = csrf_token # No git found - self.assertRaises(pagure.exceptions.FileNotFoundException) + output = self.app.post('/test/settings/Pagure tickets', data=data) + self.assertEqual(output.status_code, 404) # Create both the tickets repo tests.create_projects_git(os.path.join(tests.HERE, 'tickets'))