|
Pierre-Yves Chibon |
7a8384 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
"""
|
|
Pierre-Yves Chibon |
7a8384 |
(c) 2016 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
Authors:
|
|
Pierre-Yves Chibon |
7a8384 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
"""
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
7a8384 |
import pkg_resources
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
import json
|
|
Pierre-Yves Chibon |
7a8384 |
import unittest
|
|
Pierre-Yves Chibon |
7a8384 |
import shutil
|
|
Pierre-Yves Chibon |
7a8384 |
import sys
|
|
Pierre-Yves Chibon |
7a8384 |
import os
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
import pygit2
|
|
Pierre-Yves Chibon |
7a8384 |
from mock import patch
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
7a8384 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
import pagure.lib
|
|
Pierre-Yves Chibon |
7a8384 |
import tests
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
class PagureFlaskPluginRtdHooktests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
7a8384 |
""" Tests for rtd_hook plugin of pagure """
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
def setUp(self):
|
|
Pierre-Yves Chibon |
7a8384 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
7a8384 |
super(PagureFlaskPluginRtdHooktests, self).setUp()
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.ui.plugins.SESSION = self.session
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.ui.filters.SESSION = self.session
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.APP.config['GIT_FOLDER'] = tests.HERE
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
7a8384 |
tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
7a8384 |
tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
7a8384 |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
7a8384 |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
7a8384 |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
def test_plugin_pagure_request(self):
|
|
Pierre-Yves Chibon |
7a8384 |
""" Test the pagure_request plugin on/off endpoint. """
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
7a8384 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.get('/test/settings/Read the Doc')
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n'
|
|
Pierre-Yves Chibon |
7a8384 |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn('Read the Doc settings', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'<input id="active" name="active" type="checkbox" value="y">',
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
7a8384 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
data = {}
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.post('/test/settings/Read the Doc', data=data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n'
|
|
Pierre-Yves Chibon |
7a8384 |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn('Read the Doc settings', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'<input id="active" name="active" type="checkbox" value="y">',
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
7a8384 |
# No git found
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.post('/test/settings/Read the Doc', data=data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
# Create both the requests repo
|
|
Pierre-Yves Chibon |
7a8384 |
tests.create_projects_git(os.path.join(tests.HERE, 'requests'))
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
# With the git repo
|
|
Pierre-Yves Chibon |
7a8384 |
tests.create_projects_git(tests.HERE)
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7a8384 |
'/test/settings/Read the Doc', data=data,
|
|
Pierre-Yves Chibon |
7a8384 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'<section class="settings">\n Settings for test',</section>
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n Hook Read the Doc inactived',
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.get('/test/settings/Read the Doc')
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n'
|
|
Pierre-Yves Chibon |
7a8384 |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn('Read the Doc settings', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'<input id="active" name="active" type="checkbox" value="y">',
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
7a8384 |
tests.HERE, 'requests', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
7a8384 |
'post-receive.pagure')))
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
# Activate hook
|
|
Pierre-Yves Chibon |
7a8384 |
data = {
|
|
Pierre-Yves Chibon |
7a8384 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
7a8384 |
'active': 'y',
|
|
Pierre-Yves Chibon |
7a8384 |
'project_name': 'foo',
|
|
Pierre-Yves Chibon |
7a8384 |
}
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7a8384 |
'/test/settings/Read the Doc', data=data,
|
|
Pierre-Yves Chibon |
7a8384 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'<section class="settings">\n Settings for test',</section>
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n Hook Read the Doc activated',
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.get('/test/settings/Read the Doc')
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n'
|
|
Pierre-Yves Chibon |
7a8384 |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn('Read the Doc settings', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'
|
|
Pierre-Yves Chibon |
7a8384 |
'value="y">', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertTrue(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
7a8384 |
tests.HERE, 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
7a8384 |
'post-receive.rtd')))
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
# De-Activate hook
|
|
Pierre-Yves Chibon |
7a8384 |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7a8384 |
'/test/settings/Read the Doc', data=data,
|
|
Pierre-Yves Chibon |
7a8384 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'<section class="settings">\n Settings for test',</section>
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n Hook Read the Doc inactived',
|
|
Pierre-Yves Chibon |
7a8384 |
output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.get('/test/settings/Read the Doc')
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'\n'
|
|
Pierre-Yves Chibon |
7a8384 |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn('Read the Doc settings', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a8384 |
'
|
|
Pierre-Yves Chibon |
7a8384 |
'value="y">', output.data)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
7a8384 |
tests.HERE, 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
7a8384 |
'post-receive.rtd')))
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
# Try re-activate hook w/o the git repo
|
|
Pierre-Yves Chibon |
7a8384 |
data = {
|
|
Pierre-Yves Chibon |
7a8384 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
7a8384 |
'active': 'y',
|
|
Pierre-Yves Chibon |
7a8384 |
'project_name': 'foo',
|
|
Pierre-Yves Chibon |
7a8384 |
}
|
|
Pierre-Yves Chibon |
7a8384 |
shutil.rmtree(os.path.join(tests.HERE, 'test.git'))
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
output = self.app.post('/test/settings/Read the Doc', data=data)
|
|
Pierre-Yves Chibon |
7a8384 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
|
|
Pierre-Yves Chibon |
7a8384 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
7a8384 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
7a8384 |
PagureFlaskPluginRtdHooktests)
|
|
Pierre-Yves Chibon |
7a8384 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|