Blame tests/test_pagure_flask_ui_plugins_default_hook.py

Pierre-Yves Chibon 317b75
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
"""
Pierre-Yves Chibon 317b75
 (c) 2016 - Copyright Red Hat Inc
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
 Authors:
Pierre-Yves Chibon 317b75
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
"""
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 317b75
import pkg_resources
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
import json
Pierre-Yves Chibon 317b75
import unittest
Pierre-Yves Chibon 317b75
import shutil
Pierre-Yves Chibon 317b75
import sys
Pierre-Yves Chibon 317b75
import os
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
import pygit2
Pierre-Yves Chibon 317b75
from mock import patch
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 317b75
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
import pagure.lib
Pierre-Yves Chibon 317b75
import tests
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
class PagureFlaskPluginDefaultHooktests(tests.Modeltests):
Pierre-Yves Chibon 317b75
    """ Tests for default_hook plugin of pagure """
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
    def setUp(self):
Pierre-Yves Chibon 317b75
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 317b75
        super(PagureFlaskPluginDefaultHooktests, self).setUp()
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon 317b75
        pagure.SESSION = self.session
Pierre-Yves Chibon 317b75
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon 317b75
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon 317b75
        pagure.ui.plugins.SESSION = self.session
Pierre-Yves Chibon 317b75
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 317b75
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
    def test_plugin_default_ui(self):
Pierre-Yves Chibon 317b75
        """ Test the default hook plugin on/off endpoint. """
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon 317b75
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 317b75
            output = self.app.get('/test/settings/default')
Pierre-Yves Chibon 317b75
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
    def test_plugin_default_install(self):
Pierre-Yves Chibon 317b75
        """ Check that the default plugin is correctly installed when a
Pierre-Yves Chibon 317b75
        project is created.
Pierre-Yves Chibon 317b75
        """
Pierre-Yves Chibon 317b75
Patrick Uiterwijk 170974
        taskid = pagure.lib.new_project(
Pierre-Yves Chibon 317b75
            self.session,
Pierre-Yves Chibon 317b75
            user='pingou',
Pierre-Yves Chibon 317b75
            name='test',
Pierre-Yves Chibon 317b75
            blacklist=[],
Pierre-Yves Chibon 317b75
            allowed_prefix=[],
Patrick Uiterwijk 170974
            gitfolder=os.path.join(self.path, 'repos'),
Pierre-Yves Chibon 317b75
            docfolder=os.path.join(self.path, 'docs'),
Pierre-Yves Chibon 317b75
            ticketfolder=os.path.join(self.path, 'tickets'),
Pierre-Yves Chibon 317b75
            requestfolder=os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 317b75
            description=None,
Pierre-Yves Chibon 317b75
            url=None, avatar_email=None,
Pierre-Yves Chibon 317b75
            parent_id=None,
Pierre-Yves Chibon 317b75
            add_readme=False,
Pierre-Yves Chibon 317b75
            userobj=None,
Pierre-Yves Chibon 317b75
            prevent_40_chars=False,
Pierre-Yves Chibon 317b75
            namespace=None
Pierre-Yves Chibon 317b75
        )
Patrick Uiterwijk 170974
        result = pagure.lib.tasks.get_result(taskid).get()
Patrick Uiterwijk 170974
        self.assertEqual(result,
Patrick Uiterwijk 170974
                         {'endpoint': 'view_repo',
Patrick Uiterwijk 170974
                          'repo': 'test',
Patrick Uiterwijk 170974
                          'namespace': None})
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
        self.assertTrue(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
            self.path, 'repos', 'test.git', 'hooks', 'post-receive.default')))
Pierre-Yves Chibon 317b75
        self.assertTrue(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
            self.path, 'repos', 'test.git', 'hooks', 'post-receive')))
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
Pierre-Yves Chibon 317b75
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)