|
Pierre-Yves Chibon |
65ffcd |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
"""
|
|
Pierre-Yves Chibon |
65ffcd |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
Authors:
|
|
Pierre-Yves Chibon |
65ffcd |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
"""
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
65ffcd |
import pkg_resources
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
import json
|
|
Pierre-Yves Chibon |
65ffcd |
import unittest
|
|
Pierre-Yves Chibon |
65ffcd |
import shutil
|
|
Pierre-Yves Chibon |
65ffcd |
import sys
|
|
Pierre-Yves Chibon |
65ffcd |
import os
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
import pygit2
|
|
Pierre-Yves Chibon |
65ffcd |
from mock import patch
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
65ffcd |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
fe5017 |
import pagure.lib
|
|
Pierre-Yves Chibon |
65ffcd |
import tests
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
fe5017 |
class PagureFlaskPluginMailtests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for flask plugins controller of pagure """
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
def setUp(self):
|
|
Pierre-Yves Chibon |
65ffcd |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
fe5017 |
super(PagureFlaskPluginMailtests, self).setUp()
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.ui.plugins.SESSION = self.session
|
|
Pierre-Yves Chibon |
59394d |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['GIT_FOLDER'] = tests.HERE
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
65ffcd |
tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
65ffcd |
tests.HERE, 'tickets')
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
65ffcd |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
fe5017 |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
def test_plugin_mail(self):
|
|
Pierre-Yves Chibon |
65ffcd |
""" Test the mail plugin on/off endpoint. """
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
fe5017 |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
65ffcd |
output = self.app.get('/test/settings/Mail')
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('test project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('Mail' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<label for="mail_to">Mail to</label>'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
csrf_token = output.data.split(
|
|
Pierre-Yves Chibon |
65ffcd |
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
data = {}
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
output = self.app.post('/test/settings/Mail', data=data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('test project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('Mail' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<label for="mail_to">Mail to</label>'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
data['csrf_token'] = csrf_token
|
|
Pierre-Yves Chibon |
65ffcd |
# No git found
|
|
Pierre-Yves Chibon |
65ffcd |
output = self.app.post('/test/settings/Mail', data=data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
tests.create_projects_git(tests.HERE)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
# With the git repo
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Mail', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertTrue('Settings' in output.data)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
1e4803 |
'Hook Mail inactived' in output.data)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Mail')
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('test project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('Mail' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<label for="mail_to">Mail to</label>'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<input id="active" name="active" type="checkbox" value="y">'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
aad1a6 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
aad1a6 |
tests.HERE, 'test.git', 'hooks', 'post-receive.mail')))
|
|
Pierre-Yves Chibon |
aad1a6 |
|
|
Pierre-Yves Chibon |
65ffcd |
# Missing the required mail_to
|
|
Pierre-Yves Chibon |
65ffcd |
data = {'csrf_token': csrf_token, 'active': 'y'}
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Mail', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('test project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('Mail' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertFalse(
|
|
Pierre-Yves Chibon |
65ffcd |
'Hook activated' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<input id="mail_to" name="mail_to" type="text" value="">'
|
|
Pierre-Yves Chibon |
65ffcd |
'\nThis field is required.'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'
|
|
Pierre-Yves Chibon |
65ffcd |
'value="y">' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
aad1a6 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
aad1a6 |
tests.HERE, 'test.git', 'hooks', 'post-receive.mail')))
|
|
Pierre-Yves Chibon |
aad1a6 |
|
|
Pierre-Yves Chibon |
65ffcd |
# Activate hook
|
|
Pierre-Yves Chibon |
65ffcd |
data = {
|
|
Pierre-Yves Chibon |
65ffcd |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
65ffcd |
'active': 'y',
|
|
Pierre-Yves Chibon |
65ffcd |
'mail_to': 'foo@bar'
|
|
Pierre-Yves Chibon |
65ffcd |
}
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Mail', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertTrue('Settings' in output.data)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
1e4803 |
'Hook Mail activated' in output.data)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Mail')
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('test project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('Mail' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<label for="mail_to">Mail to</label>'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'
|
|
Pierre-Yves Chibon |
65ffcd |
'value="y">' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
aad1a6 |
self.assertTrue(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
aad1a6 |
tests.HERE, 'test.git', 'hooks', 'post-receive.mail')))
|
|
Pierre-Yves Chibon |
aad1a6 |
|
|
Pierre-Yves Chibon |
65ffcd |
# De-Activate hook
|
|
Pierre-Yves Chibon |
65ffcd |
data = {'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1e4803 |
'/test/settings/Mail', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertTrue('Settings' in output.data)
|
|
Pierre-Yves Chibon |
1e4803 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
1e4803 |
'Hook Mail inactived' in output.data)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Mail')
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('test project #1 ' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue('Mail' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'<label for="mail_to">Mail to</label>'
|
|
Pierre-Yves Chibon |
65ffcd |
in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
self.assertTrue(
|
|
Pierre-Yves Chibon |
65ffcd |
'
|
|
Pierre-Yves Chibon |
65ffcd |
'value="y">' in output.data)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
aad1a6 |
self.assertFalse(os.path.exists(os.path.join(
|
|
Pierre-Yves Chibon |
aad1a6 |
tests.HERE, 'test.git', 'hooks', 'post-receive.mail')))
|
|
Pierre-Yves Chibon |
aad1a6 |
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
d496cf |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
fe5017 |
PagureFlaskPluginMailtests)
|
|
Pierre-Yves Chibon |
65ffcd |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|