|
Pierre-Yves Chibon |
0ce05f |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
"""
|
|
Pierre-Yves Chibon |
0ce05f |
(c) 2016 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
Authors:
|
|
Pierre-Yves Chibon |
0ce05f |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
"""
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
0ce05f |
import pkg_resources
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
import json
|
|
Pierre-Yves Chibon |
0ce05f |
import unittest
|
|
Pierre-Yves Chibon |
0ce05f |
import shutil
|
|
Pierre-Yves Chibon |
0ce05f |
import sys
|
|
Pierre-Yves Chibon |
0ce05f |
import os
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
import pygit2
|
|
Pierre-Yves Chibon |
0ce05f |
from mock import patch
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
0ce05f |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
import pagure.lib
|
|
Pierre-Yves Chibon |
0ce05f |
import tests
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Clement Verna |
109c4b |
class PagureFlaskPluginUnsignedtests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
0ce05f |
""" Tests for Block pushes with unsigned commit plugin of pagure """
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
def setUp(self):
|
|
Pierre-Yves Chibon |
0ce05f |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
0ce05f |
super(PagureFlaskPluginUnsignedtests, self).setUp()
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.ui.plugins.SESSION = self.session
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
0ce05f |
pagure.ui.filters.SESSION = self.session
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
7f1275 |
def test_plugin_unsigned(self):
|
|
Pierre-Yves Chibon |
0ce05f |
""" Test the noff plugin on/off endpoint. """
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
0ce05f |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.get(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits')
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n'
|
|
Pierre-Yves Chibon |
0ce05f |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'Block Un-Signed commits settings',
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ce05f |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
0ce05f |
in output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
0ce05f |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
data = {}
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits', data=data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n'
|
|
Pierre-Yves Chibon |
0ce05f |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'Block Un-Signed commits settings',
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ce05f |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
0ce05f |
in output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
# With the git repo
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits',
|
|
Pierre-Yves Chibon |
0ce05f |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'<section class="settings">\n Settings for test',</section>
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n Hook Block Un-Signed '
|
|
Michael Watters |
f855b8 |
'commits deactivated' in output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.get(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits')
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n'
|
|
Pierre-Yves Chibon |
0ce05f |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'Block Un-Signed commits settings',
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ce05f |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
0ce05f |
in output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertFalse(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
0ce05f |
'pre-receive.pagureunsignedcommit')))
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
# Activate the hook
|
|
Pierre-Yves Chibon |
0ce05f |
data = {'csrf_token': csrf_token, 'active': 'y'}
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits',
|
|
Pierre-Yves Chibon |
0ce05f |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n'
|
|
Pierre-Yves Chibon |
0ce05f |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'<section class="settings">\n Settings for test',</section>
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n Hook activated',
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertTrue(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
0ce05f |
'pre-receive.pagureunsignedcommit')))
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
# De-Activate hook
|
|
Pierre-Yves Chibon |
0ce05f |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits',
|
|
Pierre-Yves Chibon |
0ce05f |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'<section class="settings">\n Settings for test',</section>
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertTrue(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n Hook Block Un-Signed '
|
|
Michael Watters |
f855b8 |
'commits deactivated' in output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
output = self.app.get(
|
|
Pierre-Yves Chibon |
0ce05f |
'/test/settings/Block Un-Signed commits')
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'\n'
|
|
Pierre-Yves Chibon |
0ce05f |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'Block Un-Signed commits settings',
|
|
Pierre-Yves Chibon |
0ce05f |
output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertIn(
|
|
Pierre-Yves Chibon |
0ce05f |
'
|
|
Pierre-Yves Chibon |
0ce05f |
'value="y">', output.data)
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
self.assertFalse(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
0ce05f |
'pre-receive.pagureunsignedcommit')))
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
|
|
Pierre-Yves Chibon |
0ce05f |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|