Blame tests/test_pagure_flask_ui_plugins_noff.py

Pierre-Yves Chibon b6ab03
# -*- coding: utf-8 -*-
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
"""
Pierre-Yves Chibon b6ab03
 (c) 2016 - Copyright Red Hat Inc
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
 Authors:
Pierre-Yves Chibon b6ab03
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
"""
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon b6ab03
import pkg_resources
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
import json
Pierre-Yves Chibon b6ab03
import unittest
Pierre-Yves Chibon b6ab03
import shutil
Pierre-Yves Chibon b6ab03
import sys
Pierre-Yves Chibon b6ab03
import os
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
import pygit2
Pierre-Yves Chibon b6ab03
from mock import patch
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon b6ab03
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
import pagure.lib
Pierre-Yves Chibon b6ab03
import tests
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
Clement Verna 109c4b
class PagureFlaskPluginNoFFtests(tests.SimplePagureTest):
Pierre-Yves Chibon b6ab03
    """ Tests for Block non fast-forward pushes plugin of pagure """
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
    def test_plugin_noff(self):
Pierre-Yves Chibon b6ab03
        """ Test the noff plugin on/off endpoint. """
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon b6ab03
            output = self.app.get(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes')
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
\n'
Pierre-Yves Chibon b6ab03
                'test project #1        ', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Block non fast-forward pushes settings

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="">', output.data)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Pierre-Yves Chibon b6ab03
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon b6ab03
                in output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            csrf_token = output.data.split(
Pierre-Yves Chibon b6ab03
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            data = {}
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.post(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes', data=data)
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
\n'
Pierre-Yves Chibon b6ab03
                'test project #1        ', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Block non fast-forward pushes settings

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="">', output.data)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Pierre-Yves Chibon b6ab03
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon b6ab03
                in output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            # With the git repo
Pierre-Yves Chibon b6ab03
            output = self.app.post(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes',
Pierre-Yves Chibon b6ab03
                data=data, follow_redirects=True)
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '<section class="settings">\n  

Settings for test

',</section>
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Pierre-Yves Chibon b6ab03
                '\n                      Hook Block non '
Michael Watters f855b8
                'fast-forward pushes deactivated' in output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.get(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes')
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
\n'
Pierre-Yves Chibon b6ab03
                'test project #1        ', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Block non fast-forward pushes settings

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="">', output.data)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Pierre-Yves Chibon b6ab03
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon b6ab03
                in output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks', 'post-receive.mail')))
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            # Missing the required mail_to
Pierre-Yves Chibon b6ab03
            data = {'csrf_token': csrf_token, 'active': 'y'}
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.post(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes',
Pierre-Yves Chibon b6ab03
                data=data, follow_redirects=True)
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
\n'
Pierre-Yves Chibon b6ab03
                'test project #1        ', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Block non fast-forward pushes settings

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertNotIn(
Pierre-Yves Chibon b6ab03
                '\n                      Hook activated',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="">', output.data)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="y">' in output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Pierre-Yves Chibon b6ab03
                'pre-receive.pagureforcecommit')))
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            # Activate hook
Pierre-Yves Chibon b6ab03
            data = {
Pierre-Yves Chibon b6ab03
                'csrf_token': csrf_token,
Pierre-Yves Chibon b6ab03
                'active': 'y',
Pierre-Yves Chibon b6ab03
                'branches': 'master',
Pierre-Yves Chibon b6ab03
            }
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.post(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes',
Pierre-Yves Chibon b6ab03
                data=data, follow_redirects=True)
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Settings for test

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '\n                      Hook Block non '
Pierre-Yves Chibon b6ab03
                'fast-forward pushes activated', output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.get(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes')
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
\n'
Pierre-Yves Chibon b6ab03
                'test project #1        ', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Block non fast-forward pushes settings

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="master">', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="y">', output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            self.assertTrue(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Pierre-Yves Chibon b6ab03
                'pre-receive.pagureforcecommit')))
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            # De-Activate hook
Pierre-Yves Chibon b6ab03
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon b6ab03
            output = self.app.post(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes',
Pierre-Yves Chibon b6ab03
                data=data, follow_redirects=True)
Pierre-Yves Chibon b6ab03
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '<section class="settings">\n  

Settings for test

',</section>
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '\n                      Hook Block non '
Michael Watters f855b8
                'fast-forward pushes deactivated', output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.get(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes')
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
\n'
Pierre-Yves Chibon b6ab03
                'test project #1        ', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '

Block non fast-forward pushes settings

',
Pierre-Yves Chibon b6ab03
                output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="">', output.data)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon b6ab03
                '
Pierre-Yves Chibon b6ab03
                'value="y">', output.data)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Pierre-Yves Chibon b6ab03
                'pre-receive.pagureforcecommit')))
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)