|
Pierre-Yves Chibon |
1348de |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
"""
|
|
Pierre-Yves Chibon |
9071b6 |
(c) 2015-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
Authors:
|
|
Pierre-Yves Chibon |
1348de |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
"""
|
|
Pierre-Yves Chibon |
1348de |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
1348de |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
import unittest
|
|
Pierre-Yves Chibon |
1348de |
import sys
|
|
Pierre-Yves Chibon |
1348de |
import os
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
from mock import patch
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
1348de |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
import pagure.lib
|
|
Pierre-Yves Chibon |
1348de |
import tests
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
|
|
Clement Verna |
109c4b |
class PagureFlaskPluginFedmsgtests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
1348de |
""" Tests for fedmsg plugin of pagure """
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
def setUp(self):
|
|
Pierre-Yves Chibon |
1348de |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
1348de |
super(PagureFlaskPluginFedmsgtests, self).setUp()
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
4fe245 |
tests.create_projects_git(os.path.join(self.path, 'docs'))
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
e6f2ec |
def tearDown(self):
|
|
Pierre-Yves Chibon |
e6f2ec |
""" Tear Down the environment after the tests. """
|
|
Pierre-Yves Chibon |
e6f2ec |
super(PagureFlaskPluginFedmsgtests, self).tearDown()
|
|
Pierre-Yves Chibon |
e6f2ec |
pagure.config.config['DOCS_FOLDER'] = None
|
|
Pierre-Yves Chibon |
e6f2ec |
|
|
Pierre-Yves Chibon |
4fe245 |
def test_plugin_fedmsg_defaul_page(self):
|
|
Pierre-Yves Chibon |
4fe245 |
""" Test the fedmsg plugin endpoint's default page. """
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
1348de |
output = self.app.get('/test/settings/Fedmsg')
|
|
Pierre-Yves Chibon |
1348de |
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 |
9071b6 |
'<title>Settings Fedmsg - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Clement Verna |
2c8224 |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
4fe245 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
data = {}
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
output = self.app.post('/test/settings/Fedmsg', data=data)
|
|
Pierre-Yves Chibon |
1348de |
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 |
9071b6 |
'<title>Settings Fedmsg - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Clement Verna |
2c8224 |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
self.assertFalse(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Patrick Uiterwijk |
170974 |
'post-receive.fedmsg')))
|
|
Pierre-Yves Chibon |
4fe245 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
4fe245 |
self.path, 'docs', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
4fe245 |
'post-receive')))
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
def test_plugin_fedmsg_no_data(self):
|
|
Pierre-Yves Chibon |
4fe245 |
""" Test the setting up the fedmsg plugin when there are no Docs
|
|
Pierre-Yves Chibon |
4fe245 |
folder.
|
|
Pierre-Yves Chibon |
4fe245 |
"""
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
4fe245 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
4fe245 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
# With the git repo
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Fedmsg', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
1348de |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
4beb7c |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Fedmsg deactivated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
9071b6 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Fedmsg', data=data)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Fedmsg - test - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertIn(
|
|
Clement Verna |
2c8224 |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
self.assertFalse(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Patrick Uiterwijk |
170974 |
'post-receive.fedmsg')))
|
|
Pierre-Yves Chibon |
4fe245 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
4fe245 |
self.path, 'docs', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
4fe245 |
'post-receive')))
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
def test_plugin_fedmsg_activate(self):
|
|
Pierre-Yves Chibon |
4fe245 |
""" Test the setting up the fedmsg plugin when there are no Docs
|
|
Pierre-Yves Chibon |
4fe245 |
folder.
|
|
Pierre-Yves Chibon |
4fe245 |
"""
|
|
Pierre-Yves Chibon |
e6f2ec |
pagure.config.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
e6f2ec |
self.path, 'repos', 'docs')
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
4fe245 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
# Activate hook
|
|
Pierre-Yves Chibon |
1348de |
data = {
|
|
Pierre-Yves Chibon |
1348de |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
1348de |
'active': 'y',
|
|
Pierre-Yves Chibon |
1348de |
}
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Fedmsg', data=data, 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 |
1e4803 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
4beb7c |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Fedmsg activated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
9071b6 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Fedmsg', data=data)
|
|
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 |
9071b6 |
'<title>Settings Fedmsg - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Clement Verna |
2c8224 |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
7c1138 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Patrick Uiterwijk |
170974 |
'post-receive.fedmsg')))
|
|
Pierre-Yves Chibon |
4fe245 |
self.assertTrue(os.path.exists(os.path.join(
|
|
Slavek Kabrda |
adea20 |
self.path, 'repos', 'docs', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
4fe245 |
'post-receive')))
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
def test_plugin_fedmsg_deactivate(self):
|
|
Pierre-Yves Chibon |
4fe245 |
""" Test the setting up the fedmsg plugin when there are no Docs
|
|
Pierre-Yves Chibon |
4fe245 |
folder.
|
|
Pierre-Yves Chibon |
4fe245 |
"""
|
|
Pierre-Yves Chibon |
4fe245 |
self.test_plugin_fedmsg_activate()
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
4fe245 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
# De-Activate hook
|
|
Pierre-Yves Chibon |
1348de |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Fedmsg', data=data, 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 |
1e4803 |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
''
|
|
Pierre-Yves Chibon |
9071b6 |
'Project Settings\n', output_text)
|
|
Pierre-Yves Chibon |
4beb7c |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Hook Fedmsg deactivated',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
9071b6 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Fedmsg', data=data)
|
|
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 |
9071b6 |
'<title>Settings Fedmsg - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Clement Verna |
2c8224 |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
self.assertFalse(os.path.exists(os.path.join(
|
|
Patrick Uiterwijk |
170974 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Patrick Uiterwijk |
170974 |
'post-receive.fedmsg')))
|
|
Pierre-Yves Chibon |
4fe245 |
self.assertTrue(os.path.exists(os.path.join(
|
|
Slavek Kabrda |
adea20 |
self.path, 'repos', 'docs', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
4fe245 |
'post-receive')))
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
b130e5 |
@patch.dict('pagure.config.config', {'DOCS_FOLDER': None})
|
|
Pierre-Yves Chibon |
4fe245 |
def test_plugin_fedmsg_no_docs(self):
|
|
Pierre-Yves Chibon |
4fe245 |
""" Test the setting up the fedmsg plugin when there are no Docs
|
|
Pierre-Yves Chibon |
4fe245 |
folder.
|
|
Pierre-Yves Chibon |
4fe245 |
"""
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
4fe245 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
# Activate hook
|
|
Pierre-Yves Chibon |
4fe245 |
data = {
|
|
Pierre-Yves Chibon |
4fe245 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
4fe245 |
'active': 'y',
|
|
Pierre-Yves Chibon |
4fe245 |
}
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
4fe245 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
4fe245 |
'/test/settings/Fedmsg', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
4fe245 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
4fe245 |
|
|
Pierre-Yves Chibon |
7c1138 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
4fe245 |
self.path, 'repos', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
4fe245 |
'post-receive.fedmsg')))
|
|
Pierre-Yves Chibon |
4fe245 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
4fe245 |
self.path, 'docs', 'test.git', 'hooks',
|
|
Pierre-Yves Chibon |
4fe245 |
'post-receive')))
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
|
|
Pierre-Yves Chibon |
1348de |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|