Blame tests/test_progit_flask_ui_fork.py

Pierre-Yves Chibon 9347b5
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
"""
Pierre-Yves Chibon 9347b5
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
 Authors:
Pierre-Yves Chibon 9347b5
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
"""
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 9347b5
import pkg_resources
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
import json
Pierre-Yves Chibon 9347b5
import unittest
Pierre-Yves Chibon 9347b5
import shutil
Pierre-Yves Chibon 9347b5
import sys
Pierre-Yves Chibon 9347b5
import tempfile
Pierre-Yves Chibon 9347b5
import os
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
import pygit2
Pierre-Yves Chibon 9347b5
from mock import patch
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 9347b5
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
import pagure.lib
Pierre-Yves Chibon 9347b5
import tests
Pierre-Yves Chibon 27a73d
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
class PagureFlaskForktests(tests.Modeltests):
Pierre-Yves Chibon 9347b5
    """ Tests for flask fork controller of pagure """
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
    def setUp(self):
Pierre-Yves Chibon 9347b5
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 9347b5
        super(PagureFlaskForktests, self).setUp()
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon 9347b5
        pagure.SESSION = self.session
Pierre-Yves Chibon 005063
        pagure.lib.SESSION = self.session
Pierre-Yves Chibon 9347b5
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon 9347b5
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon f4b1a9
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon 9347b5
        pagure.ui.fork.SESSION = self.session
Pierre-Yves Chibon 9347b5
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 8dec5e
        pagure.ui.issues.SESSION = self.session
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon ae1f3a
        pagure.APP.config['GIT_FOLDER'] = os.path.join(tests.HERE, 'repos')
Pierre-Yves Chibon ae1f3a
        pagure.APP.config['FORK_FOLDER'] = os.path.join(tests.HERE, 'forks')
Pierre-Yves Chibon 9347b5
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 9347b5
            tests.HERE, 'tickets')
Pierre-Yves Chibon 9347b5
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 9347b5
            tests.HERE, 'docs')
Pierre-Yves Chibon 9347b5
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 9347b5
            tests.HERE, 'requests')
Pierre-Yves Chibon 9347b5
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 224b96
    def set_up_git_repo(
Pierre-Yves Chibon 224b96
            self, new_project=None, branch_from='feature', mtype='FF'):
Pierre-Yves Chibon 9347b5
        """ Set up the git repo and create the corresponding PullRequest
Pierre-Yves Chibon 9347b5
        object.
Pierre-Yves Chibon 9347b5
        """
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # Create a git repo to play with
Pierre-Yves Chibon ae1f3a
        gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
Pierre-Yves Chibon 9347b5
        repo = pygit2.init_repository(gitrepo, bare=True)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
Pierre-Yves Chibon eaaf26
        repopath = os.path.join(newpath, 'test')
Pierre-Yves Chibon eaaf26
        clone_repo = pygit2.clone_repository(gitrepo, repopath)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # Create a file in that git repo
Pierre-Yves Chibon eaaf26
        with open(os.path.join(repopath, 'sources'), 'w') as stream:
Pierre-Yves Chibon 9347b5
            stream.write('foo\n bar')
Pierre-Yves Chibon 9347b5
        clone_repo.index.add('sources')
Pierre-Yves Chibon 9347b5
        clone_repo.index.write()
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # Commits the files added
Pierre-Yves Chibon 9347b5
        tree = clone_repo.index.write_tree()
