|
farhaanbukhsh |
fbda94 |
# -*- coding: utf-8 -*-
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
farhaanbukhsh |
fbda94 |
import pkg_resources
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
import json
|
|
farhaanbukhsh |
fbda94 |
import unittest
|
|
farhaanbukhsh |
fbda94 |
import shutil
|
|
farhaanbukhsh |
fbda94 |
import sys
|
|
farhaanbukhsh |
fbda94 |
import os
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
import pygit2
|
|
farhaanbukhsh |
fbda94 |
from mock import patch
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
farhaanbukhsh |
fbda94 |
os.path.abspath(__file__)), '..'))
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
import pagure.lib
|
|
farhaanbukhsh |
fbda94 |
import tests
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
class PagureFlaskPluginPagureCItests(tests.Modeltests):
|
|
farhaanbukhsh |
fbda94 |
""" Tests for flask plugins controller of pagure """
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
def setUp(self):
|
|
farhaanbukhsh |
fbda94 |
""" Set up the environnment, ran before every tests. """
|
|
farhaanbukhsh |
fbda94 |
super(PagureFlaskPluginPagureCItests, self).setUp()
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
pagure.APP.config['TESTING'] = True
|
|
farhaanbukhsh |
fbda94 |
pagure.SESSION = self.session
|
|
farhaanbukhsh |
fbda94 |
pagure.ui.SESSION = self.session
|
|
farhaanbukhsh |
fbda94 |
pagure.ui.app.SESSION = self.session
|
|
farhaanbukhsh |
fbda94 |
pagure.ui.plugins.SESSION = self.session
|
|
farhaanbukhsh |
fbda94 |
pagure.ui.repo.SESSION = self.session
|
|
farhaanbukhsh |
fbda94 |
pagure.ui.filters.SESSION = self.session
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
pagure.APP.config['GIT_FOLDER'] = tests.HERE
|
|
farhaanbukhsh |
fbda94 |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
fbda94 |
tests.HERE, 'forks')
|
|
farhaanbukhsh |
fbda94 |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
fbda94 |
tests.HERE, 'tickets')
|
|
farhaanbukhsh |
fbda94 |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
fbda94 |
tests.HERE, 'docs')
|
|
farhaanbukhsh |
fbda94 |
self.app = pagure.APP.test_client()
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
def test_plugin_pagure_ci(self):
|
|
farhaanbukhsh |
fbda94 |
""" Test the pagure ci plugin on/off endpoint. """
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
tests.create_projects(self.session)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
user = tests.FakeUser(username='pingou')
|
|
farhaanbukhsh |
fbda94 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'\n'
|
|
farhaanbukhsh |
fbda94 |
'test project #1 ', output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue('Pagure CI settings' in output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Pierre-Yves Chibon |
1e2f0d |
'service' , output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<input id="active" name="active" type="checkbox" value="y">',
|
|
Pierre-Yves Chibon |
1e2f0d |
output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
csrf_token = output.data.split(
|
|
farhaanbukhsh |
fbda94 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
data = {}
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.post('/test/settings/Pagure CI', data=data)
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'\n'
|
|
farhaanbukhsh |
fbda94 |
'test project #1 ', output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue('Pagure CI settings' in output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Pierre-Yves Chibon |
1e2f0d |
'service' , output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<input id="active" name="active" type="checkbox" value="y">',
|
|
Pierre-Yves Chibon |
1e2f0d |
output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
# Activate hook
|
|
farhaanbukhsh |
fbda94 |
data = {
|
|
farhaanbukhsh |
fbda94 |
'active': 'y',
|
|
Pierre-Yves Chibon |
1e2f0d |
'ci_url': 'https://jenkins.fedoraproject.org',
|
|
Pierre-Yves Chibon |
1e2f0d |
'ci_type': 'jenkins',
|
|
farhaanbukhsh |
fbda94 |
}
|
|
Pierre-Yves Chibon |
1e2f0d |
# CSRF Token missing
|
|
farhaanbukhsh |
fbda94 |
output = self.app.post(
|
|
farhaanbukhsh |
fbda94 |
'/test/settings/Pagure CI', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'\n'
|
|
Pierre-Yves Chibon |
1e2f0d |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertTrue('Pagure CI settings' in output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Pierre-Yves Chibon |
1e2f0d |
'service' , output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'
|
|
Pierre-Yves Chibon |
1e2f0d |
'value="y">', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
|
|
Pierre-Yves Chibon |
1e2f0d |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
1e2f0d |
|
|
Pierre-Yves Chibon |
1e2f0d |
# No git found
|
|
Pierre-Yves Chibon |
1e2f0d |
output = self.app.post('/test/settings/Pagure', data=data)
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
tests.create_projects_git(tests.HERE)
|
|
farhaanbukhsh |
fbda94 |
|
|
Pierre-Yves Chibon |
117b2a |
if not pagure.APP.config.get('PAGURE_CI_SERVICES'):
|
|
Pierre-Yves Chibon |
51656a |
return
|
|
Pierre-Yves Chibon |
51656a |
|
|
Pierre-Yves Chibon |
1e2f0d |
# Activate hook
|
|
farhaanbukhsh |
fbda94 |
output = self.app.post(
|
|
farhaanbukhsh |
fbda94 |
'/test/settings/Pagure CI', data=data, follow_redirects=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'\n'
|
|
farhaanbukhsh |
fbda94 |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<title>Settings - test - Pagure</title>', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn('Settings for test', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'\n Hook Pagure CI activated',
|
|
Pierre-Yves Chibon |
1e2f0d |
output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'\n'
|
|
farhaanbukhsh |
fbda94 |
'test project #1 ', output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue('Pagure CI settings' in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Pierre-Yves Chibon |
1e2f0d |
'service' , output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<input checked="" id="active" name="active" type="checkbox" value="y">'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
Pierre-Yves Chibon |
1e2f0d |
# De-activate the hook
|
|
farhaanbukhsh |
fbda94 |
data = {
|
|
farhaanbukhsh |
fbda94 |
'csrf_token': csrf_token,
|
|
farhaanbukhsh |
fbda94 |
}
|
|
farhaanbukhsh |
fbda94 |
output = self.app.post(
|
|
farhaanbukhsh |
fbda94 |
'/test/settings/Pagure CI', data=data, follow_redirects=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'\n Hook Pagure CI inactived',
|
|
Pierre-Yves Chibon |
1e2f0d |
output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'<section class="settings">\n Settings for test',</section>
|
|
farhaanbukhsh |
fbda94 |
output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'\n'
|
|
farhaanbukhsh |
fbda94 |
'test project #1 ', output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue('Pagure CI settings' in output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Pierre-Yves Chibon |
1e2f0d |
'service' , output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'
|
|
Pierre-Yves Chibon |
1e2f0d |
'value="y">', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
|
|
Pierre-Yves Chibon |
1e2f0d |
# Missing the required ci_url
|
|
Pierre-Yves Chibon |
1e2f0d |
data = {'csrf_token': csrf_token, 'active': 'y'}
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.post(
|
|
farhaanbukhsh |
fbda94 |
'/test/settings/Pagure CI', data=data, follow_redirects=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'\n'
|
|
Pierre-Yves Chibon |
1e2f0d |
'test project #1 ', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn('Pagure CI settings', output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertFalse(
|
|
Pierre-Yves Chibon |
1e2f0d |
'\n Hook activated' in output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'<input id="ci_url" name="ci_url" type="text" value="">'
|
|
Pierre-Yves Chibon |
1e2f0d |
'\nThis field is required.',
|
|
farhaanbukhsh |
fbda94 |
output.data)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
1e2f0d |
'
|
|
Pierre-Yves Chibon |
1e2f0d |
'value="y">', output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
if __name__ == '__main__':
|
|
farhaanbukhsh |
fbda94 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
farhaanbukhsh |
fbda94 |
PagureFlaskPluginPagureCItests)
|
|
farhaanbukhsh |
fbda94 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|