Blame tests/test_progit_flask_ui_plugins_progit_ticket_hook.py

Pierre-Yves Chibon e8d17b
# -*- coding: utf-8 -*-
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
"""
Pierre-Yves Chibon e8d17b
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
 Authors:
Pierre-Yves Chibon e8d17b
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
"""
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon e8d17b
import pkg_resources
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
import json
Pierre-Yves Chibon e8d17b
import unittest
Pierre-Yves Chibon e8d17b
import shutil
Pierre-Yves Chibon e8d17b
import sys
Pierre-Yves Chibon e8d17b
import os
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
import pygit2
Pierre-Yves Chibon e8d17b
from mock import patch
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon e8d17b
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon fe5017
import pagure.lib
Pierre-Yves Chibon e8d17b
import tests
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon fe5017
class PagureFlaskPluginPagureTicketHooktests(tests.Modeltests):
Pierre-Yves Chibon fe5017
    """ Tests for pagure_hook plugin of pagure """
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
    def setUp(self):
Pierre-Yves Chibon e8d17b
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon fe5017
        super(PagureFlaskPluginPagureTicketHooktests, self).setUp()
Pierre-Yves Chibon e8d17b
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 e8d17b
Pierre-Yves Chibon fe5017
        pagure.APP.config['GIT_FOLDER'] = tests.HERE
Pierre-Yves Chibon fe5017
        pagure.APP.config['FORK_FOLDER'] = os.path.join(
Pierre-Yves Chibon e8d17b
            tests.HERE, 'forks')
Pierre-Yves Chibon fe5017
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Pierre-Yves Chibon e8d17b
            tests.HERE, 'tickets')
Pierre-Yves Chibon fe5017
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Pierre-Yves Chibon e8d17b
            tests.HERE, 'docs')
Pierre-Yves Chibon fe5017
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon fe5017
    def test_plugin_pagure_ticket(self):
Pierre-Yves Chibon fe5017
        """ Test the pagure_ticket plugin on/off endpoint. """
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
        tests.create_projects(self.session)
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon fe5017
            output = self.app.get('/test/settings/pagure tickets')
Pierre-Yves Chibon e8d17b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon e8d17b
            self.assertTrue('

test project #1

' in output.data)
Pierre-Yves Chibon fe5017
            self.assertTrue('

pagure tickets

' in output.data)
Pierre-Yves Chibon e8d17b
            self.assertTrue(
Pierre-Yves Chibon e8d17b
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon e8d17b
                in output.data)
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
            csrf_token = output.data.split(
Pierre-Yves Chibon e8d17b
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
            data = {}
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon fe5017
            output = self.app.post('/test/settings/pagure tickets', data=data)
Pierre-Yves Chibon e8d17b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon e8d17b
            self.assertTrue('

test project #1

' in output.data)
Pierre-Yves Chibon fe5017
            self.assertTrue('

pagure tickets

' in output.data)
Pierre-Yves Chibon e8d17b
            self.assertTrue(
Pierre-Yves Chibon e8d17b
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon e8d17b
                in output.data)
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon e8d17b
            # No git found
Pierre-Yves Chibon fe5017
            output = self.app.post('/test/settings/pagure tickets', data=data)
Pierre-Yves Chibon e8d17b
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon 02a5c3
            # Create both the tickets repo
Pierre-Yves Chibon e8d17b
            tests.create_projects_git(os.path.join(tests.HERE, 'tickets'))
Pierre-Yves Chibon e8d17b
Pierre-Yves Chibon e8d17b
            # With the git repo
Pierre-Yves Chibon fe5017
            output = self.app.post('/test/settings/pagure tickets', data=data)
Pierre-Yves Chibon e8d17b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon e8d17b
            self.assertTrue('

test project #1

' in output.data)
Pierre-Yves Chibon fe5017
            self.assertTrue('

pagure tickets

' in output.data)
Pierre-Yves Chibon e8d17b
            self.assertTrue(
Pierre-Yves Chibon e8d17b
                '
  • Hook inactived
  • ' in output.data)
    Pierre-Yves Chibon e8d17b
                self.assertTrue(
    Pierre-Yves Chibon e8d17b
                    '<input id="active" name="active" type="checkbox" value="y">'
    Pierre-Yves Chibon e8d17b
                    in output.data)
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
                self.assertFalse(os.path.exists(os.path.join(
    Pierre-Yves Chibon e8d17b
                    tests.HERE, 'tickets', 'test.git', 'hooks',
    Pierre-Yves Chibon fe5017
                    'post-receive.pagure')))
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
                # Activate hook
    Pierre-Yves Chibon e8d17b
                data = {
    Pierre-Yves Chibon e8d17b
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon e8d17b
                    'active': 'y',
    Pierre-Yves Chibon e8d17b
                }
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon fe5017
                output = self.app.post('/test/settings/pagure tickets', data=data)
    Pierre-Yves Chibon e8d17b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon e8d17b
                self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon fe5017
                self.assertTrue('

    pagure tickets

    ' in output.data)
    Pierre-Yves Chibon e8d17b
                self.assertTrue(
    Pierre-Yves Chibon e8d17b
                    '
  • Hook activated
  • ' in output.data)
    Pierre-Yves Chibon e8d17b
                self.assertTrue(
    Pierre-Yves Chibon e8d17b
                    '
    Pierre-Yves Chibon e8d17b
                    'value="y">' in output.data)
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
                self.assertTrue(os.path.exists(os.path.join(
    Pierre-Yves Chibon e8d17b
                    tests.HERE, 'tickets', 'test.git', 'hooks',
    Pierre-Yves Chibon 02a5c3
                    'post-receive.pagure-ticket')))
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
                # De-Activate hook
    Pierre-Yves Chibon e8d17b
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon fe5017
                output = self.app.post('/test/settings/pagure tickets', data=data)
    Pierre-Yves Chibon e8d17b
                self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon fe5017
                self.assertTrue('

    pagure tickets

    ' in output.data)
    Pierre-Yves Chibon e8d17b
                self.assertTrue(
    Pierre-Yves Chibon e8d17b
                    '
  • Hook inactived
  • ' in output.data)
    Pierre-Yves Chibon e8d17b
                self.assertTrue(
    Pierre-Yves Chibon e8d17b
                    '
    Pierre-Yves Chibon e8d17b
                    'value="y">' in output.data)
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
                self.assertFalse(os.path.exists(os.path.join(
    Pierre-Yves Chibon e8d17b
                    tests.HERE, 'tickets', 'test.git', 'hooks',
    Pierre-Yves Chibon 02a5c3
                    'post-receive.pagure-ticket')))
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
    Pierre-Yves Chibon e8d17b
    if __name__ == '__main__':
    Pierre-Yves Chibon e8d17b
        SUITE = unittest.TestLoader().loadTestsFromTestCase(
    Pierre-Yves Chibon fe5017
            PagureFlaskPluginPagureTicketHooktests)
    Pierre-Yves Chibon e8d17b
        unittest.TextTestRunner(verbosity=2).run(SUITE)