|
Pierre-Yves Chibon |
9ec6f9 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
"""
|
|
Pierre-Yves Chibon |
9ec6f9 |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
Authors:
|
|
Pierre-Yves Chibon |
9ec6f9 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
"""
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
9ec6f9 |
import pkg_resources
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
import json
|
|
Pierre-Yves Chibon |
9ec6f9 |
import unittest
|
|
Pierre-Yves Chibon |
9ec6f9 |
import shutil
|
|
Pierre-Yves Chibon |
9ec6f9 |
import sys
|
|
Pierre-Yves Chibon |
9ec6f9 |
import os
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
import pygit2
|
|
Pierre-Yves Chibon |
605777 |
import wtforms
|
|
Pierre-Yves Chibon |
9ec6f9 |
from mock import patch
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
9ec6f9 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
import progit.lib
|
|
Pierre-Yves Chibon |
605777 |
import progit.hooks
|
|
Pierre-Yves Chibon |
9ec6f9 |
import tests
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
605777 |
class FakeForm(wtforms.Form):
|
|
Pierre-Yves Chibon |
605777 |
''' Form to configure the mail hook. '''
|
|
Pierre-Yves Chibon |
605777 |
field1 = wtforms.TextField(
|
|
Pierre-Yves Chibon |
605777 |
'Title', [progit.hooks.RequiredIf('active')]
|
|
Pierre-Yves Chibon |
605777 |
)
|
|
Pierre-Yves Chibon |
605777 |
field2 = wtforms.BooleanField(
|
|
Pierre-Yves Chibon |
605777 |
'Title2', [wtforms.validators.Optional()]
|
|
Pierre-Yves Chibon |
605777 |
)
|
|
Pierre-Yves Chibon |
605777 |
|
|
Pierre-Yves Chibon |
605777 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
class ProgitFlaskPluginstests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
9ec6f9 |
""" Tests for flask plugins controller of progit """
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
def setUp(self):
|
|
Pierre-Yves Chibon |
9ec6f9 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
9ec6f9 |
super(ProgitFlaskPluginstests, self).setUp()
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.SESSION = self.session
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.ui.SESSION = self.session
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.ui.plugins.SESSION = self.session
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.APP.config['GIT_FOLDER'] = tests.HERE
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.APP.config['FORK_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
9ec6f9 |
tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
9ec6f9 |
tests.HERE, 'tickets')
|
|
Pierre-Yves Chibon |
9ec6f9 |
progit.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
9ec6f9 |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
9ec6f9 |
self.app = progit.APP.test_client()
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
def test_index(self):
|
|
Pierre-Yves Chibon |
9ec6f9 |
""" Test the index endpoint. """
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
output = self.app.get('/foo/settings/Mail')
|
|
Pierre-Yves Chibon |
9ec6f9 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
9ec6f9 |
with tests.user_set(progit.APP, user):
|
|
Pierre-Yves Chibon |
9ec6f9 |
output = self.app.get('/foo/settings/Mail')
|
|
Pierre-Yves Chibon |
9ec6f9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
output = self.app.get('/test/settings/Mail')
|
|
Pierre-Yves Chibon |
9ec6f9 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
605777 |
def test_RequiredIf(self):
|
|
Pierre-Yves Chibon |
605777 |
""" Test the behavior of the RequiredIf validator. """
|
|
Pierre-Yves Chibon |
605777 |
form = FakeForm()
|
|
Pierre-Yves Chibon |
605777 |
|
|
Pierre-Yves Chibon |
605777 |
try:
|
|
Pierre-Yves Chibon |
605777 |
form.validate()
|
|
Pierre-Yves Chibon |
605777 |
except Exception, err:
|
|
Pierre-Yves Chibon |
605777 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
605777 |
str(err), 'no field named "active" in form')
|
|
Pierre-Yves Chibon |
605777 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
|
|
Pierre-Yves Chibon |
9ec6f9 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
9ec6f9 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitFlaskPluginstests)
|
|
Pierre-Yves Chibon |
9ec6f9 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|