Blame tests/test_pagure_flask_ui_plugins_pagure_hook.py

Pierre-Yves Chibon 180887
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
"""
Pierre-Yves Chibon 9fae46
 (c) 2015-2016 - Copyright Red Hat Inc
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
 Authors:
Pierre-Yves Chibon 180887
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
"""
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 180887
import pkg_resources
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
import json
Pierre-Yves Chibon 180887
import unittest
Pierre-Yves Chibon 180887
import shutil
Pierre-Yves Chibon 180887
import sys
Pierre-Yves Chibon 180887
import os
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
import pygit2
Pierre-Yves Chibon 180887
from mock import patch
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 180887
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 180887
Pierre-Yves Chibon fe5017
import pagure.lib
Pierre-Yves Chibon 180887
import tests
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
Clement Verna 109c4b
class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest):
Pierre-Yves Chibon fe5017
    """ Tests for pagure_hook plugin of pagure """
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
    def setUp(self):
Pierre-Yves Chibon 180887
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon fe5017
        super(PagureFlaskPluginPagureHooktests, self).setUp()
Pierre-Yves Chibon 180887
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 9fae46
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
    def test_plugin_mail(self):
Pierre-Yves Chibon 59394d
        """ Test the pagure hook plugin on/off endpoint. """
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Lubomír Sedlář 4443c5
            output = self.app.get('/test/settings/Pagure')
Pierre-Yves Chibon 180887
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Lubomír Sedlář 4443c5
            self.assertTrue('

Pagure settings

' in output.data)
Pierre-Yves Chibon 180887
            self.assertTrue(
Pierre-Yves Chibon 180887
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon 180887
                in output.data)
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
            csrf_token = output.data.split(
Pierre-Yves Chibon 180887
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
            data = {}
Pierre-Yves Chibon 180887
Lubomír Sedlář 4443c5
            output = self.app.post('/test/settings/Pagure', data=data)
Pierre-Yves Chibon 180887
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Lubomír Sedlář 4443c5
            self.assertTrue('

Pagure settings

' in output.data)
Pierre-Yves Chibon 180887
            self.assertTrue(
Pierre-Yves Chibon 180887
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon 180887
                in output.data)
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 180887
Jeremy Cline 20109f
            tests.create_projects_git(os.path.join(self.path, 'docs'))
Jeremy Cline 20109f
            tests.create_projects_git(os.path.join(self.path, 'requests'))
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 180887
            # With the git repo
Pierre-Yves Chibon 1e4803
            output = self.app.post(
Lubomír Sedlář 4443c5
                '/test/settings/Pagure', data=data, follow_redirects=True)
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4beb7c
            self.assertIn(
Pierre-Yves Chibon 4beb7c
                '<section class="settings">\n  

Settings for test

',</section>
Pierre-Yves Chibon 4beb7c
                output.data)
Pierre-Yves Chibon 1e4803
            self.assertTrue(
Michael Watters f855b8
                '\n                      Hook Pagure deactivated'
Pierre-Yves Chibon 1e4803
                in output.data)
Pierre-Yves Chibon 1e4803
Lubomír Sedlář 4443c5
            output = self.app.get('/test/settings/Pagure')
Pierre-Yves Chibon 180887
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Lubomír Sedlář 4443c5
            self.assertTrue('

Pagure settings

' in output.data)
Pierre-Yves Chibon 180887
            self.assertTrue(
Pierre-Yves Chibon 180887
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon 180887
                in output.data)
Pierre-Yves Chibon 180887
Pierre-Yves Chibon d7106c
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Patrick Uiterwijk 170974
                'post-receive.pagure')))
Pierre-Yves Chibon d7106c
Pierre-Yves Chibon 180887
            # Activate hook
Pierre-Yves Chibon 180887
            data = {
Pierre-Yves Chibon 180887
                'csrf_token': csrf_token,
Pierre-Yves Chibon 180887
                'active': 'y',
Pierre-Yves Chibon 180887
            }
Pierre-Yves Chibon 180887
Pierre-Yves Chibon 1e4803
            output = self.app.post(
Lubomír Sedlář 4443c5
                '/test/settings/Pagure', data=data, follow_redirects=True)
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4beb7c
            self.assertIn(
Pierre-Yves Chibon 4beb7c
                '<section class="settings">\n  

Settings for test

',</section>
Pierre-Yves Chibon 4beb7c
                output.data)
Pierre-Yves Chibon 1e4803
            self.assertTrue(
Lubomír Sedlář 4443c5
                '\n                      Hook Pagure activated'
Pierre-Yves Chibon 1e4803
                in output.data)
Pierre-Yves Chibon 1e4803
Lubomír Sedlář 4443c5
            output = self.app.get('/test/settings/Pagure')
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Lubomír Sedlář 4443c5
            self.assertTrue('

Pagure settings

' in output.data)
Pierre-Yves Chibon 180887
            self.assertTrue(
Pierre-Yves Chibon 180887
                '
Pierre-Yves Chibon 180887
                'value="y">' in output.data)
Pierre-Yves Chibon 180887
Pierre-Yves Chibon d7106c
            self.assertTrue(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Patrick Uiterwijk 170974
                'post-receive.pagure')))
Pierre-Yves Chibon d7106c
Pierre-Yves Chibon 180887
            # De-Activate hook
Pierre-Yves Chibon 180887
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 1e4803
            output = self.app.post(
Lubomír Sedlář 4443c5
                '/test/settings/Pagure', data=data, follow_redirects=True)
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4beb7c
            self.assertIn(
Pierre-Yves Chibon 4beb7c
                '<section class="settings">\n  

Settings for test

',</section>
Pierre-Yves Chibon 4beb7c
                output.data)
Pierre-Yves Chibon 1e4803
            self.assertTrue(
Michael Watters f855b8
                '\n                      Hook Pagure deactivated'
Pierre-Yves Chibon 1e4803
                in output.data)
Pierre-Yves Chibon 1e4803
Lubomír Sedlář 4443c5
            output = self.app.get('/test/settings/Pagure')
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Lubomír Sedlář 4443c5
            self.assertTrue('

Pagure settings

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