|
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)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="pagure_name">Name of project in Pagure</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_name">Name of project in Jenkins</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_url">Jenkins URL</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_token">Jenkins token</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
farhaanbukhsh |
fbda94 |
in 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)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="pagure_name">Name of project in Pagure</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_name">Name of project in Jenkins</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_url">Jenkins URL</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_token">Jenkins token</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
# Activate hook
|
|
farhaanbukhsh |
fbda94 |
data = {
|
|
farhaanbukhsh |
fbda94 |
'csrf_token': csrf_token,
|
|
farhaanbukhsh |
fbda94 |
'active': 'y',
|
|
farhaanbukhsh |
fbda94 |
'pagure_name': 'test',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_name': 'jenkins_test',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_url': 'https://jenkins.fedoraproject.org',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_token': 'BEEFCAFE'
|
|
farhaanbukhsh |
fbda94 |
}
|
|
farhaanbukhsh |
fbda94 |
# No git found
|
|
farhaanbukhsh |
fbda94 |
output = self.app.post(
|
|
farhaanbukhsh |
fbda94 |
'/test/settings/Pagure CI', data=data, follow_redirects=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
tests.create_projects_git(tests.HERE)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
data = {'csrf_token': csrf_token}
|
|
farhaanbukhsh |
fbda94 |
# With the git repo
|
|
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 |
|
|
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.assertFalse(
|
|
farhaanbukhsh |
fbda94 |
'\n Hook activated' in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="pagure_name" name="pagure_name" type="text" value="">'
|
|
farhaanbukhsh |
fbda94 |
'\nThis field is required.'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="active" name="active" type="checkbox" value="y">' in 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.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="pagure_name">Name of project in Pagure</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_name">Name of project in Jenkins</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_url">Jenkins URL</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_token">Jenkins token</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input checked="" id="active" name="active" type="checkbox" value="y">'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
# Missing the required
|
|
farhaanbukhsh |
fbda94 |
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(
|
|
farhaanbukhsh |
fbda94 |
'\n'
|
|
farhaanbukhsh |
fbda94 |
'test project #1 ', output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue('Pagure CI settings' in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertFalse(
|
|
farhaanbukhsh |
fbda94 |
'\n Hook activated' in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="pagure_name" name="pagure_name" type="text" value="">'
|
|
farhaanbukhsh |
fbda94 |
'\nThis field is required.'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'
|
|
farhaanbukhsh |
fbda94 |
'value="y">' in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
# Activate hook
|
|
farhaanbukhsh |
fbda94 |
data = {
|
|
farhaanbukhsh |
fbda94 |
'csrf_token': csrf_token,
|
|
farhaanbukhsh |
fbda94 |
'active': 'y',
|
|
farhaanbukhsh |
fbda94 |
'pagure_name': 'test',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_name': 'jenkins_test',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_url': 'https://jenkins.fedoraproject.org',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_token': 'BEEFCAFE'
|
|
farhaanbukhsh |
fbda94 |
}
|
|
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(
|
|
farhaanbukhsh |
fbda94 |
'<section class="settings">\n Settings for test',</section>
|
|
farhaanbukhsh |
fbda94 |
output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'\n Hook Pagure CI activated' in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
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.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="pagure_name">Name of project in Pagure</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="pagure_name" name="pagure_name" type="text" value="test">'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<label for="jenkins_name">Name of project in Jenkins</label>'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input id="jenkins_name" name="jenkins_name" type="text" value="jenkins_test">'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
self.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'<input checked="" id="active" name="active" type="checkbox" value="y">'
|
|
farhaanbukhsh |
fbda94 |
in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
# De-Activate hook
|
|
farhaanbukhsh |
fbda94 |
data = {
|
|
farhaanbukhsh |
fbda94 |
'csrf_token': csrf_token,
|
|
farhaanbukhsh |
fbda94 |
'pagure_name': 'test',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_name': 'jenkins_test',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_url': 'https://jenkins.fedoraproject.org',
|
|
farhaanbukhsh |
fbda94 |
'jenkins_token': 'BEEFCAFE'
|
|
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.assertTrue(
|
|
farhaanbukhsh |
fbda94 |
'\n Hook Pagure CI inactived' in output.data)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
farhaanbukhsh |
fbda94 |
'<section class="settings">\n Settings for test',</section>
|
|
farhaanbukhsh |
fbda94 |
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)
|