Blame tests/test_progit_flask_ui_plugins_irc.py

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

test project #1

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

IRC

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

test project #1

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

IRC

' in output.data)
Pierre-Yves Chibon 382fd3
            self.assertTrue(
Pierre-Yves Chibon 382fd3
                '<input id="active" name="active" type="checkbox" value="y">'
Pierre-Yves Chibon 382fd3
                in output.data)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 899d15
            self.assertFalse(os.path.exists(os.path.join(
Pierre-Yves Chibon 899d15
                tests.HERE, 'test.git', 'hooks', 'post-receive.irc')))
Pierre-Yves Chibon 899d15
Pierre-Yves Chibon 382fd3
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 382fd3
            # No git found
Pierre-Yves Chibon 382fd3
            output = self.app.post('/test/settings/IRC', data=data)
Pierre-Yves Chibon 382fd3
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
            tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
            # With the git repo
Pierre-Yves Chibon 382fd3
            output = self.app.post('/test/settings/IRC', data=data)
Pierre-Yves Chibon 382fd3
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 382fd3
            self.assertTrue('

test project #1

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

IRC

' in output.data)
Pierre-Yves Chibon 382fd3
            self.assertTrue(
Pierre-Yves Chibon 382fd3
                '
  • Hook inactived
  • ' in output.data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue(
    Pierre-Yves Chibon 382fd3
                    '<input id="active" name="active" type="checkbox" value="y">'
    Pierre-Yves Chibon 382fd3
                    in output.data)
    Pierre-Yves Chibon 382fd3
    Pierre-Yves Chibon 899d15
                self.assertFalse(os.path.exists(os.path.join(
    Pierre-Yves Chibon 899d15
                    tests.HERE, 'test.git', 'hooks', 'post-receive.irc')))
    Pierre-Yves Chibon 899d15
    Pierre-Yves Chibon 382fd3
                # Activate hook
    Pierre-Yves Chibon 382fd3
                data = {
    Pierre-Yves Chibon 382fd3
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 382fd3
                    'active': 'y',
    Pierre-Yves Chibon 382fd3
                    'server': 'irc.freenode.net',
    Pierre-Yves Chibon 382fd3
                    'port': 6667,
    Pierre-Yves Chibon 382fd3
                    'room': '#fedora-apps',
    Pierre-Yves Chibon 382fd3
                }
    Pierre-Yves Chibon 382fd3
    Pierre-Yves Chibon 382fd3
                output = self.app.post('/test/settings/IRC', data=data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue('

    test project #1

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

    IRC

    ' in output.data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue(
    Pierre-Yves Chibon 382fd3
                    '
  • Hook activated
  • ' in output.data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue(
    Pierre-Yves Chibon 382fd3
                    '
    Pierre-Yves Chibon 382fd3
                    'value="y">' in output.data)
    Pierre-Yves Chibon 382fd3
    Pierre-Yves Chibon 899d15
                # TODO: Fix this
    Pierre-Yves Chibon 899d15
                #self.assertTrue(os.path.exists(os.path.join(
    Pierre-Yves Chibon 899d15
                    #tests.HERE, 'test.git', 'hooks', 'post-receive.irc')))
    Pierre-Yves Chibon 899d15
    Pierre-Yves Chibon 382fd3
                # De-Activate hook
    Pierre-Yves Chibon 382fd3
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon 382fd3
                output = self.app.post('/test/settings/IRC', data=data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue('

    test project #1

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

    IRC

    ' in output.data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue(
    Pierre-Yves Chibon 382fd3
                    '
  • Hook inactived
  • ' in output.data)
    Pierre-Yves Chibon 382fd3
                self.assertTrue(
    Pierre-Yves Chibon 382fd3
                    '
    Pierre-Yves Chibon 382fd3
                    'value="y">' in output.data)
    Pierre-Yves Chibon 382fd3
    Pierre-Yves Chibon 899d15
                self.assertFalse(os.path.exists(os.path.join(
    Pierre-Yves Chibon 899d15
                    tests.HERE, 'test.git', 'hooks', 'post-receive.irc')))
    Pierre-Yves Chibon 899d15
    Pierre-Yves Chibon 382fd3
    Pierre-Yves Chibon 382fd3
    if __name__ == '__main__':
    Pierre-Yves Chibon 382fd3
        SUITE = unittest.TestLoader().loadTestsFromTestCase(
    Pierre-Yves Chibon 382fd3
            ProgitFlaskPluginIRCtests)
    Pierre-Yves Chibon 382fd3
        unittest.TextTestRunner(verbosity=2).run(SUITE)