|
Pierre-Yves Chibon |
65ffcd |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
"""
|
|
Pierre-Yves Chibon |
9071b6 |
(c) 2015-2018 - 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 |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
65ffcd |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
import unittest
|
|
Pierre-Yves Chibon |
65ffcd |
import sys
|
|
Pierre-Yves Chibon |
65ffcd |
import os
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
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 |
|
|
Clement Verna |
109c4b |
class PagureFlaskPluginMailtests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for flask plugins controller of pagure """
|
|
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)
|
|
Patrick Uiterwijk |
170974 |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
65ffcd |
output = self.app.get('/test/settings/Mail')
|
|
Pierre-Yves Chibon |
65ffcd |
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 Mail - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<label for="mail_to">Mail to</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 |
65ffcd |
|
|
Aurélien Bompard |
626417 |
csrf_token = output_text.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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Mail - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<label for="mail_to">Mail to</label>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
data['csrf_token'] = csrf_token
|
|
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)
|
|
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 Mail deactivated', output_text)
|
|
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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Mail - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<label for="mail_to">Mail to</label>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
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)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Mail - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertNotIn(
|
|
Ryan Lerch |
90916a |
'Hook activated', output_text)
|
|
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 |
7a5ac6 |
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 '
|
|
Pierre-Yves Chibon |
7a5ac6 |
'This field is required. ',
|
|
Pierre-Yves Chibon |
7a5ac6 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
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)
|
|
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 Mail activated', output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Mail')
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Mail - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<label for="mail_to">Mail to</label>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
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)
|
|
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 Mail deactivated', output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.get('/test/settings/Mail')
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
98f2af |
self.assertIn(
|
|
Pierre-Yves Chibon |
9071b6 |
'<title>Settings Mail - test - Pagure</title>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<label for="mail_to">Mail to</label>', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
014c1c |
'
|
|
Aurélien Bompard |
626417 |
'type="checkbox" value="y">', output_text)
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
|
|
Pierre-Yves Chibon |
65ffcd |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|