|
farhaanbukhsh |
fbda94 |
# -*- coding: utf-8 -*-
|
|
farhaanbukhsh |
fbda94 |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
farhaanbukhsh |
fbda94 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
import unittest
|
|
farhaanbukhsh |
fbda94 |
import sys
|
|
farhaanbukhsh |
fbda94 |
import os
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
import tests
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
|
|
Clement Verna |
109c4b |
class PagureFlaskPluginPagureCItests(tests.SimplePagureTest):
|
|
farhaanbukhsh |
fbda94 |
""" Tests for flask plugins controller of pagure """
|
|
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)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_commit" type="checkbox" value="y">', output_text)
|
|
Clement Verna |
926cdd |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_pr" type="checkbox" value="y">', output_text)
|
|
farhaanbukhsh |
fbda94 |
|
|
Aurélien Bompard |
626417 |
csrf_token = output_text.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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_commit" type="checkbox" value="y">', output_text)
|
|
Clement Verna |
926cdd |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_pr" type="checkbox" value="y">', output_text)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
# Activate hook
|
|
farhaanbukhsh |
fbda94 |
data = {
|
|
Clement Verna |
926cdd |
'active_commit': 'y',
|
|
Pierre-Yves Chibon |
1e2f0d |
'ci_url': 'https://jenkins.fedoraproject.org',
|
|
Pierre-Yves Chibon |
1e2f0d |
'ci_type': 'jenkins',
|
|
Clement Verna |
5434db |
'ci_job': 'test/job'
|
|
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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_commit" type="checkbox" value="y">', output_text)
|
|
Clement Verna |
926cdd |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_pr" type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
|
|
Pierre-Yves Chibon |
1e2f0d |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
1e2f0d |
|
|
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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Settings - test - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
9071b6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure CI activated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
farhaanbukhsh |
fbda94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_commit" type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Neal Gompa |
9c34c4 |
'\nhttp://localhost.localdomain/api/0/ci/jenkins/test/',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure CI deactivated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
output = self.app.get('/test/settings/Pagure CI')
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_commit" type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
|
|
Pierre-Yves Chibon |
1e2f0d |
# Missing the required ci_url
|
|
Clement Verna |
926cdd |
data = {'csrf_token': csrf_token, 'active_commit': '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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
fbda94 |
self.assertIn(
|
|
Pierre-Yves Chibon |
440fae |
'<title>Settings Pagure CI - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
95e961 |
output_text)
|
|
Pierre-Yves Chibon |
95e961 |
self.assertNotIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure CI activated',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Pierre-Yves Chibon |
3e9b1d |
|
|
Pierre-Yves Chibon |
3e9b1d |
if self.get_wtforms_version() >= (2, 2):
|
|
Pierre-Yves Chibon |
3e9b1d |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a5ac6 |
'\n '
|
|
Pierre-Yves Chibon |
7a5ac6 |
'
|
|
Pierre-Yves Chibon |
7a5ac6 |
'required type="text" value="">\n \n \n '
|
|
Pierre-Yves Chibon |
7a5ac6 |
'This field is required. ',
|
|
Pierre-Yves Chibon |
3e9b1d |
output_text)
|
|
Pierre-Yves Chibon |
3e9b1d |
self.assertIn(
|
|
Pierre-Yves Chibon |
7a5ac6 |
'\n '
|
|
Pierre-Yves Chibon |
7a5ac6 |
'
|
|
Pierre-Yves Chibon |
7a5ac6 |
'required type="text" value="">\n \n \n '
|
|
Pierre-Yves Chibon |
7a5ac6 |
'This field is required. ',
|
|
Pierre-Yves Chibon |
3e9b1d |
output_text)
|
|
Pierre-Yves Chibon |
3e9b1d |
else:
|
|
Pierre-Yves Chibon |
3e9b1d |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'\n '
|
|
Ryan Lerch |
014c1c |
'
|
|
Ryan Lerch |
014c1c |
'type="text" value="">\n \n \n '
|
|
Ryan Lerch |
014c1c |
'This field is required. ',
|
|
Pierre-Yves Chibon |
3e9b1d |
output_text)
|
|
Pierre-Yves Chibon |
3e9b1d |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'\n '
|
|
Ryan Lerch |
014c1c |
'
|
|
Ryan Lerch |
014c1c |
'type="text" value="">\n \n \n '
|
|
Ryan Lerch |
014c1c |
'This field is required. ',
|
|
Pierre-Yves Chibon |
3e9b1d |
output_text)
|
|
Pierre-Yves Chibon |
1e2f0d |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'name="active_commit" type="checkbox" value="y">', output_text)
|
|
farhaanbukhsh |
fbda94 |
|
|
Pierre-Yves Chibon |
7f3b76 |
def test_plugin_pagure_ci_namespaced(self):
|
|
Pierre-Yves Chibon |
7f3b76 |
""" Test the pagure ci plugin on/off endpoint. """
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
Pierre-Yves Chibon |
7f3b76 |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
Pierre-Yves Chibon |
7f3b76 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
7f3b76 |
output = self.app.get('/somenamespace/test3/settings/Pagure CI')
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - somenamespace/test3 - '</title>
|
|
Pierre-Yves Chibon |
9071b6 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
Aurélien Bompard |
626417 |
csrf_token = output_text.split(
|
|
Pierre-Yves Chibon |
7f3b76 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
Pierre-Yves Chibon |
7f3b76 |
# Activate hook
|
|
Pierre-Yves Chibon |
7f3b76 |
data = {
|
|
Clement Verna |
926cdd |
'active_pr': 'y',
|
|
Pierre-Yves Chibon |
7f3b76 |
'ci_url': 'https://jenkins.fedoraproject.org',
|
|
Clement Verna |
5434db |
'ci_job': 'test/job',
|
|
Pierre-Yves Chibon |
7f3b76 |
'ci_type': 'jenkins',
|
|
Pierre-Yves Chibon |
7f3b76 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
7f3b76 |
}
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
Pierre-Yves Chibon |
7f3b76 |
# Activate hook
|
|
Pierre-Yves Chibon |
7f3b76 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7f3b76 |
'/somenamespace/test3/settings/Pagure CI', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Settings - somenamespace/test3 - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure CI activated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
Pierre-Yves Chibon |
7f3b76 |
output = self.app.get('/somenamespace/test3/settings/Pagure CI')
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Pagure CI - somenamespace/test3 - '</title>
|
|
Pierre-Yves Chibon |
9071b6 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_url">URL to the project on the CI '</label>
|
|
Aurélien Bompard |
626417 |
'service', output_text)
|
|
Clement Verna |
5434db |
self.assertIn(
|
|
Clement Verna |
5434db |
'<label for="ci_job">Name of the job to trigger'</label>
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
self.assertIn(
|
|
Neal Gompa |
9c34c4 |
'\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
7f3b76 |
|
|
farhaanbukhsh |
fbda94 |
|
|
farhaanbukhsh |
fbda94 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|