|
Pierre-Yves Chibon |
317b75 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
"""
|
|
Pierre-Yves Chibon |
317b75 |
(c) 2016 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
Authors:
|
|
Pierre-Yves Chibon |
317b75 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
"""
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
317b75 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
317b75 |
import pkg_resources
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
import json
|
|
Pierre-Yves Chibon |
317b75 |
import unittest
|
|
Pierre-Yves Chibon |
317b75 |
import shutil
|
|
Pierre-Yves Chibon |
317b75 |
import sys
|
|
Pierre-Yves Chibon |
317b75 |
import os
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
1d97e0 |
import flask
|
|
Pierre-Yves Chibon |
317b75 |
import pygit2
|
|
Pierre-Yves Chibon |
1d97e0 |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
317b75 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
import pagure.lib
|
|
Pierre-Yves Chibon |
317b75 |
import tests
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
class PagureFlaskPluginDefaultHooktests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
317b75 |
""" Tests for default_hook plugin of pagure """
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
def test_plugin_default_ui(self):
|
|
Pierre-Yves Chibon |
317b75 |
""" Test the default hook plugin on/off endpoint. """
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
317b75 |
output = self.app.get('/test/settings/default')
|
|
Pierre-Yves Chibon |
317b75 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
def test_plugin_default_install(self):
|
|
Pierre-Yves Chibon |
317b75 |
""" Check that the default plugin is correctly installed when a
|
|
Pierre-Yves Chibon |
317b75 |
project is created.
|
|
Pierre-Yves Chibon |
317b75 |
"""
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Aurélien Bompard |
a7f281 |
task = pagure.lib.new_project(
|
|
Pierre-Yves Chibon |
317b75 |
self.session,
|
|
Pierre-Yves Chibon |
317b75 |
user='pingou',
|
|
Pierre-Yves Chibon |
317b75 |
name='test',
|
|
Patrick Uiterwijk |
3f97f6 |
repospanner_region=None,
|
|
Pierre-Yves Chibon |
317b75 |
blacklist=[],
|
|
Pierre-Yves Chibon |
317b75 |
allowed_prefix=[],
|
|
Pierre-Yves Chibon |
317b75 |
description=None,
|
|
Pierre-Yves Chibon |
317b75 |
url=None, avatar_email=None,
|
|
Pierre-Yves Chibon |
317b75 |
parent_id=None,
|
|
Pierre-Yves Chibon |
317b75 |
add_readme=False,
|
|
Pierre-Yves Chibon |
317b75 |
userobj=None,
|
|
Pierre-Yves Chibon |
317b75 |
prevent_40_chars=False,
|
|
Pierre-Yves Chibon |
317b75 |
namespace=None
|
|
Pierre-Yves Chibon |
317b75 |
)
|
|
Aurélien Bompard |
a7f281 |
self.assertEqual(task.get(),
|
|
Pierre-Yves Chibon |
b130e5 |
{'endpoint': 'ui_ns.view_repo',
|
|
Patrick Uiterwijk |
170974 |
'repo': 'test',
|
|
Patrick Uiterwijk |
170974 |
'namespace': None})
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
self.assertTrue(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks', 'post-receive')))
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
1d97e0 |
def test_plugin_default_remove(self):
|
|
Pierre-Yves Chibon |
1d97e0 |
""" Check that the default plugin can be correctly removed if
|
|
Pierre-Yves Chibon |
1d97e0 |
somehow managed.
|
|
Pierre-Yves Chibon |
1d97e0 |
"""
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
task = pagure.lib.new_project(
|
|
Pierre-Yves Chibon |
1d97e0 |
self.session,
|
|
Pierre-Yves Chibon |
1d97e0 |
user='pingou',
|
|
Pierre-Yves Chibon |
1d97e0 |
name='test',
|
|
Patrick Uiterwijk |
3f97f6 |
repospanner_region=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
blacklist=[],
|
|
Pierre-Yves Chibon |
1d97e0 |
allowed_prefix=[],
|
|
Pierre-Yves Chibon |
1d97e0 |
description=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
url=None, avatar_email=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
parent_id=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
add_readme=False,
|
|
Pierre-Yves Chibon |
1d97e0 |
userobj=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
prevent_40_chars=False,
|
|
Pierre-Yves Chibon |
1d97e0 |
namespace=None
|
|
Pierre-Yves Chibon |
1d97e0 |
)
|
|
Pierre-Yves Chibon |
1d97e0 |
self.assertEqual(task.get(),
|
|
Pierre-Yves Chibon |
1d97e0 |
{'endpoint': 'ui_ns.view_repo',
|
|
Pierre-Yves Chibon |
1d97e0 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
1d97e0 |
'namespace': None})
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
1d97e0 |
plugin = pagure.lib.plugins.get_plugin('default')
|
|
Pierre-Yves Chibon |
1d97e0 |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
plugin.remove(repo)
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
1d97e0 |
self.path, 'repos', 'test.git', 'hooks', 'post-receive.default')))
|
|
Pierre-Yves Chibon |
1d97e0 |
self.assertTrue(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
1d97e0 |
self.path, 'repos', 'test.git', 'hooks', 'post-receive')))
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
def test_plugin_default_form(self):
|
|
Pierre-Yves Chibon |
1d97e0 |
""" Check that the default plugin's form.
|
|
Pierre-Yves Chibon |
1d97e0 |
"""
|
|
Pierre-Yves Chibon |
1d97e0 |
with self._app.test_request_context('/') as ctx:
|
|
Pierre-Yves Chibon |
1d97e0 |
flask.g.session = self.session
|
|
Pierre-Yves Chibon |
1d97e0 |
flask.g.fas_user = tests.FakeUser(username='foo')
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
task = pagure.lib.new_project(
|
|
Pierre-Yves Chibon |
1d97e0 |
self.session,
|
|
Pierre-Yves Chibon |
1d97e0 |
user='pingou',
|
|
Pierre-Yves Chibon |
1d97e0 |
name='test',
|
|
Patrick Uiterwijk |
3f97f6 |
repospanner_region=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
blacklist=[],
|
|
Pierre-Yves Chibon |
1d97e0 |
allowed_prefix=[],
|
|
Pierre-Yves Chibon |
1d97e0 |
description=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
url=None, avatar_email=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
parent_id=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
add_readme=False,
|
|
Pierre-Yves Chibon |
1d97e0 |
userobj=None,
|
|
Pierre-Yves Chibon |
1d97e0 |
prevent_40_chars=False,
|
|
Pierre-Yves Chibon |
1d97e0 |
namespace=None
|
|
Pierre-Yves Chibon |
1d97e0 |
)
|
|
Pierre-Yves Chibon |
1d97e0 |
self.assertEqual(task.get(),
|
|
Pierre-Yves Chibon |
1d97e0 |
{'endpoint': 'ui_ns.view_repo',
|
|
Pierre-Yves Chibon |
1d97e0 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
1d97e0 |
'namespace': None})
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
1d97e0 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
1d97e0 |
plugin = pagure.lib.plugins.get_plugin('default')
|
|
Pierre-Yves Chibon |
1d97e0 |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
1d97e0 |
form = plugin.form(obj=dbobj)
|
|
Pierre-Yves Chibon |
1d97e0 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
1d97e0 |
str(form.active),
|
|
Pierre-Yves Chibon |
1d97e0 |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
1d97e0 |
)
|
|
Pierre-Yves Chibon |
1d97e0 |
|
|
Pierre-Yves Chibon |
317b75 |
|
|
Pierre-Yves Chibon |
317b75 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|