|
Pierre-Yves Chibon |
74ef37 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
"""
|
|
Pierre-Yves Chibon |
9071b6 |
(c) 2015-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
Authors:
|
|
Pierre-Yves Chibon |
74ef37 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
"""
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
74ef37 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
import unittest
|
|
Pierre-Yves Chibon |
74ef37 |
import shutil
|
|
Pierre-Yves Chibon |
74ef37 |
import sys
|
|
Pierre-Yves Chibon |
74ef37 |
import os
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
74ef37 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
import pagure.lib
|
|
Pierre-Yves Chibon |
74ef37 |
import tests
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Clement Verna |
109c4b |
class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
74ef37 |
""" Tests for pagure_hook plugin of pagure """
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
def test_plugin_pagure_request(self):
|
|
Pierre-Yves Chibon |
74ef37 |
""" Test the pagure_request plugin on/off endpoint. """
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Lubomír Sedlář |
4443c5 |
output = self.app.get('/test/settings/Pagure requests')
|
|
Pierre-Yves Chibon |
74ef37 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'<title>Settings Pagure requests - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Aurélien Bompard |
626417 |
csrf_token = output.get_data(as_text=True).split(
|
|
Pierre-Yves Chibon |
74ef37 |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
data = {}
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Lubomír Sedlář |
4443c5 |
output = self.app.post('/test/settings/Pagure requests', data=data)
|
|
Pierre-Yves Chibon |
74ef37 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'<title>Settings Pagure requests - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
3f60e3 |
# Create the requests repo
|
|
Slavek Kabrda |
adea20 |
tests.create_projects_git(os.path.join(self.path, 'repos', 'requests'))
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Lubomír Sedlář |
4443c5 |
'/test/settings/Pagure requests', data=data,
|
|
Pierre-Yves Chibon |
1e4803 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
4beb7c |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure requests deactivated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Lubomír Sedlář |
4443c5 |
output = self.app.get('/test/settings/Pagure requests')
|
|
Pierre-Yves Chibon |
74ef37 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'<title>Settings Pagure requests - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'requests', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
74ef37 |
'post-receive.pagure')))
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
# Activate hook
|
|
Pierre-Yves Chibon |
74ef37 |
data = {
|
|
Pierre-Yves Chibon |
74ef37 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
74ef37 |
'active': 'y',
|
|
Pierre-Yves Chibon |
74ef37 |
}
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Lubomír Sedlář |
4443c5 |
'/test/settings/Pagure requests', data=data,
|
|
Pierre-Yves Chibon |
1e4803 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
4beb7c |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure requests activated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Lubomír Sedlář |
4443c5 |
output = self.app.get('/test/settings/Pagure requests')
|
|
Pierre-Yves Chibon |
74ef37 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'<title>Settings Pagure requests - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
# De-Activate hook
|
|
Pierre-Yves Chibon |
74ef37 |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Lubomír Sedlář |
4443c5 |
'/test/settings/Pagure requests', data=data,
|
|
Pierre-Yves Chibon |
1e4803 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
4beb7c |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Pagure requests deactivated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Lubomír Sedlář |
4443c5 |
output = self.app.get('/test/settings/Pagure requests')
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'<title>Settings Pagure requests - test - Pagure</title>',
|
|
Pierre-Yves Chibon |
9071b6 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'requests', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
74ef37 |
'post-receive.pagure-requests')))
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
|
|
Pierre-Yves Chibon |
74ef37 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|