Pierre-Yves Chibon 9347b5
        author = pygit2.Signature(
Pierre-Yves Chibon 9347b5
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 9347b5
        committer = pygit2.Signature(
Pierre-Yves Chibon 9347b5
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 9347b5
        clone_repo.create_commit(
Pierre-Yves Chibon 9347b5
            'refs/heads/master',  # the name of the reference to update
Pierre-Yves Chibon 9347b5
            author,
Pierre-Yves Chibon 9347b5
            committer,
Pierre-Yves Chibon 9347b5
            'Add sources file for testing',
Pierre-Yves Chibon 9347b5
            # binary string representing the tree object ID
Pierre-Yves Chibon 9347b5
            tree,
Pierre-Yves Chibon 9347b5
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 9347b5
            []
Pierre-Yves Chibon 9347b5
        )
Pierre-Yves Chibon 9347b5
        refname = 'refs/heads/master:refs/heads/master'
Pierre-Yves Chibon 9347b5
        ori_remote = clone_repo.remotes[0]
Pierre-Yves Chibon 27a73d
        PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        first_commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 224b96
        if mtype == 'merge':
Pierre-Yves Chibon eaaf26
            with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
Pierre-Yves Chibon 224b96
                stream.write('*~')
Pierre-Yves Chibon 224b96
            clone_repo.index.add('.gitignore')
Pierre-Yves Chibon 224b96
            clone_repo.index.write()
Pierre-Yves Chibon 224b96
Pierre-Yves Chibon 224b96
            # Commits the files added
Pierre-Yves Chibon 224b96
            tree = clone_repo.index.write_tree()
Pierre-Yves Chibon 224b96
            author = pygit2.Signature(
Pierre-Yves Chibon 224b96
                'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 224b96
            committer = pygit2.Signature(
Pierre-Yves Chibon 224b96
                'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 224b96
            clone_repo.create_commit(
Pierre-Yves Chibon 224b96
                'refs/heads/master',
Pierre-Yves Chibon 224b96
                author,
Pierre-Yves Chibon 224b96
                committer,
Pierre-Yves Chibon 224b96
                'Add .gitignore file for testing',
Pierre-Yves Chibon 224b96
                # binary string representing the tree object ID
Pierre-Yves Chibon 224b96
                tree,
Pierre-Yves Chibon 224b96
                # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 224b96
                [first_commit.oid.hex]
Pierre-Yves Chibon 224b96
            )
Pierre-Yves Chibon 224b96
            refname = 'refs/heads/master:refs/heads/master'
Pierre-Yves Chibon 224b96
            ori_remote = clone_repo.remotes[0]
Pierre-Yves Chibon 27a73d
            PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 224b96
Pierre-Yves Chibon 224b96
        if mtype == 'conflicts':
Pierre-Yves Chibon eaaf26
            with open(os.path.join(repopath, 'sources'), 'w') as stream:
Pierre-Yves Chibon 224b96
                stream.write('foo\n bar\nbaz')
Pierre-Yves Chibon 224b96
            clone_repo.index.add('sources')
Pierre-Yves Chibon 224b96
            clone_repo.index.write()
Pierre-Yves Chibon 224b96
Pierre-Yves Chibon 224b96
            # Commits the files added
Pierre-Yves Chibon 224b96
            tree = clone_repo.index.write_tree()
Pierre-Yves Chibon 224b96
            author = pygit2.Signature(
Pierre-Yves Chibon 224b96
                'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 224b96
            committer = pygit2.Signature(
Pierre-Yves Chibon 224b96
                'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 224b96
            clone_repo.create_commit(
Pierre-Yves Chibon 224b96
                'refs/heads/master',
Pierre-Yves Chibon 224b96
                author,
Pierre-Yves Chibon 224b96
                committer,
Pierre-Yves Chibon 224b96
                'Add sources conflicting',
Pierre-Yves Chibon 224b96
                # binary string representing the tree object ID
Pierre-Yves Chibon 224b96
                tree,
Pierre-Yves Chibon 224b96
                # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 224b96
                [first_commit.oid.hex]
Pierre-Yves Chibon 224b96
            )
Pierre-Yves Chibon 224b96
            refname = 'refs/heads/master:refs/heads/master'
Pierre-Yves Chibon 224b96
            ori_remote = clone_repo.remotes[0]
Pierre-Yves Chibon 27a73d
            PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 224b96
Pierre-Yves Chibon 9347b5
        # Set the second repo
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon eaaf26
        new_gitrepo = repopath
Pierre-Yves Chibon 9347b5
        if new_project:
Pierre-Yves Chibon 9347b5
            # Create a new git repo to play with
Pierre-Yves Chibon eaaf26
            new_gitrepo = os.path.join(newpath, new_project.fullname)
Pierre-Yves Chibon 9347b5
            if not os.path.exists(new_gitrepo):
Pierre-Yves Chibon 9347b5
                os.makedirs(new_gitrepo)
Pierre-Yves Chibon 9347b5
                new_repo = pygit2.clone_repository(gitrepo, new_gitrepo)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        repo = pygit2.Repository(new_gitrepo)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 224b96
        if mtype != 'nochanges':
Pierre-Yves Chibon 224b96
            # Edit the sources file again
Pierre-Yves Chibon 224b96
            with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
Pierre-Yves Chibon 224b96
                stream.write('foo\n bar\nbaz\n boose')
Pierre-Yves Chibon 224b96
            repo.index.add('sources')
Pierre-Yves Chibon 224b96
            repo.index.write()
Pierre-Yves Chibon 224b96
Pierre-Yves Chibon 224b96
            # Commits the files added
Pierre-Yves Chibon 224b96
            tree = repo.index.write_tree()
Pierre-Yves Chibon 224b96
            author = pygit2.Signature(
Pierre-Yves Chibon 224b96
                'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 224b96
            committer = pygit2.Signature(
Pierre-Yves Chibon 224b96
                'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 224b96
            repo.create_commit(
Pierre-Yves Chibon 224b96
                'refs/heads/%s' % branch_from,
Pierre-Yves Chibon 224b96
                author,
Pierre-Yves Chibon 224b96
                committer,
Pierre-Yves Chibon 224b96
                'A commit on branch %s' % branch_from,
Pierre-Yves Chibon 224b96
                tree,
Pierre-Yves Chibon 224b96
                [first_commit.oid.hex]
Pierre-Yves Chibon 224b96
            )
Pierre-Yves Chibon eaaf26
            refname = 'refs/heads/%s' % (branch_from)
Pierre-Yves Chibon eaaf26
            ori_remote = repo.remotes[0]
Pierre-Yves Chibon 27a73d
            PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # Create a PR for these changes
Pierre-Yves Chibon 9347b5
        project = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 9347b5
            session=self.session,
Pierre-Yves Chibon 9347b5
            repo_from=project,
Pierre-Yves Chibon 9347b5
            branch_from=branch_from,
Pierre-Yves Chibon 9347b5
            repo_to=project,
Pierre-Yves Chibon 9347b5
            branch_to='master',
Pierre-Yves Chibon 9347b5
            title='PR from the %s branch' % branch_from,
Pierre-Yves Chibon 9347b5
            user='pingou',
Pierre-Yves Chibon 9347b5
            requestfolder=None,
Pierre-Yves Chibon 9347b5
        )
Pierre-Yves Chibon 9347b5
        self.session.commit()
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'PR from the %s branch' % branch_from)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 5d6e3d
        shutil.rmtree(newpath)
Pierre-Yves Chibon 5d6e3d
Pierre-Yves Chibon 9347b5
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 9347b5
    def test_request_pull(self, send_email):
Pierre-Yves Chibon 9347b5
        """ Test the request_pull endpoint. """
Pierre-Yves Chibon 9347b5
        send_email.return_value = True
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        tests.create_projects(self.session)
Pierre-Yves Chibon 9347b5
        tests.create_projects_git(
Pierre-Yves Chibon 9347b5
            os.path.join(tests.HERE, 'requests'), bare=True)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # Non-existant project
Pierre-Yves Chibon 9347b5
        output = self.app.get('/foobar/pull-request/1')
Pierre-Yves Chibon 9347b5
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # Project has no PR
Pierre-Yves Chibon 9347b5
        output = self.app.get('/test/pull-request/1')
Pierre-Yves Chibon 9347b5
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        self.set_up_git_repo(new_project=None, branch_from='feature')
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        project = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 9347b5
        self.assertEqual(len(project.requests), 1)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 9347b5
        # View the pull-request
Pierre-Yves Chibon 9347b5
        output = self.app.get('/test/pull-request/1')
Pierre-Yves Chibon 9347b5
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 9347b5
        self.assertIn(
Pierre-Yves Chibon 9347b5
            '<title>Pull request #1 - test - Pagure</title>', output.data)
Pierre-Yves Chibon 9347b5
        self.assertIn(
Pierre-Yves Chibon 9347b5
            'title="View file as of 2a552b">View', output.data)
Pierre-Yves Chibon 9347b5
Pierre-Yves Chibon 502b7a
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 502b7a
    def test_merge_request_pull_FF(self, send_email):
Pierre-Yves Chibon 8911da
        """ Test the merge_request_pull endpoint with a FF PR. """
Pierre-Yves Chibon 502b7a
        send_email.return_value = True
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
        self.test_request_pull()
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
        user = tests.FakeUser()
Pierre-Yves Chibon 502b7a
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 502b7a
            output = self.app.get('/test/pull-request/1')
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            csrf_token = output.data.split(
Pierre-Yves Chibon 502b7a
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # No CSRF
Pierre-Yves Chibon 502b7a
            output = self.app.post(
Pierre-Yves Chibon 502b7a
                '/test/pull-request/1/merge', data={}, follow_redirects=True)
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 502b7a
            self.assertIn(
Pierre-Yves Chibon 502b7a
                '<title>Pull request #1 - test - Pagure</title>', output.data)
Pierre-Yves Chibon 502b7a
            self.assertIn(
Pierre-Yves Chibon 502b7a
                'title="View file as of 2a552b">View', output.data)
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # Wrong project
Pierre-Yves Chibon 502b7a
            data = {
Pierre-Yves Chibon 502b7a
                'csrf_token': csrf_token,
Pierre-Yves Chibon 502b7a
            }
Pierre-Yves Chibon 502b7a
            output = self.app.post(
Pierre-Yves Chibon 502b7a
                '/foobar/pull-request/100/merge', data=data, follow_redirects=True)
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # Wrong project
Pierre-Yves Chibon 502b7a
            data = {
Pierre-Yves Chibon 502b7a
                'csrf_token': csrf_token,
Pierre-Yves Chibon 502b7a
            }
Pierre-Yves Chibon 502b7a
            output = self.app.post(
Pierre-Yves Chibon 502b7a
                '/test/pull-request/1/merge', data=data, follow_redirects=True)
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
        user.username = 'pingou'
Pierre-Yves Chibon 502b7a
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # Wrong request id
Pierre-Yves Chibon 502b7a
            data = {
Pierre-Yves Chibon 502b7a
                'csrf_token': csrf_token,
Pierre-Yves Chibon 502b7a
            }
Pierre-Yves Chibon 502b7a
            output = self.app.post(
Pierre-Yves Chibon 502b7a
                '/test/pull-request/100/merge', data=data, follow_redirects=True)
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # Project w/o pull-request
Pierre-Yves Chibon 502b7a
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 502b7a
            settings = repo.settings
Pierre-Yves Chibon 502b7a
            settings['pull_requests'] = False
Pierre-Yves Chibon 502b7a
            repo.settings = settings
Pierre-Yves Chibon 502b7a
            self.session.add(repo)
Pierre-Yves Chibon 502b7a
            self.session.commit()
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # Pull-request disabled
Pierre-Yves Chibon 502b7a
            output = self.app.post(
Pierre-Yves Chibon 502b7a
                '/test/pull-request/1/merge', data=data, follow_redirects=True)
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            # Project w pull-request but only assignee can merge
Pierre-Yves Chibon 502b7a
            settings['pull_requests'] = True
Pierre-Yves Chibon 502b7a
            settings['Only_assignee_can_merge_pull-request'] = True
Pierre-Yves Chibon 502b7a
            repo.settings = settings
Pierre-Yves Chibon 502b7a
            self.session.add(repo)
Pierre-Yves Chibon 502b7a
            self.session.commit()
Pierre-Yves Chibon 502b7a
Pierre-Yves Chibon 502b7a
            output = self.app.post(
Pierre-Yves Chibon 502b7a
                '/test/pull-request/1/merge', data=data, follow_redirects=True)
Pierre-Yves Chibon 502b7a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 502b7a
            self.assertIn(
Pierre-Yves Chibon 502b7a
                '<title>Pull request #1 - test - Pagure</title>',
Pierre-Yves Chibon 502b7a
                output.data)
Pierre-Yves Chibon 502b7a
            self.assertIn(
Pierre-Yves Chibon 502b7a
                '
  • This request must be assigned to be merged
  • ',
    Pierre-Yves Chibon 502b7a
                    output.data)
    Pierre-Yves Chibon 502b7a
    Pierre-Yves Chibon 502b7a
                # PR assigned but not to this user
    Pierre-Yves Chibon 502b7a
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 502b7a
                req = repo.requests[0]
    Pierre-Yves Chibon 502b7a
                req.assignee_id = 2
    Pierre-Yves Chibon 502b7a
                self.session.add(req)
    Pierre-Yves Chibon 502b7a
                self.session.commit()
    Pierre-Yves Chibon 502b7a
    Pierre-Yves Chibon 502b7a
                output = self.app.post(
    Pierre-Yves Chibon 502b7a
                    '/test/pull-request/1/merge', data=data, follow_redirects=True)
    Pierre-Yves Chibon 502b7a
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 502b7a
                self.assertIn(
    Pierre-Yves Chibon 502b7a
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 502b7a
                    output.data)
    Pierre-Yves Chibon 502b7a
                self.assertIn(
    Pierre-Yves Chibon 502b7a
                    '
  • Only the assignee can merge this review
  • ',
    Pierre-Yves Chibon 502b7a
                    output.data)
    Pierre-Yves Chibon 502b7a
    Pierre-Yves Chibon 502b7a
                # Project w/ minimal PR score
    Pierre-Yves Chibon 502b7a
                settings['Only_assignee_can_merge_pull-request'] = False
    Pierre-Yves Chibon 502b7a
                settings['Minimum_score_to_merge_pull-request'] = 2
    Pierre-Yves Chibon 502b7a
                repo.settings = settings
    Pierre-Yves Chibon 502b7a
                self.session.add(repo)
    Pierre-Yves Chibon 502b7a
                self.session.commit()
    Pierre-Yves Chibon 502b7a
    Pierre-Yves Chibon 502b7a
                output = self.app.post(
    Pierre-Yves Chibon 502b7a
                    '/test/pull-request/1/merge', data=data, follow_redirects=True)
    Pierre-Yves Chibon 502b7a
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 502b7a
                self.assertIn(
    Pierre-Yves Chibon 502b7a
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 502b7a
                    output.data)
    Pierre-Yves Chibon 502b7a
                self.assertIn(
    Pierre-Yves Chibon 502b7a
                    '
  • This request does not have the minimum '
  • Pierre-Yves Chibon 502b7a
                    'review score necessary to be merged', output.data)
    Pierre-Yves Chibon 502b7a
    Pierre-Yves Chibon 502b7a
                # Merge
    Pierre-Yves Chibon 502b7a
                settings['Minimum_score_to_merge_pull-request'] = -1
    Pierre-Yves Chibon 502b7a
                repo.settings = settings
    Pierre-Yves Chibon 502b7a
                self.session.add(repo)
    Pierre-Yves Chibon 502b7a
                self.session.commit()
    Pierre-Yves Chibon 502b7a
                output = self.app.post(
    Pierre-Yves Chibon 502b7a
                    '/test/pull-request/1/merge', data=data, follow_redirects=True)
    Pierre-Yves Chibon 502b7a
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 502b7a
                self.assertIn(
    Pierre-Yves Chibon 502b7a
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 502b7a
                self.assertIn(
    Pierre-Yves Chibon 502b7a
                    '
  • Changes merged!
  • ', output.data)
    Pierre-Yves Chibon 502b7a
    Pierre-Yves Chibon 4ce7b3
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 4ce7b3
        def test_merge_request_pull_merge(self, send_email):
    Pierre-Yves Chibon 4ce7b3
            """ Test the merge_request_pull endpoint with a merge PR. """
    Pierre-Yves Chibon 4ce7b3
            send_email.return_value = True
    Pierre-Yves Chibon 4ce7b3
    Pierre-Yves Chibon 4ce7b3
            tests.create_projects(self.session)
    Pierre-Yves Chibon 4ce7b3
            tests.create_projects_git(
    Pierre-Yves Chibon 4ce7b3
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 4ce7b3
            self.set_up_git_repo(
    Pierre-Yves Chibon 4ce7b3
                new_project=None, branch_from='feature', mtype='merge')
    Pierre-Yves Chibon 4ce7b3
    Pierre-Yves Chibon 4ce7b3
            user = tests.FakeUser()
    Pierre-Yves Chibon 4ce7b3
            user.username = 'pingou'
    Pierre-Yves Chibon 4ce7b3
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 4ce7b3
                output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon 4ce7b3
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 4ce7b3
    Pierre-Yves Chibon 4ce7b3
                csrf_token = output.data.split(
    Pierre-Yves Chibon 4ce7b3
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 4ce7b3
    Pierre-Yves Chibon 4ce7b3
                data = {
    Pierre-Yves Chibon 4ce7b3
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 4ce7b3
                }
    Pierre-Yves Chibon 4ce7b3
    Pierre-Yves Chibon 4ce7b3
                # Merge
    Pierre-Yves Chibon 4ce7b3
                output = self.app.post(
    Pierre-Yves Chibon 4ce7b3
                    '/test/pull-request/1/merge', data=data, follow_redirects=True)
    Pierre-Yves Chibon 4ce7b3
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 4ce7b3
                self.assertIn(
    Pierre-Yves Chibon 4ce7b3
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 4ce7b3
                self.assertIn(
    Pierre-Yves Chibon 4ce7b3
                    '
  • Changes merged!
  • ', output.data)
    Pierre-Yves Chibon 4ce7b3
    Pierre-Yves Chibon fb36e7
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon fb36e7
        def test_merge_request_pull_conflicts(self, send_email):
    Pierre-Yves Chibon fb36e7
            """ Test the merge_request_pull endpoint with a conflicting PR. """
    Pierre-Yves Chibon fb36e7
            send_email.return_value = True
    Pierre-Yves Chibon fb36e7
    Pierre-Yves Chibon fb36e7
            tests.create_projects(self.session)
    Pierre-Yves Chibon fb36e7
            tests.create_projects_git(
    Pierre-Yves Chibon fb36e7
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon fb36e7
            self.set_up_git_repo(
    Pierre-Yves Chibon fb36e7
                new_project=None, branch_from='feature', mtype='conflicts')
    Pierre-Yves Chibon fb36e7
    Pierre-Yves Chibon fb36e7
            user = tests.FakeUser()
    Pierre-Yves Chibon fb36e7
            user.username = 'pingou'
    Pierre-Yves Chibon fb36e7
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon fb36e7
                output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon fb36e7
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon fb36e7
    Pierre-Yves Chibon fb36e7
                csrf_token = output.data.split(
    Pierre-Yves Chibon fb36e7
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon fb36e7
    Pierre-Yves Chibon fb36e7
                data = {
    Pierre-Yves Chibon fb36e7
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon fb36e7
                }
    Pierre-Yves Chibon fb36e7
    Pierre-Yves Chibon fb36e7
                # Merge conflicts
    Pierre-Yves Chibon fb36e7
                output = self.app.post(
    Pierre-Yves Chibon fb36e7
                    '/test/pull-request/1/merge', data=data, follow_redirects=True)
    Pierre-Yves Chibon fb36e7
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon fb36e7
                self.assertIn(
    Pierre-Yves Chibon fb36e7
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon fb36e7
                    output.data)
    Pierre-Yves Chibon fb36e7
                self.assertIn(
    Pierre-Yves Chibon fb36e7
                    '
  • Merge conflicts!
  • ', output.data)
    Pierre-Yves Chibon fb36e7
    Pierre-Yves Chibon 51d667
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 51d667
        def test_merge_request_pull_nochange(self, send_email):
    Pierre-Yves Chibon 51d667
            """ Test the merge_request_pull endpoint. """
    Pierre-Yves Chibon 51d667
            send_email.return_value = True
    Pierre-Yves Chibon 51d667
    Pierre-Yves Chibon 51d667
            tests.create_projects(self.session)
    Pierre-Yves Chibon 51d667
            tests.create_projects_git(
    Pierre-Yves Chibon 51d667
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 51d667
            self.set_up_git_repo(
    Pierre-Yves Chibon 51d667
                new_project=None, branch_from='master', mtype='nochanges')
    Pierre-Yves Chibon 51d667
    Pierre-Yves Chibon 51d667
            user = tests.FakeUser()
    Pierre-Yves Chibon 51d667
            user.username = 'pingou'
    Pierre-Yves Chibon 51d667
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 51d667
                output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon 51d667
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 51d667
    Pierre-Yves Chibon 51d667
                csrf_token = output.data.split(
    Pierre-Yves Chibon 51d667
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 51d667
    Pierre-Yves Chibon 51d667
                data = {
    Pierre-Yves Chibon 51d667
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 51d667
                }
    Pierre-Yves Chibon 51d667
    Pierre-Yves Chibon 51d667
                # Nothing to merge
    Pierre-Yves Chibon 51d667
                output = self.app.post(
    Pierre-Yves Chibon 51d667
                    '/test/pull-request/1/merge', data=data, follow_redirects=True)
    Pierre-Yves Chibon 51d667
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 51d667
                self.assertIn(
    Pierre-Yves Chibon 51d667
                    '<title>Pull request #1 - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 51d667
                self.assertIn(
    Pierre-Yves Chibon 51d667
                    '
  • Nothing to do, changes were already '
  • Pierre-Yves Chibon 51d667
                    'merged', output.data)
    Pierre-Yves Chibon 51d667
    Pierre-Yves Chibon 21924a
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 21924a
        def test_request_pull_close(self, send_email):
    Pierre-Yves Chibon 21924a
            """ Test the request_pull endpoint with a closed PR. """
    Pierre-Yves Chibon 21924a
            send_email.return_value = True
    Pierre-Yves Chibon 21924a
    Pierre-Yves Chibon 21924a
            self.test_merge_request_pull_FF()
    Pierre-Yves Chibon 21924a
    Pierre-Yves Chibon 21924a
            output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon 21924a
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 21924a
            self.assertIn(
    Pierre-Yves Chibon 21924a
                '<title>Pull request #1 - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 21924a
            self.assertIn(
    Pierre-Yves Chibon 2af7f7
                'Merged by', output.data)
    Pierre-Yves Chibon 21924a
            self.assertIn(
    Pierre-Yves Chibon 21924a
                'title="View file as of 2a552b">View', output.data)
    Pierre-Yves Chibon 21924a
    Pierre-Yves Chibon c19e35
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon c19e35
        def test_request_pull_disabled(self, send_email):
    Pierre-Yves Chibon c19e35
            """ Test the request_pull endpoint with PR disabled. """
    Pierre-Yves Chibon c19e35
            send_email.return_value = True
    Pierre-Yves Chibon c19e35
    Pierre-Yves Chibon c19e35
            tests.create_projects(self.session)
    Pierre-Yves Chibon c19e35
            tests.create_projects_git(
    Pierre-Yves Chibon c19e35
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon c19e35
            self.set_up_git_repo(new_project=None, branch_from='feature')
    Pierre-Yves Chibon c19e35
    Pierre-Yves Chibon c19e35
            # Project w/o pull-request
    Pierre-Yves Chibon c19e35
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon c19e35
            settings = repo.settings
    Pierre-Yves Chibon c19e35
            settings['pull_requests'] = False
    Pierre-Yves Chibon c19e35
            repo.settings = settings
    Pierre-Yves Chibon c19e35
            self.session.add(repo)
    Pierre-Yves Chibon c19e35
            self.session.commit()
    Pierre-Yves Chibon c19e35
    Pierre-Yves Chibon c19e35
            output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon c19e35
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon c19e35
    Pierre-Yves Chibon cbbc1c
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon cbbc1c
        def test_request_pull_empty_repo(self, send_email):
    Pierre-Yves Chibon ee247e
            """ Test the request_pull endpoint against an empty repo. """
    Pierre-Yves Chibon cbbc1c
            send_email.return_value = True
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            tests.create_projects(self.session)
    Pierre-Yves Chibon cbbc1c
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon cbbc1c
                user_id=2,  # foo
    Pierre-Yves Chibon cbbc1c
                name='test',
    Pierre-Yves Chibon cbbc1c
                description='test project #1',
    Pierre-Yves Chibon cbbc1c
                hook_token='aaabbb',
    Pierre-Yves Chibon cbbc1c
                parent_id=1,
    Pierre-Yves Chibon cbbc1c
            )
    Pierre-Yves Chibon cbbc1c
            self.session.add(item)
    Pierre-Yves Chibon cbbc1c
            self.session.commit()
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            tests.create_projects_git(
    Pierre-Yves Chibon cbbc1c
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon cbbc1c
            tests.create_projects_git(
    Pierre-Yves Chibon cbbc1c
                os.path.join(tests.HERE, 'forks', 'foo'), bare=True)
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            # Create a git repo to play with
    Pierre-Yves Chibon cbbc1c
            gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
    Pierre-Yves Chibon cbbc1c
            self.assertFalse(os.path.exists(gitrepo))
    Pierre-Yves Chibon cbbc1c
            os.makedirs(gitrepo)
    Pierre-Yves Chibon cbbc1c
            repo = pygit2.init_repository(gitrepo, bare=True)
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            # Create a fork of this repo
    Pierre-Yves Chibon cbbc1c
            newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
    Pierre-Yves Chibon cbbc1c
            gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon cbbc1c
            new_repo = pygit2.clone_repository(gitrepo, newpath)
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            # Edit the sources file again
    Pierre-Yves Chibon cbbc1c
            with open(os.path.join(newpath, 'sources'), 'w') as stream:
    Pierre-Yves Chibon cbbc1c
                stream.write('foo\n bar\nbaz\n boose')
    Pierre-Yves Chibon cbbc1c
            new_repo.index.add('sources')
    Pierre-Yves Chibon cbbc1c
            new_repo.index.write()
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            # Commits the files added
    Pierre-Yves Chibon cbbc1c
            tree = new_repo.index.write_tree()
    Pierre-Yves Chibon cbbc1c
            author = pygit2.Signature(
    Pierre-Yves Chibon cbbc1c
                'Alice Author', 'alice@authors.tld')
    Pierre-Yves Chibon cbbc1c
            committer = pygit2.Signature(
    Pierre-Yves Chibon cbbc1c
                'Cecil Committer', 'cecil@committers.tld')
    Pierre-Yves Chibon cbbc1c
            new_repo.create_commit(
    Pierre-Yves Chibon cbbc1c
                'refs/heads/feature',
    Pierre-Yves Chibon cbbc1c
                author,
    Pierre-Yves Chibon cbbc1c
                committer,
    Pierre-Yves Chibon cbbc1c
                'A commit on branch feature',
    Pierre-Yves Chibon cbbc1c
                tree,
    Pierre-Yves Chibon cbbc1c
                []
    Pierre-Yves Chibon cbbc1c
            )
    Pierre-Yves Chibon cbbc1c
            refname = 'refs/heads/feature:refs/heads/feature'
    Pierre-Yves Chibon cbbc1c
            ori_remote = new_repo.remotes[0]
    Pierre-Yves Chibon 27a73d
            PagureRepo.push(ori_remote, refname)
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            # Create a PR for these changes
    Pierre-Yves Chibon cbbc1c
            project = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon f9c5f9
            req = pagure.lib.new_pull_request(
    Pierre-Yves Chibon cbbc1c
                session=self.session,
    Pierre-Yves Chibon cbbc1c
                repo_from=item,
    Pierre-Yves Chibon cbbc1c
                branch_from='feature',
    Pierre-Yves Chibon cbbc1c
                repo_to=project,
    Pierre-Yves Chibon cbbc1c
                branch_to='master',
    Pierre-Yves Chibon cbbc1c
                title='PR from the feature branch',
    Pierre-Yves Chibon cbbc1c
                user='pingou',
    Pierre-Yves Chibon cbbc1c
                requestfolder=None,
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            )
    Pierre-Yves Chibon cbbc1c
            self.session.commit()
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.title, 'PR from the feature branch')
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon cbbc1c
            output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon cbbc1c
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon cbbc1c
            self.assertIn(
    Pierre-Yves Chibon cbbc1c
                '<title>Pull request #1 - test - Pagure</title>', output.data)
    Pierre-Yves Chibon cbbc1c
            self.assertTrue(output.data.count(''), 1)
    Pierre-Yves Chibon cbbc1c
    Pierre-Yves Chibon 54d454
            shutil.rmtree(newpath)
    Pierre-Yves Chibon 54d454
    Pierre-Yves Chibon 981ad4
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 981ad4
        def test_request_pull_empty_fork(self, send_email):
    Pierre-Yves Chibon 981ad4
            """ Test the request_pull endpoint from an empty fork. """
    Pierre-Yves Chibon 981ad4
            send_email.return_value = True
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            tests.create_projects(self.session)
    Pierre-Yves Chibon 981ad4
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon 981ad4
                user_id=2,  # foo
    Pierre-Yves Chibon 981ad4
                name='test',
    Pierre-Yves Chibon 981ad4
                description='test project #1',
    Pierre-Yves Chibon 981ad4
                hook_token='aaabbb',
    Pierre-Yves Chibon 981ad4
                parent_id=1,
    Pierre-Yves Chibon 981ad4
            )
    Pierre-Yves Chibon 981ad4
            self.session.add(item)
    Pierre-Yves Chibon 981ad4
            self.session.commit()
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            tests.create_projects_git(
    Pierre-Yves Chibon 981ad4
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 981ad4
            tests.create_projects_git(
    Pierre-Yves Chibon 981ad4
                os.path.join(tests.HERE, 'forks', 'foo'), bare=True)
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            # Create a git repo to play with
    Pierre-Yves Chibon 981ad4
            gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
    Pierre-Yves Chibon 981ad4
            self.assertFalse(os.path.exists(gitrepo))
    Pierre-Yves Chibon 981ad4
            os.makedirs(gitrepo)
    Pierre-Yves Chibon 981ad4
            repo = pygit2.init_repository(gitrepo, bare=True)
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            # Create a fork of this repo
    Pierre-Yves Chibon 981ad4
            newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
    Pierre-Yves Chibon 981ad4
            gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon 981ad4
            new_repo = pygit2.clone_repository(gitrepo, newpath)
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            # Create a PR for these "changes" (there are none, both repos are
    Pierre-Yves Chibon 981ad4
            # empty)
    Pierre-Yves Chibon 981ad4
            project = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon f9c5f9
            req = pagure.lib.new_pull_request(
    Pierre-Yves Chibon 981ad4
                session=self.session,
    Pierre-Yves Chibon 981ad4
                repo_from=item,
    Pierre-Yves Chibon 981ad4
                branch_from='feature',
    Pierre-Yves Chibon 981ad4
                repo_to=project,
    Pierre-Yves Chibon 981ad4
                branch_to='master',
    Pierre-Yves Chibon 981ad4
                title='PR from the feature branch',
    Pierre-Yves Chibon 981ad4
                user='pingou',
    Pierre-Yves Chibon 981ad4
                requestfolder=None,
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            )
    Pierre-Yves Chibon 981ad4
            self.session.commit()
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.title, 'PR from the feature branch')
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 981ad4
            output = self.app.get('/test/pull-request/1', follow_redirects=True)
    Pierre-Yves Chibon 981ad4
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 981ad4
            self.assertIn(
    Pierre-Yves Chibon 981ad4
                '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 981ad4
            self.assertIn(
    Pierre-Yves Chibon 981ad4
                '
  • Fork is empty, there are no commits to '
  • Pierre-Yves Chibon 981ad4
                'request pulling', output.data)
    Pierre-Yves Chibon 981ad4
    Pierre-Yves Chibon 54d454
            shutil.rmtree(newpath)
    Pierre-Yves Chibon 54d454
    Pierre-Yves Chibon e8b89f
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon e8b89f
        def test_request_pulls(self, send_email):
    Pierre-Yves Chibon a2d4e0
            """ Test the request_pulls endpoint. """
    Pierre-Yves Chibon e8b89f
            send_email.return_value = True
    Pierre-Yves Chibon e8b89f
    Pierre-Yves Chibon a2d4e0
            # No such project
    Pierre-Yves Chibon a2d4e0
            output = self.app.get('/test/pull-requests')
    Pierre-Yves Chibon a2d4e0
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon a2d4e0
            tests.create_projects(self.session)
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon a2d4e0
            output = self.app.get('/test/pull-requests')
    Pierre-Yves Chibon a2d4e0
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon a2d4e0
            self.assertIn('Pull-requests (0)', output.data)
    Pierre-Yves Chibon a2d4e0
            self.assertIn('(0 Closed)', output.data)
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon a2d4e0
            self.set_up_git_repo(new_project=None, branch_from='feature')
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon a2d4e0
            output = self.app.get('/test/pull-requests')
    Pierre-Yves Chibon a2d4e0
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon a2d4e0
            self.assertIn('Pull-requests (1)', output.data)
    Pierre-Yves Chibon a2d4e0
            self.assertIn('(0 Closed)', output.data)
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon 6e3c4b
            output = self.app.get('/test/pull-requests?status=Closed')
    Pierre-Yves Chibon a2d4e0
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon a2d4e0
            self.assertIn('Closed Pull-requests (0)', output.data)
    Pierre-Yves Chibon a2d4e0
            self.assertIn('(1 Open)', output.data)
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon 6e3c4b
            output = self.app.get('/test/pull-requests?status=0')
    Pierre-Yves Chibon 6e3c4b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 6e3c4b
            self.assertIn('Closed/Merged Pull-requests (0)', output.data)
    Pierre-Yves Chibon 6e3c4b
            self.assertIn('(1 Open)', output.data)
    Pierre-Yves Chibon 6e3c4b
    Pierre-Yves Chibon a2d4e0
            # Project w/o pull-request
    Pierre-Yves Chibon a2d4e0
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon a2d4e0
            settings = repo.settings
    Pierre-Yves Chibon a2d4e0
            settings['pull_requests'] = False
    Pierre-Yves Chibon a2d4e0
            repo.settings = settings
    Pierre-Yves Chibon a2d4e0
            self.session.add(repo)
    Pierre-Yves Chibon a2d4e0
            self.session.commit()
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon a2d4e0
            output = self.app.get('/test/pull-requests')
    Pierre-Yves Chibon a2d4e0
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon a2d4e0
    Pierre-Yves Chibon d61bcb
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon d61bcb
        def test_request_pull_patch(self, send_email):
    Pierre-Yves Chibon d61bcb
            """ Test the request_pull_patch endpoint. """
    Pierre-Yves Chibon d61bcb
            send_email.return_value = True
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            output = self.app.get('/test/pull-request/1.patch')
    Pierre-Yves Chibon d61bcb
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            tests.create_projects(self.session)
    Pierre-Yves Chibon d61bcb
            tests.create_projects_git(
    Pierre-Yves Chibon d61bcb
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon d61bcb
            self.set_up_git_repo(
    Pierre-Yves Chibon d61bcb
                new_project=None, branch_from='feature', mtype='merge')
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            output = self.app.get('/test/pull-request/100.patch')
    Pierre-Yves Chibon d61bcb
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            output = self.app.get('/test/pull-request/1.patch')
    Pierre-Yves Chibon d61bcb
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            npatch = []
    Pierre-Yves Chibon d61bcb
            for row in output.data.split('\n'):
    Pierre-Yves Chibon d61bcb
                if row.startswith('Date:'):
    Pierre-Yves Chibon d61bcb
                    continue
    Pierre-Yves Chibon d61bcb
                if row.startswith('From '):
    Pierre-Yves Chibon d61bcb
                    row = row.split(' ', 2)[2]
    Pierre-Yves Chibon d61bcb
                npatch.append(row)
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            exp = """Mon Sep 17 00:00:00 2001
    Pierre-Yves Chibon d61bcb
    From: Alice Author <alice@authors.tld></alice@authors.tld>
    Pierre-Yves Chibon d61bcb
    Subject: A commit on branch feature
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
    ---
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
    diff --git a/.gitignore b/.gitignore
    Pierre-Yves Chibon d61bcb
    new file mode 100644
    Pierre-Yves Chibon d61bcb
    index 0000000..e4e5f6c
    Pierre-Yves Chibon d61bcb
    --- /dev/null
    Pierre-Yves Chibon d61bcb
    +++ b/.gitignore
    Pierre-Yves Chibon d61bcb
    @@ -0,0 +1 @@
    Pierre-Yves Chibon d61bcb
    +*~
    Pierre-Yves Chibon d61bcb
    \ No newline at end of file
    Pierre-Yves Chibon d61bcb
    diff --git a/sources b/sources
    Pierre-Yves Chibon d61bcb
    index 9f44358..2a552bb 100644
    Pierre-Yves Chibon d61bcb
    --- a/sources
    Pierre-Yves Chibon d61bcb
    +++ b/sources
    Pierre-Yves Chibon d61bcb
    @@ -1,2 +1,4 @@
    Pierre-Yves Chibon d61bcb
     foo
    Pierre-Yves Chibon d61bcb
    - bar
    Pierre-Yves Chibon d61bcb
    \ No newline at end of file
    Pierre-Yves Chibon d61bcb
    + bar
    Pierre-Yves Chibon d61bcb
    +baz
    Pierre-Yves Chibon d61bcb
    + boose
    Pierre-Yves Chibon d61bcb
    \ No newline at end of file
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
    """
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            patch = '\n'.join(npatch)
    Pierre-Yves Chibon d61bcb
            #print patch
    Pierre-Yves Chibon d61bcb
            self.assertEqual(patch, exp)
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            # Project w/o pull-request
    Pierre-Yves Chibon d61bcb
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon d61bcb
            settings = repo.settings
    Pierre-Yves Chibon d61bcb
            settings['pull_requests'] = False
    Pierre-Yves Chibon d61bcb
            repo.settings = settings
    Pierre-Yves Chibon d61bcb
            self.session.add(repo)
    Pierre-Yves Chibon d61bcb
            self.session.commit()
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon d61bcb
            output = self.app.get('/test/pull-request/1.patch')
    Pierre-Yves Chibon d61bcb
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon d61bcb
    Pierre-Yves Chibon b54ac4
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon f75e13
        def test_request_pull_patch_close(self, send_email):
    Pierre-Yves Chibon f75e13
            """ Test the request_pull_patch endpoint with a closed PR. """
    Pierre-Yves Chibon f75e13
            send_email.return_value = True
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
            self.test_merge_request_pull_FF()
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
            output = self.app.get('/test/pull-request/1.patch')
    Pierre-Yves Chibon f75e13
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
            npatch = []
    Pierre-Yves Chibon f75e13
            for row in output.data.split('\n'):
    Pierre-Yves Chibon f75e13
                if row.startswith('Date:'):
    Pierre-Yves Chibon f75e13
                    continue
    Pierre-Yves Chibon f75e13
                if row.startswith('From '):
    Pierre-Yves Chibon f75e13
                    row = row.split(' ', 2)[2]
    Pierre-Yves Chibon f75e13
                npatch.append(row)
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
            exp = """Mon Sep 17 00:00:00 2001
    Pierre-Yves Chibon f75e13
    From: Alice Author <alice@authors.tld></alice@authors.tld>
    Pierre-Yves Chibon f75e13
    Subject: A commit on branch feature
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
    ---
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
    diff --git a/sources b/sources
    Pierre-Yves Chibon f75e13
    index 9f44358..2a552bb 100644
    Pierre-Yves Chibon f75e13
    --- a/sources
    Pierre-Yves Chibon f75e13
    +++ b/sources
    Pierre-Yves Chibon f75e13
    @@ -1,2 +1,4 @@
    Pierre-Yves Chibon f75e13
     foo
    Pierre-Yves Chibon f75e13
    - bar
    Pierre-Yves Chibon f75e13
    \ No newline at end of file
    Pierre-Yves Chibon f75e13
    + bar
    Pierre-Yves Chibon f75e13
    +baz
    Pierre-Yves Chibon f75e13
    + boose
    Pierre-Yves Chibon f75e13
    \ No newline at end of file
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
    """
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
            patch = '\n'.join(npatch)
    Pierre-Yves Chibon f75e13
            #print patch
    Pierre-Yves Chibon f75e13
            self.assertEqual(patch, exp)
    Pierre-Yves Chibon f75e13
    Pierre-Yves Chibon f75e13
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 300a00
        def test_request_pull_patch_empty_repo(self, send_email):
    Pierre-Yves Chibon 300a00
            """ Test the request_pull_patch endpoint against an empty repo. """
    Pierre-Yves Chibon 300a00
            send_email.return_value = True
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            tests.create_projects(self.session)
    Pierre-Yves Chibon 300a00
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon 300a00
                user_id=2,  # foo
    Pierre-Yves Chibon 300a00
                name='test',
    Pierre-Yves Chibon 300a00
                description='test project #1',
    Pierre-Yves Chibon 300a00
                hook_token='aaabbb',
    Pierre-Yves Chibon 300a00
                parent_id=1,
    Pierre-Yves Chibon 300a00
            )
    Pierre-Yves Chibon 300a00
            self.session.add(item)
    Pierre-Yves Chibon 300a00
            self.session.commit()
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            tests.create_projects_git(
    Pierre-Yves Chibon 300a00
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 300a00
            tests.create_projects_git(
    Pierre-Yves Chibon 300a00
                os.path.join(tests.HERE, 'forks', 'foo'), bare=True)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            # Create a git repo to play with
    Pierre-Yves Chibon 300a00
            gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
    Pierre-Yves Chibon 300a00
            self.assertFalse(os.path.exists(gitrepo))
    Pierre-Yves Chibon 300a00
            os.makedirs(gitrepo)
    Pierre-Yves Chibon 300a00
            repo = pygit2.init_repository(gitrepo, bare=True)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            # Create a fork of this repo
    Pierre-Yves Chibon 300a00
            newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
    Pierre-Yves Chibon 300a00
            gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon 300a00
            new_repo = pygit2.clone_repository(gitrepo, newpath)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            # Edit the sources file again
    Pierre-Yves Chibon 300a00
            with open(os.path.join(newpath, 'sources'), 'w') as stream:
    Pierre-Yves Chibon 300a00
                stream.write('foo\n bar\nbaz\n boose')
    Pierre-Yves Chibon 300a00
            new_repo.index.add('sources')
    Pierre-Yves Chibon 300a00
            new_repo.index.write()
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            # Commits the files added
    Pierre-Yves Chibon 300a00
            tree = new_repo.index.write_tree()
    Pierre-Yves Chibon 300a00
            author = pygit2.Signature(
    Pierre-Yves Chibon 300a00
                'Alice Author', 'alice@authors.tld')
    Pierre-Yves Chibon 300a00
            committer = pygit2.Signature(
    Pierre-Yves Chibon 300a00
                'Cecil Committer', 'cecil@committers.tld')
    Pierre-Yves Chibon 300a00
            new_repo.create_commit(
    Pierre-Yves Chibon 300a00
                'refs/heads/feature',
    Pierre-Yves Chibon 300a00
                author,
    Pierre-Yves Chibon 300a00
                committer,
    Pierre-Yves Chibon 300a00
                'A commit on branch feature',
    Pierre-Yves Chibon 300a00
                tree,
    Pierre-Yves Chibon 300a00
                []
    Pierre-Yves Chibon 300a00
            )
    Pierre-Yves Chibon 300a00
            refname = 'refs/heads/feature:refs/heads/feature'
    Pierre-Yves Chibon 300a00
            ori_remote = new_repo.remotes[0]
    Pierre-Yves Chibon 27a73d
            PagureRepo.push(ori_remote, refname)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            # Create a PR for these "changes" (there are none, both repos are
    Pierre-Yves Chibon 300a00
            # empty)
    Pierre-Yves Chibon 300a00
            project = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon f9c5f9
            req = pagure.lib.new_pull_request(
    Pierre-Yves Chibon 300a00
                session=self.session,
    Pierre-Yves Chibon 300a00
                repo_from=item,
    Pierre-Yves Chibon 300a00
                branch_from='feature',
    Pierre-Yves Chibon 300a00
                repo_to=project,
    Pierre-Yves Chibon 300a00
                branch_to='master',
    Pierre-Yves Chibon 300a00
                title='PR from the feature branch',
    Pierre-Yves Chibon 300a00
                user='pingou',
    Pierre-Yves Chibon 300a00
                requestfolder=None,
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            )
    Pierre-Yves Chibon 300a00
            self.session.commit()
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.title, 'PR from the feature branch')
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            output = self.app.get('/test/pull-request/1.patch', follow_redirects=True)
    Pierre-Yves Chibon 300a00
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            npatch = []
    Pierre-Yves Chibon 300a00
            for row in output.data.split('\n'):
    Pierre-Yves Chibon 300a00
                if row.startswith('Date:'):
    Pierre-Yves Chibon 300a00
                    continue
    Pierre-Yves Chibon 300a00
                if row.startswith('From '):
    Pierre-Yves Chibon 300a00
                    row = row.split(' ', 2)[2]
    Pierre-Yves Chibon 300a00
                npatch.append(row)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            exp = """Mon Sep 17 00:00:00 2001
    Pierre-Yves Chibon 300a00
    From: Alice Author <alice@authors.tld></alice@authors.tld>
    Pierre-Yves Chibon 300a00
    Subject: A commit on branch feature
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
    ---
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
    diff --git a/sources b/sources
    Pierre-Yves Chibon 300a00
    new file mode 100644
    Pierre-Yves Chibon 300a00
    index 0000000..2a552bb
    Pierre-Yves Chibon 300a00
    --- /dev/null
    Pierre-Yves Chibon 300a00
    +++ b/sources
    Pierre-Yves Chibon 300a00
    @@ -0,0 +1,4 @@
    Pierre-Yves Chibon 300a00
    +foo
    Pierre-Yves Chibon 300a00
    + bar
    Pierre-Yves Chibon 300a00
    +baz
    Pierre-Yves Chibon 300a00
    + boose
    Pierre-Yves Chibon 300a00
    \ No newline at end of file
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
    """
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 300a00
            patch = '\n'.join(npatch)
    Pierre-Yves Chibon 300a00
            #print patch
    Pierre-Yves Chibon 300a00
            self.assertEqual(patch, exp)
    Pierre-Yves Chibon 300a00
    Pierre-Yves Chibon 54d454
            shutil.rmtree(newpath)
    Pierre-Yves Chibon 54d454
    Pierre-Yves Chibon 300a00
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon b54ac4
        def test_request_pull_patch_empty_fork(self, send_email):
    Pierre-Yves Chibon b54ac4
            """ Test the request_pull_patch endpoint from an empty fork. """
    Pierre-Yves Chibon b54ac4
            send_email.return_value = True
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            tests.create_projects(self.session)
    Pierre-Yves Chibon b54ac4
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon b54ac4
                user_id=2,  # foo
    Pierre-Yves Chibon b54ac4
                name='test',
    Pierre-Yves Chibon b54ac4
                description='test project #1',
    Pierre-Yves Chibon b54ac4
                hook_token='aaabbb',
    Pierre-Yves Chibon b54ac4
                parent_id=1,
    Pierre-Yves Chibon b54ac4
            )
    Pierre-Yves Chibon b54ac4
            self.session.add(item)
    Pierre-Yves Chibon b54ac4
            self.session.commit()
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            tests.create_projects_git(
    Pierre-Yves Chibon b54ac4
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon b54ac4
            tests.create_projects_git(
    Pierre-Yves Chibon b54ac4
                os.path.join(tests.HERE, 'forks', 'foo'), bare=True)
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            # Create a git repo to play with
    Pierre-Yves Chibon b54ac4
            gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
    Pierre-Yves Chibon b54ac4
            self.assertFalse(os.path.exists(gitrepo))
    Pierre-Yves Chibon b54ac4
            os.makedirs(gitrepo)
    Pierre-Yves Chibon b54ac4
            repo = pygit2.init_repository(gitrepo, bare=True)
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            # Create a fork of this repo
    Pierre-Yves Chibon b54ac4
            newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
    Pierre-Yves Chibon b54ac4
            gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon b54ac4
            new_repo = pygit2.clone_repository(gitrepo, newpath)
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            # Create a PR for these "changes" (there are none, both repos are
    Pierre-Yves Chibon b54ac4
            # empty)
    Pierre-Yves Chibon b54ac4
            project = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon f9c5f9
            req = pagure.lib.new_pull_request(
    Pierre-Yves Chibon b54ac4
                session=self.session,
    Pierre-Yves Chibon b54ac4
                repo_from=item,
    Pierre-Yves Chibon b54ac4
                branch_from='feature',
    Pierre-Yves Chibon b54ac4
                repo_to=project,
    Pierre-Yves Chibon b54ac4
                branch_to='master',
    Pierre-Yves Chibon b54ac4
                title='PR from the feature branch',
    Pierre-Yves Chibon b54ac4
                user='pingou',
    Pierre-Yves Chibon b54ac4
                requestfolder=None,
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            )
    Pierre-Yves Chibon b54ac4
            self.session.commit()
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon f9c5f9
            self.assertEqual(req.title, 'PR from the feature branch')
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon b54ac4
            output = self.app.get('/test/pull-request/1.patch', follow_redirects=True)
    Pierre-Yves Chibon b54ac4
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon b54ac4
            self.assertIn(
    Pierre-Yves Chibon b54ac4
                '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon b54ac4
            self.assertIn(
    Pierre-Yves Chibon b54ac4
                '
  • Fork is empty, there are no commits to '
  • Pierre-Yves Chibon b54ac4
                'request pulling', output.data)
    Pierre-Yves Chibon b54ac4
    Pierre-Yves Chibon 54d454
            shutil.rmtree(newpath)
    Pierre-Yves Chibon 54d454
    Pierre-Yves Chibon ccefd8
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon ccefd8
        def test_cancel_request_pull(self, send_email):
    Pierre-Yves Chibon ccefd8
            """ Test the cancel_request_pull endpoint. """
    Pierre-Yves Chibon ccefd8
            send_email.return_value = True
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
            tests.create_projects(self.session)
    Pierre-Yves Chibon ccefd8
            tests.create_projects_git(
    Pierre-Yves Chibon ccefd8
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon ccefd8
            self.set_up_git_repo(
    Pierre-Yves Chibon ccefd8
                new_project=None, branch_from='feature', mtype='merge')
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
            user = tests.FakeUser()
    Pierre-Yves Chibon ccefd8
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon ccefd8
                output = self.app.post('/test/pull-request/cancel/1')
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                output = self.app.post(
    Pierre-Yves Chibon ccefd8
                    '/test/pull-request/cancel/1', follow_redirects=True)
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon ccefd8
                self.assertIn(
    Pierre-Yves Chibon ccefd8
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon ccefd8
                self.assertIn(
    Pierre-Yves Chibon ccefd8
                    '
  • Invalid input submitted
  • ', output.data)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                csrf_token = output.data.split(
    Pierre-Yves Chibon ccefd8
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                data = {
    Pierre-Yves Chibon ccefd8
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon ccefd8
                }
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                # Invalid project
    Pierre-Yves Chibon ccefd8
                output = self.app.post(
    Pierre-Yves Chibon ccefd8
                    '/foo/pull-request/cancel/1', data=data, follow_redirects=True)
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                # Invalid PR id
    Pierre-Yves Chibon ccefd8
                output = self.app.post(
    Pierre-Yves Chibon ccefd8
                    '/test/pull-request/cancel/100', data=data, follow_redirects=True)
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                # Invalid user for this project
    Pierre-Yves Chibon ccefd8
                output = self.app.post(
    Pierre-Yves Chibon ccefd8
                    '/test/pull-request/cancel/1', data=data, follow_redirects=True)
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
            user.username = 'pingou'
    Pierre-Yves Chibon ccefd8
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon ccefd8
                # Project w/o pull-request
    Pierre-Yves Chibon ccefd8
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon ccefd8
                settings = repo.settings
    Pierre-Yves Chibon ccefd8
                settings['pull_requests'] = False
    Pierre-Yves Chibon ccefd8
                repo.settings = settings
    Pierre-Yves Chibon ccefd8
                self.session.add(repo)
    Pierre-Yves Chibon ccefd8
                self.session.commit()
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                output = self.app.post(
    Pierre-Yves Chibon ccefd8
                    '/test/pull-request/cancel/1', data=data, follow_redirects=True)
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                # Project w/o pull-request
    Pierre-Yves Chibon ccefd8
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon ccefd8
                settings = repo.settings
    Pierre-Yves Chibon ccefd8
                settings['pull_requests'] = True
    Pierre-Yves Chibon ccefd8
                repo.settings = settings
    Pierre-Yves Chibon ccefd8
                self.session.add(repo)
    Pierre-Yves Chibon ccefd8
                self.session.commit()
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon ccefd8
                output = self.app.post(
    Pierre-Yves Chibon ccefd8
                    '/test/pull-request/cancel/1', data=data, follow_redirects=True)
    Pierre-Yves Chibon ccefd8
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon ccefd8
                self.assertIn(
    Pierre-Yves Chibon ccefd8
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon ccefd8
                self.assertIn(
    Pierre-Yves Chibon ccefd8
                    '
  • Request pull canceled!
  • ',
    Pierre-Yves Chibon ccefd8
                    output.data)
    Pierre-Yves Chibon ccefd8
    Pierre-Yves Chibon 005063
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 005063
        def test_set_assignee_requests(self, send_email):
    Pierre-Yves Chibon 005063
            """ Test the set_assignee_requests endpoint. """
    Pierre-Yves Chibon 005063
            send_email.return_value = True
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
            tests.create_projects(self.session)
    Pierre-Yves Chibon 005063
            tests.create_projects_git(
    Pierre-Yves Chibon 005063
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 005063
            self.set_up_git_repo(new_project=None, branch_from='feature')
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
            # No such project
    Pierre-Yves Chibon 005063
            user = tests.FakeUser()
    Pierre-Yves Chibon 005063
            user.username = 'foo'
    Pierre-Yves Chibon 005063
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 005063
                output = self.app.post('/foo/pull-request/1/assign')
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                output = self.app.post('/test/pull-request/100/assign')
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                # Invalid input
    Pierre-Yves Chibon 005063
                output = self.app.post(
    Pierre-Yves Chibon 005063
                    '/test/pull-request/1/assign', follow_redirects=True)
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 005063
                    output.data)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '

    Title: PR from the feature branch

    ', output.data)
    Pierre-Yves Chibon 005063
                self.assertNotIn(
    Pierre-Yves Chibon 005063
                    '
  • Request assigned
  • ', output.data)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                output = self.app.get('/test/pull-request/1')
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                csrf_token = output.data.split(
    Pierre-Yves Chibon 005063
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                data = {
    Pierre-Yves Chibon 005063
                    'user': 'pingou',
    Pierre-Yves Chibon 005063
                }
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                # No CSRF
    Pierre-Yves Chibon 005063
                output = self.app.post(
    Pierre-Yves Chibon 005063
                    '/test/pull-request/1/assign', data=data,
    Pierre-Yves Chibon 005063
                    follow_redirects=True)
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 005063
                    output.data)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '

    Title: PR from the feature branch

    ', output.data)
    Pierre-Yves Chibon 005063
                self.assertNotIn(
    Pierre-Yves Chibon 005063
                    '
  • Request assigned
  • ', output.data)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                # Invalid assignee
    Pierre-Yves Chibon 005063
                data = {
    Pierre-Yves Chibon 005063
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 005063
                    'user': 'bar',
    Pierre-Yves Chibon 005063
                }
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                output = self.app.post(
    Pierre-Yves Chibon 005063
                    '/test/pull-request/1/assign', data=data,
    Pierre-Yves Chibon 005063
                    follow_redirects=True)
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 005063
                    output.data)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '

    Title: PR from the feature branch

    ', output.data)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '
  • No user "bar" found
  • ',
    Pierre-Yves Chibon 005063
                    output.data)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                # Assign the PR
    Pierre-Yves Chibon 005063
                data = {
    Pierre-Yves Chibon 005063
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 005063
                    'user': 'pingou',
    Pierre-Yves Chibon 005063
                }
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                output = self.app.post(
    Pierre-Yves Chibon 005063
                    '/test/pull-request/1/assign', data=data,
    Pierre-Yves Chibon 005063
                    follow_redirects=True)
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 005063
                    output.data)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '

    Title: PR from the feature branch

    ', output.data)
    Pierre-Yves Chibon 005063
                self.assertIn(
    Pierre-Yves Chibon 005063
                    '
  • Request assigned
  • ', output.data)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                # Pull-Request closed
    Pierre-Yves Chibon 005063
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 005063
                req = repo.requests[0]
    Pierre-Yves Chibon ce0f3f
                req.status = 'Closed'
    Pierre-Yves Chibon ce0f3f
                req.closed_by_in = 1
    Pierre-Yves Chibon 005063
                self.session.add(req)
    Pierre-Yves Chibon 005063
                self.session.commit()
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                output = self.app.post(
    Pierre-Yves Chibon 005063
                    '/test/pull-request/1/assign', data=data,
    Pierre-Yves Chibon 005063
                    follow_redirects=True)
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                # Project w/o pull-request
    Pierre-Yves Chibon 005063
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 005063
                settings = repo.settings
    Pierre-Yves Chibon 005063
                settings['pull_requests'] = False
    Pierre-Yves Chibon 005063
                repo.settings = settings
    Pierre-Yves Chibon 005063
                self.session.add(repo)
    Pierre-Yves Chibon 005063
                self.session.commit()
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 005063
                output = self.app.post(
    Pierre-Yves Chibon 005063
                    '/test/pull-request/1/assign', data=data,
    Pierre-Yves Chibon 005063
                    follow_redirects=True)
    Pierre-Yves Chibon 005063
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 005063
    Pierre-Yves Chibon 652a23
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 652a23
        def test_fork_project(self, send_email):
    Pierre-Yves Chibon 652a23
            """ Test the fork_project endpoint. """
    Pierre-Yves Chibon 652a23
            send_email.return_value = True
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
            tests.create_projects(self.session)
    Pierre-Yves Chibon 2099a6
            for folder in ['docs', 'tickets', 'requests', 'repos']:
    Pierre-Yves Chibon 652a23
                tests.create_projects_git(
    Pierre-Yves Chibon 652a23
                    os.path.join(tests.HERE, folder), bare=True)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
            user = tests.FakeUser()
    Pierre-Yves Chibon 652a23
            user.username = 'pingou'
    Pierre-Yves Chibon 652a23
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 652a23
                output = self.app.post('/do_fork/test')
    Pierre-Yves Chibon 652a23
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                output = self.app.get('/new/')
    Pierre-Yves Chibon 652a23
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 652a23
                self.assertTrue('

    New project

    ' in output.data)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                csrf_token = output.data.split(
    Pierre-Yves Chibon 652a23
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                data = {
    Pierre-Yves Chibon 652a23
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 652a23
                }
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                output = self.app.post(
    Pierre-Yves Chibon 652a23
                    '/do_fork/foo', data=data, follow_redirects=True)
    Pierre-Yves Chibon 652a23
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                output = self.app.post(
    Pierre-Yves Chibon 652a23
                    '/do_fork/test', data=data, follow_redirects=True)
    Pierre-Yves Chibon 652a23
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 652a23
                self.assertIn(
    Pierre-Yves Chibon 652a23
                    '
  • You may not fork your own repo
  • ',
    Pierre-Yves Chibon 652a23
                    output.data)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
            user.username = 'foo'
    Pierre-Yves Chibon 652a23
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 652a23
                output = self.app.post('/do_fork/test')
    Pierre-Yves Chibon 652a23
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                data = {
    Pierre-Yves Chibon 652a23
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 652a23
                }
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon 652a23
                output = self.app.post(
    Pierre-Yves Chibon 652a23
                    '/do_fork/test', data=data, follow_redirects=True)
    Pierre-Yves Chibon 652a23
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 652a23
                self.assertIn(
    Pierre-Yves Chibon 652a23
                    '
  • Repo "test" cloned to '
  • Pierre-Yves Chibon 652a23
                    '"foo/test"', output.data)
    Pierre-Yves Chibon 652a23
    Pierre-Yves Chibon cec97d
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon cec97d
        def test_new_request_pull(self, send_email):
    Pierre-Yves Chibon cec97d
            """ Test the new_request_pull endpoint. """
    Pierre-Yves Chibon cec97d
            send_email.return_value = True
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
            self.test_fork_project()
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
            tests.create_projects_git(
    Pierre-Yves Chibon cec97d
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon cec97d
            fork = pagure.lib.get_project(self.session, 'test', user='foo')
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
            self.set_up_git_repo(
    Pierre-Yves Chibon cec97d
                new_project=fork, branch_from='feature', mtype='FF')
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
            user = tests.FakeUser()
    Pierre-Yves Chibon cec97d
            user.username = 'foo'
    Pierre-Yves Chibon cec97d
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon cec97d
                output = self.app.get('/foo/diff/master..feature')
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                output = self.app.get('/test/diff/master..foo')
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                output = self.app.get('/test/diff/foo..master')
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                output = self.app.get('/test/diff/feature..master')
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon cec97d
                    '<title>Pull request # - test - Pagure</title>',
    Pierre-Yves Chibon cec97d
                    output.data)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon cec97d
                    '

    No commits found

    ', output.data)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                output = self.app.get('/test/diff/master..feature')
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon cec97d
                    '<title>Pull request # - test - Pagure</title>',
    Pierre-Yves Chibon cec97d
                    output.data)
    Pierre-Yves Chibon cec97d
                self.assertNotIn(
    Pierre-Yves Chibon cec97d
                    '
    Pierre-Yves Chibon cec97d
                    'value="Create">', output.data)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
            user.username = 'pingou'
    Pierre-Yves Chibon cec97d
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon cec97d
                output = self.app.get('/test/diff/master..feature')
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon cec97d
                    '<title>Pull request # - test - Pagure</title>',
    Pierre-Yves Chibon cec97d
                    output.data)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon cec97d
                    '
    Pierre-Yves Chibon cec97d
                    'value="Create">', output.data)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                csrf_token = output.data.split(
    Pierre-Yves Chibon cec97d
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                data = {
    Pierre-Yves Chibon cec97d
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon cec97d
                    'title': 'foo bar PR',
    Pierre-Yves Chibon cec97d
                }
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon cec97d
                output = self.app.post(
    Pierre-Yves Chibon cec97d
                    '/test/diff/master..feature', data=data, follow_redirects=True)
    Pierre-Yves Chibon cec97d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon f9c5f9
                    '<title>Pull request #2 - test - Pagure</title>',
    Pierre-Yves Chibon f9c5f9
                    output.data)
    Pierre-Yves Chibon cec97d
                self.assertIn(
    Pierre-Yves Chibon cec97d
                    '
  • Request created
  • ', output.data)
    Pierre-Yves Chibon cec97d
    Pierre-Yves Chibon 5fb13f
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 5fb13f
        def test_new_request_pull_empty_repo(self, send_email):
    Pierre-Yves Chibon 5fb13f
            """ Test the new_request_pull endpoint against an empty repo. """
    Pierre-Yves Chibon 5fb13f
            send_email.return_value = True
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
            self.test_fork_project()
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
            tests.create_projects_git(
    Pierre-Yves Chibon 5fb13f
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 5fb13f
            fork = pagure.lib.get_project(self.session, 'test', user='foo')
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
            # Create a git repo to play with
    Pierre-Yves Chibon 5fb13f
            gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
    Pierre-Yves Chibon 5fb13f
            repo = pygit2.init_repository(gitrepo, bare=True)
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
            # Create a fork of this repo
    Pierre-Yves Chibon 5fb13f
            newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
    Pierre-Yves Chibon 5fb13f
            gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon 5fb13f
            new_repo = pygit2.clone_repository(gitrepo, newpath)
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
            user = tests.FakeUser()
    Pierre-Yves Chibon 5fb13f
            user.username = 'foo'
    Pierre-Yves Chibon 5fb13f
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 4a3837
                output = self.app.get(
    Pierre-Yves Chibon 4a3837
                    '/fork/foo/test/diff/master..feature',
    Pierre-Yves Chibon 4a3837
                    follow_redirects=True)
    Pierre-Yves Chibon 5fb13f
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 5fb13f
                self.assertIn(
    Pierre-Yves Chibon 4a3837
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 5fb13f
                self.assertIn(
    Pierre-Yves Chibon 4a3837
                    '
  • Fork is empty, there are no commits to '
  • Pierre-Yves Chibon 4a3837
                    'request pulling', output.data)
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon bab89f
                output = self.app.get('/test/new_issue')
    Pierre-Yves Chibon 5fb13f
                csrf_token = output.data.split(
    Pierre-Yves Chibon 5fb13f
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
                data = {
    Pierre-Yves Chibon 5fb13f
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 5fb13f
                    'title': 'foo bar PR',
    Pierre-Yves Chibon 5fb13f
                }
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 5fb13f
                output = self.app.post(
    Pierre-Yves Chibon 5fb13f
                    '/test/diff/master..feature', data=data, follow_redirects=True)
    Pierre-Yves Chibon 5fb13f
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 5fb13f
                self.assertIn(
    Pierre-Yves Chibon 5fb13f
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 5fb13f
                self.assertIn(
    Pierre-Yves Chibon 5fb13f
                    '
  • Fork is empty, there are no commits to '
  • Pierre-Yves Chibon 5fb13f
                    'request pulling', output.data)
    Pierre-Yves Chibon 5fb13f
    Pierre-Yves Chibon 54d454
            shutil.rmtree(newpath)
    Pierre-Yves Chibon 54d454
    Pierre-Yves Chibon c18cb0
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon c18cb0
        def test_new_request_pull_empty_fork(self, send_email):
    Pierre-Yves Chibon c18cb0
            """ Test the new_request_pull endpoint against an empty repo. """
    Pierre-Yves Chibon c18cb0
            send_email.return_value = True
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon c18cb0
            self.test_fork_project()
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon c18cb0
            tests.create_projects_git(
    Pierre-Yves Chibon c18cb0
                os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon c18cb0
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon c18cb0
            fork = pagure.lib.get_project(self.session, 'test', user='foo')
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon c18cb0
            # Create a git repo to play with
    Pierre-Yves Chibon c18cb0
            gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
    Pierre-Yves Chibon c18cb0
            repo = pygit2.init_repository(gitrepo, bare=True)
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon c18cb0
            # Create a fork of this repo
    Pierre-Yves Chibon c18cb0
            newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
    Pierre-Yves Chibon c18cb0
            gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon c18cb0
            new_repo = pygit2.clone_repository(gitrepo, newpath)
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon c18cb0
            user = tests.FakeUser()
    Pierre-Yves Chibon c18cb0
            user.username = 'foo'
    Pierre-Yves Chibon c18cb0
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon c18cb0
                output = self.app.get(
    Pierre-Yves Chibon c18cb0
                    '/fork/foo/test/diff/master..master', follow_redirects=True)
    Pierre-Yves Chibon c18cb0
                self.assertIn(
    Pierre-Yves Chibon c18cb0
                    '<title>Overview - test - Pagure</title>', output.data)
    Pierre-Yves Chibon c18cb0
                self.assertIn(
    Pierre-Yves Chibon c18cb0
                    '
  • Fork is empty, there are no commits to '
  • Pierre-Yves Chibon c18cb0
                    'request pulling', output.data)
    Pierre-Yves Chibon c18cb0
    Pierre-Yves Chibon 54d454
            shutil.rmtree(newpath)
    Pierre-Yves Chibon 54d454
    Pierre-Yves Chibon eeb8a9
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon eeb8a9
        def test_pull_request_add_comment(self, send_email):
    Pierre-Yves Chibon eeb8a9
            """ Test the pull_request_add_comment endpoint. """
    Pierre-Yves Chibon eeb8a9
            send_email.return_value = True
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
            self.test_request_pull()
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
            user = tests.FakeUser()
    Pierre-Yves Chibon eeb8a9
            user.username = 'pingou'
    Pierre-Yves Chibon eeb8a9
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon eeb8a9
                output = self.app.post('/foo/pull-request/1/comment')
    Pierre-Yves Chibon eeb8a9
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
                output = self.app.post('/test/pull-request/100/comment')
    Pierre-Yves Chibon eeb8a9
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
                output = self.app.post('/test/pull-request/1/comment')
    Pierre-Yves Chibon eeb8a9
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon eeb8a9
                self.assertTrue(
    Pierre-Yves Chibon eeb8a9
                    output.data.startswith('<section class="add_comment">'))</section>
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
                csrf_token = output.data.split(
    Pierre-Yves Chibon eeb8a9
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
                data = {
    Pierre-Yves Chibon eeb8a9
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon eeb8a9
                    'comment': 'This look alright but we can do better',
    Pierre-Yves Chibon eeb8a9
                }
    Pierre-Yves Chibon eeb8a9
                output = self.app.post(
    Pierre-Yves Chibon eeb8a9
                    '/test/pull-request/1/comment', data=data,
    Pierre-Yves Chibon eeb8a9
                    follow_redirects=True)
    Pierre-Yves Chibon eeb8a9
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon eeb8a9
                self.assertIn(
    Pierre-Yves Chibon eeb8a9
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon eeb8a9
                    output.data)
    Pierre-Yves Chibon eeb8a9
                self.assertIn(
    Pierre-Yves Chibon eeb8a9
                    '
  • Comment added
  • ', output.data)
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
                # Project w/o pull-request
    Pierre-Yves Chibon eeb8a9
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon eeb8a9
                settings = repo.settings
    Pierre-Yves Chibon eeb8a9
                settings['pull_requests'] = False
    Pierre-Yves Chibon eeb8a9
                repo.settings = settings
    Pierre-Yves Chibon eeb8a9
                self.session.add(repo)
    Pierre-Yves Chibon eeb8a9
                self.session.commit()
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon eeb8a9
                output = self.app.post(
    Pierre-Yves Chibon eeb8a9
                    '/test/pull-request/1/comment', data=data,
    Pierre-Yves Chibon eeb8a9
                    follow_redirects=True)
    Pierre-Yves Chibon eeb8a9
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon eeb8a9
    Pierre-Yves Chibon 6d9a52
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 6d9a52
        def test_pull_request_drop_comment(self, send_email):
    Pierre-Yves Chibon 6d9a52
            """ Test the pull_request_drop_comment endpoint. """
    Pierre-Yves Chibon 6d9a52
            send_email.return_value = True
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
            self.test_pull_request_add_comment()
    Pierre-Yves Chibon 6d9a52
            # Project w/ pull-request
    Pierre-Yves Chibon 6d9a52
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 6d9a52
            settings = repo.settings
    Pierre-Yves Chibon 6d9a52
            settings['pull_requests'] = True
    Pierre-Yves Chibon 6d9a52
            repo.settings = settings
    Pierre-Yves Chibon 6d9a52
            self.session.add(repo)
    Pierre-Yves Chibon 6d9a52
            self.session.commit()
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
            user = tests.FakeUser()
    Pierre-Yves Chibon 6d9a52
            user.username = 'foo'
    Pierre-Yves Chibon 6d9a52
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 6d9a52
                output = self.app.post('/foo/pull-request/1/comment/drop')
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                output = self.app.post('/test/pull-request/100/comment/drop')
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                output = self.app.post(
    Pierre-Yves Chibon 6d9a52
                    '/test/pull-request/1/comment/drop', follow_redirects=True)
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 6d9a52
                self.assertIn(
    Pierre-Yves Chibon 6d9a52
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 6d9a52
                    output.data)
    Pierre-Yves Chibon 6d9a52
                self.assertIn('href="#comment-1">Âś', output.data)
    Pierre-Yves Chibon 6d9a52
                self.assertIn(
    Pierre-Yves Chibon 6d9a52
                    '

    This look alright but we can do better

    ',
    Pierre-Yves Chibon 6d9a52
                    output.data)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                csrf_token = output.data.split(
    Pierre-Yves Chibon 6d9a52
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                # Invalid comment id
    Pierre-Yves Chibon 6d9a52
                data = {
    Pierre-Yves Chibon 6d9a52
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon 6d9a52
                    'drop_comment': '10',
    Pierre-Yves Chibon 6d9a52
                }
    Pierre-Yves Chibon 6d9a52
                output = self.app.post(
    Pierre-Yves Chibon 6d9a52
                    '/test/pull-request/1/comment/drop', data=data,
    Pierre-Yves Chibon 6d9a52
                    follow_redirects=True)
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                data['drop_comment'] = '1'
    Pierre-Yves Chibon 6d9a52
                output = self.app.post(
    Pierre-Yves Chibon 6d9a52
                    '/test/pull-request/1/comment/drop', data=data,
    Pierre-Yves Chibon 6d9a52
                    follow_redirects=True)
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
            user.username = 'pingou'
    Pierre-Yves Chibon 6d9a52
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 6d9a52
                # Drop comment
    Pierre-Yves Chibon 6d9a52
                output = self.app.post(
    Pierre-Yves Chibon 6d9a52
                    '/test/pull-request/1/comment/drop', data=data,
    Pierre-Yves Chibon 6d9a52
                    follow_redirects=True)
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 6d9a52
                self.assertIn(
    Pierre-Yves Chibon 6d9a52
                    '<title>Pull request #1 - test - Pagure</title>',
    Pierre-Yves Chibon 6d9a52
                    output.data)
    Pierre-Yves Chibon 6d9a52
                self.assertIn(
    Pierre-Yves Chibon 6d9a52
                    '
  • Comment removed
  • ', output.data)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                # Project w/o pull-request
    Pierre-Yves Chibon 6d9a52
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 6d9a52
                settings = repo.settings
    Pierre-Yves Chibon 6d9a52
                settings['pull_requests'] = False
    Pierre-Yves Chibon 6d9a52
                repo.settings = settings
    Pierre-Yves Chibon 6d9a52
                self.session.add(repo)
    Pierre-Yves Chibon 6d9a52
                self.session.commit()
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 6d9a52
                output = self.app.post(
    Pierre-Yves Chibon 6d9a52
                    '/test/pull-request/1/comment/drop', data=data,
    Pierre-Yves Chibon 6d9a52
                    follow_redirects=True)
    Pierre-Yves Chibon 6d9a52
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 6d9a52
    Pierre-Yves Chibon 9347b5
    Pierre-Yves Chibon 9347b5
    if __name__ == '__main__':
    Pierre-Yves Chibon 9347b5
        SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskForktests)
    Pierre-Yves Chibon 9347b5
        unittest.TextTestRunner(verbosity=2).run(SUITE)