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 9071b6
 (c) 2016-2018 - 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
Aurélien Bompard dcf6f6
from __future__ import unicode_literals
Aurélien Bompard dcf6f6
Pierre-Yves Chibon b6ab03
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
import unittest
Pierre-Yves Chibon b6ab03
import sys
Pierre-Yves Chibon b6ab03
import os
Pierre-Yves Chibon b6ab03
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Block non fast-forward pushes - test - '</title>
Pierre-Yves Chibon 9071b6
                'Pagure', output_text)
Pierre-Yves Chibon c3d71e
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon c3d71e
                    'required type="text" value="">', output_text)
Pierre-Yves Chibon c3d71e
            else:
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="">', output_text)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">' in output_text)
Pierre-Yves Chibon b6ab03
Aurélien Bompard 626417
            csrf_token = output_text.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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Block non fast-forward pushes - test - '</title>
Pierre-Yves Chibon 9071b6
                'Pagure', output_text)
Pierre-Yves Chibon c3d71e
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon c3d71e
                    'required type="text" value="">', output_text)
Pierre-Yves Chibon c3d71e
            else:
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="">', output_text)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">' in output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Ryan Lerch 90916a
                'Hook Block non '
Aurélien Bompard 626417
                'fast-forward pushes deactivated' in output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Block non fast-forward pushes - test - '</title>
Pierre-Yves Chibon 9071b6
                'Pagure', output_text)
Pierre-Yves Chibon c3d71e
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon c3d71e
                    'required type="text" value="">', output_text)
Pierre-Yves Chibon c3d71e
            else:
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="">', output_text)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">' in output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Block non fast-forward pushes - test - '</title>
Pierre-Yves Chibon 9071b6
                'Pagure', output_text)
Pierre-Yves Chibon b6ab03
            self.assertNotIn(
Ryan Lerch 90916a
                'Hook activated',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 3e9b1d
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon 3e9b1d
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon 3e9b1d
                    'required type="text" value="">', output_text)
Pierre-Yves Chibon 3e9b1d
            else:
Pierre-Yves Chibon 3e9b1d
                self.assertIn(
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="">', output_text)
Pierre-Yves Chibon b6ab03
            self.assertTrue(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">' in output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Ryan Lerch 90916a
                'Hook Block non '
Aurélien Bompard 626417
                'fast-forward pushes activated', output_text)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.get(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes')
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Block non fast-forward pushes - test - '</title>
Pierre-Yves Chibon 9071b6
                'Pagure', output_text)
Pierre-Yves Chibon c3d71e
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon c3d71e
                    'required type="text" value="master">', output_text)
Pierre-Yves Chibon c3d71e
            else:
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="master">', output_text)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Ryan Lerch 90916a
                'Hook Block non '
Aurélien Bompard 626417
                'fast-forward pushes deactivated', output_text)
Pierre-Yves Chibon b6ab03
Pierre-Yves Chibon b6ab03
            output = self.app.get(
Pierre-Yves Chibon b6ab03
                '/test/settings/Block non fast-forward pushes')
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Block non fast-forward pushes - test - '</title>
Pierre-Yves Chibon 9071b6
                'Pagure', output_text)
Pierre-Yves Chibon c3d71e
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon c3d71e
                    'required type="text" value="">', output_text)
Pierre-Yves Chibon c3d71e
            else:
Pierre-Yves Chibon c3d71e
                self.assertIn(
Ryan Lerch 014c1c
                    '
Pierre-Yves Chibon c3d71e
                    'type="text" value="">', output_text)
Pierre-Yves Chibon b6ab03
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
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)