Blame tests/test_pagure_lib_git.py

Pierre-Yves Chibon a945ba
# -*- coding: utf-8 -*-
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
"""
Pierre-Yves Chibon baaf54
 (c) 2015-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
 Authors:
Pierre-Yves Chibon a945ba
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
"""
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard 626417
Pierre-Yves Chibon b63f28
import datetime
Pierre-Yves Chibon b63f28
import os
Pierre-Yves Chibon a945ba
import shutil
Pierre-Yves Chibon a945ba
import sys
Clement Verna 469e2c
import tempfile
Pierre-Yves Chibon b63f28
import time
Pierre-Yves Chibon b63f28
import unittest
Pierre-Yves Chibon b63f28
Pierre-Yves Chibon 024459
import pygit2
Aurélien Bompard 626417
import six
Pierre-Yves Chibon 145998
from mock import patch, MagicMock
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 73d120
sys.path.insert(
Pierre-Yves Chibon 73d120
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon fe5017
import pagure.lib.git
Pierre-Yves Chibon a945ba
import tests
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon bda7f1
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon bda7f1
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon fe5017
class PagureLibGittests(tests.Modeltests):
Pierre-Yves Chibon fe5017
    """ Tests for pagure.lib.git """
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
    def test_write_gitolite_acls(self):
Vivek Anand ffcb0c
        """ Test the write_gitolite_acls function of pagure.lib.git.
Vivek Anand ffcb0c
        when the new uesr is an made an admin """
Pierre-Yves Chibon a945ba
        tests.create_projects(self.session)
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon ead0df
        # Add an user to a project
Vivek Anand ffcb0c
        # The user will be an admin of the project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_user="foo", user="pingou"
Pierre-Yves Chibon ead0df
        )
Pierre-Yves Chibon ead0df
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Pierre-Yves Chibon ead0df
        # Add a forked project
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon ead0df
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test3",
Pierre-Yves Chibon 73d120
            description="test project #2",
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon e2259d
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Pierre-Yves Chibon ead0df
        )
Pierre-Yves Chibon ead0df
        self.session.add(item)
Pierre-Yves Chibon ead0df
        self.session.commit()
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 73d120
            self.session, configfile=outputconf, project=-1
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
        with open(outputconf) as stream:
Pierre-Yves Chibon a945ba
            data = stream.read()
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon ccb160
        exp = """repo test
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
  RW+ = foo
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo docs/test
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
  RW+ = foo
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo tickets/test
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
  RW+ = foo
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon a6701e
repo requests/test
Pierre-Yves Chibon a6701e
  RW+ = pingou
Pierre-Yves Chibon a6701e
  RW+ = foo
Pierre-Yves Chibon a6701e
Pierre-Yves Chibon ead0df
repo test2
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo docs/test2
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo tickets/test2
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon a6701e
repo requests/test2
Pierre-Yves Chibon a6701e
  RW+ = pingou
Pierre-Yves Chibon a6701e
clime afed57
repo somenamespace/test3
clime afed57
  R   = @all
clime afed57
  RW+ = pingou
clime afed57
clime afed57
repo docs/somenamespace/test3
clime afed57
  R   = @all
clime afed57
  RW+ = pingou
clime afed57
clime afed57
repo tickets/somenamespace/test3
clime afed57
  RW+ = pingou
clime afed57
clime afed57
repo requests/somenamespace/test3
clime afed57
  RW+ = pingou
clime afed57
Pierre-Yves Chibon ead0df
repo forks/pingou/test3
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon 59a1eb
repo docs/forks/pingou/test3
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon 59a1eb
repo tickets/forks/pingou/test3
Pierre-Yves Chibon a6701e
  RW+ = pingou
Pierre-Yves Chibon a6701e
Pierre-Yves Chibon 59a1eb
repo requests/forks/pingou/test3
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon ead0df
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon ead0df
        self.assertEqual(data, exp)
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 22e4bd
        os.unlink(outputconf)
Pierre-Yves Chibon 22e4bd
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon d1fe6f
    def test_write_gitolite_acls_preconf(self):
Pierre-Yves Chibon d1fe6f
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon d1fe6f
        a preconf set """
Pierre-Yves Chibon d1fe6f
        tests.create_projects(self.session)
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon 73d120
        preconf = os.path.join(self.path, "header_gitolite")
Pierre-Yves Chibon 73d120
        with open(preconf, "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("# this is a header that is manually added")
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 145998
        helper.write_gitolite_acls(
Pierre-Yves Chibon 73d120
            self.session, outputconf, project=-1, preconf=preconf
Pierre-Yves Chibon d1fe6f
        )
Pierre-Yves Chibon d1fe6f
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        with open(outputconf) as stream:
Pierre-Yves Chibon d1fe6f
            data = stream.read()
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        exp = """# this is a header that is manually added
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon d1fe6f
repo test
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/test
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/test
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/test
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo test2
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/test2
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/test2
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/test2
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo somenamespace/test3
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon d1fe6f
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon 73d120
        self.assertEqual(data.split("\n"), exp.split("\n"))
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        os.unlink(outputconf)
Pierre-Yves Chibon d1fe6f
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
    def test_write_gitolite_acls_preconf_postconf(self):
Pierre-Yves Chibon d1fe6f
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon d1fe6f
        a postconf set """
Pierre-Yves Chibon d1fe6f
        tests.create_projects(self.session)
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        preconf = os.path.join(self.path, "header_gitolite")
Pierre-Yves Chibon 73d120
        with open(preconf, "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("# this is a header that is manually added")
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        postconf = os.path.join(self.path, "footer_gitolite")
Pierre-Yves Chibon 73d120
        with open(postconf, "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("# end of generated configuration")
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 145998
        helper.write_gitolite_acls(
Pierre-Yves Chibon d1fe6f
            self.session,
Pierre-Yves Chibon d1fe6f
            outputconf,
Pierre-Yves Chibon 274e60
            project=-1,
Pierre-Yves Chibon d1fe6f
            preconf=preconf,
Pierre-Yves Chibon 73d120
            postconf=postconf,
Pierre-Yves Chibon d1fe6f
        )
Pierre-Yves Chibon d1fe6f
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        with open(outputconf) as stream:
Pierre-Yves Chibon d1fe6f
            data = stream.read()
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        exp = """# this is a header that is manually added
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon d1fe6f
repo test
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/test
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/test
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/test
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo test2
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/test2
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/test2
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/test2
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo somenamespace/test3
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon d1fe6f
# end of generated configuration
Pierre-Yves Chibon d1fe6f
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon d1fe6f
        self.assertEqual(data, exp)
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        os.unlink(outputconf)
Pierre-Yves Chibon d1fe6f
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
    def test_write_gitolite_acls_postconf(self):
Pierre-Yves Chibon d1fe6f
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon d1fe6f
        a preconf and a postconf set """
Pierre-Yves Chibon d1fe6f
        tests.create_projects(self.session)
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon 73d120
        postconf = os.path.join(self.path, "footer_gitolite")
Pierre-Yves Chibon 73d120
        with open(postconf, "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("# end of generated configuration")
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 145998
        helper.write_gitolite_acls(
Pierre-Yves Chibon 73d120
            self.session, outputconf, project=-1, postconf=postconf
Pierre-Yves Chibon d1fe6f
        )
Pierre-Yves Chibon d1fe6f
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        with open(outputconf) as stream:
Pierre-Yves Chibon d1fe6f
            data = stream.read()
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon ccb160
        exp = """repo test
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/test
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/test
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/test
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo test2
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/test2
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/test2
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/test2
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo somenamespace/test3
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo docs/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  R   = @all
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo tickets/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
repo requests/somenamespace/test3
Pierre-Yves Chibon d1fe6f
  RW+ = pingou
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon d1fe6f
# end of generated configuration
Pierre-Yves Chibon d1fe6f
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon d1fe6f
        self.assertEqual(data, exp)
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        os.unlink(outputconf)
Pierre-Yves Chibon d1fe6f
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon d1fe6f
Patrick Uiterwijk faa79d
    def test_write_gitolite_acls_deploykeys(self):
Patrick Uiterwijk faa79d
        """ Test write_gitolite_acls function to add deploy keys. """
Patrick Uiterwijk faa79d
        tests.create_projects(self.session)
Patrick Uiterwijk faa79d
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Patrick Uiterwijk faa79d
        # Add two deploy keys (one readonly one push)
Pierre-Yves Chibon 73d120
        pingou = pagure.lib.query.get_user(self.session, "pingou")
Pierre-Yves Chibon 930073
        msg1 = pagure.lib.query.add_sshkey_to_project_or_user(
Patrick Uiterwijk faa79d
            session=self.session,
Patrick Uiterwijk faa79d
            project=repo,
Pierre-Yves Chibon 73d120
            ssh_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==",
Patrick Uiterwijk faa79d
            pushaccess=False,
Pierre-Yves Chibon 73d120
            creator=pingou,
Patrick Uiterwijk faa79d
        )
Pierre-Yves Chibon 930073
        msg2 = pagure.lib.query.add_sshkey_to_project_or_user(
Patrick Uiterwijk faa79d
            session=self.session,
Patrick Uiterwijk faa79d
            project=repo,
Pierre-Yves Chibon 73d120
            ssh_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9Xwc2RDzPBhlEDARfHldGjudIVoa04tqT1JVKGQmyllTFz7Rb8CngQL3e7zyNzotnhwYKHdoiLlPkVEiDee4dWMUe48ilqId+FJZQGhyv8fu4BoFdE1AJUVylzmltbLg14VqG5gjTpXgtlrEva9arKwBMHJjRYc8ScaSn3OgyQw==",
Patrick Uiterwijk faa79d
            pushaccess=True,
Pierre-Yves Chibon 73d120
            creator=pingou,
Patrick Uiterwijk faa79d
        )
Patrick Uiterwijk faa79d
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg1, "SSH key added")
Pierre-Yves Chibon 73d120
        self.assertEqual(msg2, "SSH key added")
Patrick Uiterwijk faa79d
        # Add a forked project
Patrick Uiterwijk faa79d
        item = pagure.lib.model.Project(
Patrick Uiterwijk faa79d
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test3",
Pierre-Yves Chibon 73d120
            description="test project #2",
Patrick Uiterwijk faa79d
            is_fork=True,
Patrick Uiterwijk faa79d
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Patrick Uiterwijk faa79d
        )
Patrick Uiterwijk faa79d
        self.session.add(item)
Patrick Uiterwijk faa79d
        self.session.commit()
Patrick Uiterwijk faa79d
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Patrick Uiterwijk faa79d
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
        self.assertTrue(os.path.exists(outputconf))
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
        with open(outputconf) as stream:
Patrick Uiterwijk faa79d
            data = stream.read()
Patrick Uiterwijk faa79d
Pierre-Yves Chibon ccb160
        exp = """repo test
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
  R = deploykey_test_1
Patrick Uiterwijk faa79d
  RW+ = deploykey_test_2
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo docs/test
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
  R = deploykey_test_1
Patrick Uiterwijk faa79d
  RW+ = deploykey_test_2
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo tickets/test
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
  R = deploykey_test_1
Patrick Uiterwijk faa79d
  RW+ = deploykey_test_2
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo requests/test
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
  R = deploykey_test_1
Patrick Uiterwijk faa79d
  RW+ = deploykey_test_2
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo test2
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo docs/test2
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo tickets/test2
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo requests/test2
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo somenamespace/test3
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo docs/somenamespace/test3
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo tickets/somenamespace/test3
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo requests/somenamespace/test3
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo forks/pingou/test3
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo docs/forks/pingou/test3
Patrick Uiterwijk faa79d
  R   = @all
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo tickets/forks/pingou/test3
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
repo requests/forks/pingou/test3
Patrick Uiterwijk faa79d
  RW+ = pingou
Patrick Uiterwijk faa79d
Pierre-Yves Chibon ccb160
# end of body
Patrick Uiterwijk faa79d
"""
Pierre-Yves Chibon 73d120
        # print data
Patrick Uiterwijk faa79d
        self.assertEqual(data, exp)
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
        os.unlink(outputconf)
Patrick Uiterwijk faa79d
        self.assertFalse(os.path.exists(outputconf))
Patrick Uiterwijk faa79d
Vivek Anand 2897c2
    def test_write_gitolite_acls_ticket(self):
Vivek Anand 2897c2
        """ Test the write_gitolite_acls function of pagure.lib.git.
Vivek Anand 2897c2
        when the new uesr is just a ticketer """
Vivek Anand 2897c2
        tests.create_projects(self.session)
Vivek Anand 2897c2
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Vivek Anand 2897c2
        # Add an user to a project
Vivek Anand 2897c2
        # The user will be an admin of the project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Vivek Anand 2897c2
            session=self.session,
Vivek Anand 2897c2
            project=repo,
Pierre-Yves Chibon 73d120
            new_user="foo",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            access="ticket",
Vivek Anand 2897c2
        )
Vivek Anand 2897c2
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Vivek Anand 2897c2
        # Add a forked project
Vivek Anand 2897c2
        item = pagure.lib.model.Project(
Vivek Anand 2897c2
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test3",
Pierre-Yves Chibon 73d120
            description="test project #2",
Vivek Anand 2897c2
            is_fork=True,
Vivek Anand 2897c2
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Vivek Anand 2897c2
        )
Vivek Anand 2897c2
        self.session.add(item)
Vivek Anand 2897c2
        self.session.commit()
Vivek Anand 2897c2
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Vivek Anand 2897c2
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Vivek Anand 2897c2
Vivek Anand 2897c2
        self.assertTrue(os.path.exists(outputconf))
Vivek Anand 2897c2
Vivek Anand 2897c2
        with open(outputconf) as stream:
Vivek Anand 2897c2
            data = stream.read()
Vivek Anand 2897c2
Pierre-Yves Chibon ccb160
        exp = """repo test
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo docs/test
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo tickets/test
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo requests/test
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo test2
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo docs/test2
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo tickets/test2
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo requests/test2
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo somenamespace/test3
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo docs/somenamespace/test3
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo tickets/somenamespace/test3
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo requests/somenamespace/test3
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo forks/pingou/test3
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo docs/forks/pingou/test3
Vivek Anand 2897c2
  R   = @all
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo tickets/forks/pingou/test3
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Vivek Anand 2897c2
repo requests/forks/pingou/test3
Vivek Anand 2897c2
  RW+ = pingou
Vivek Anand 2897c2
Pierre-Yves Chibon ccb160
# end of body
Vivek Anand 2897c2
"""
Pierre-Yves Chibon 73d120
        # print data
Vivek Anand 2897c2
        self.assertEqual(data, exp)
Vivek Anand 2897c2
Vivek Anand 2897c2
        os.unlink(outputconf)
Vivek Anand 2897c2
        self.assertFalse(os.path.exists(outputconf))
Vivek Anand 2897c2
Vivek Anand 994729
    def test_write_gitolite_acls_commit(self):
Vivek Anand 994729
        """ Test the write_gitolite_acls function of pagure.lib.git.
Vivek Anand 994729
        when the new uesr is just a committer """
Vivek Anand 994729
        tests.create_projects(self.session)
Vivek Anand 994729
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Vivek Anand 994729
        # Add an user to a project
Vivek Anand 994729
        # The user will be an admin of the project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Vivek Anand 994729
            session=self.session,
Vivek Anand 994729
            project=repo,
Pierre-Yves Chibon 73d120
            new_user="foo",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            access="commit",
Vivek Anand 994729
        )
Vivek Anand 994729
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Vivek Anand 994729
        # Add a forked project
Vivek Anand 994729
        item = pagure.lib.model.Project(
Vivek Anand 994729
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test3",
Pierre-Yves Chibon 73d120
            description="test project #2",
Vivek Anand 994729
            is_fork=True,
Vivek Anand 994729
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Vivek Anand 994729
        )
Vivek Anand 994729
        self.session.add(item)
Vivek Anand 994729
        self.session.commit()
Vivek Anand 994729
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Vivek Anand 994729
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Vivek Anand 994729
Vivek Anand 994729
        self.assertTrue(os.path.exists(outputconf))
Vivek Anand 994729
Vivek Anand 994729
        with open(outputconf) as stream:
Vivek Anand 994729
            data = stream.read()
Vivek Anand 994729
Pierre-Yves Chibon ccb160
        exp = """repo test
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
  RW+ = foo
Vivek Anand 994729
Vivek Anand 994729
repo docs/test
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
  RW+ = foo
Vivek Anand 994729
Vivek Anand 994729
repo tickets/test
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
  RW+ = foo
Vivek Anand 994729
Vivek Anand 994729
repo requests/test
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
  RW+ = foo
Vivek Anand 994729
Vivek Anand 994729
repo test2
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo docs/test2
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo tickets/test2
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo requests/test2
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo somenamespace/test3
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo docs/somenamespace/test3
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo tickets/somenamespace/test3
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo requests/somenamespace/test3
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo forks/pingou/test3
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo docs/forks/pingou/test3
Vivek Anand 994729
  R   = @all
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo tickets/forks/pingou/test3
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Vivek Anand 994729
repo requests/forks/pingou/test3
Vivek Anand 994729
  RW+ = pingou
Vivek Anand 994729
Pierre-Yves Chibon ccb160
# end of body
Vivek Anand 994729
"""
Pierre-Yves Chibon 73d120
        # print data
Vivek Anand 994729
        self.assertEqual(data, exp)
Vivek Anand 994729
Vivek Anand 994729
        os.unlink(outputconf)
Vivek Anand 994729
        self.assertFalse(os.path.exists(outputconf))
Vivek Anand 994729
Pierre-Yves Chibon 4fc47a
    def test_write_gitolite_acls_groups(self):
Pierre-Yves Chibon 4fc47a
        """ Test the write_gitolite_acls function of pagure.lib.git with
Vivek Anand b5a557
        groups as admin
Pierre-Yves Chibon 4fc47a
        """
Pierre-Yves Chibon 4fc47a
        tests.create_projects(self.session)
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 6f5851
        # Add a couple of groups
Vivek Anand b5a557
        # They would be admins
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group(
Pierre-Yves Chibon 4fc47a
            self.session,
Pierre-Yves Chibon 73d120
            group_name="sysadmin",
Pierre-Yves Chibon 73d120
            display_name="sysadmin group",
Pierre-Yves Chibon ce6666
            description=None,
Pierre-Yves Chibon 73d120
            group_type="user",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 4fc47a
            is_admin=False,
Pierre-Yves Chibon d4d101
            blacklist=[],
Pierre-Yves Chibon 4fc47a
        )
Pierre-Yves Chibon 4fc47a
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User `pingou` added to the group `sysadmin`.")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group(
Pierre-Yves Chibon 6f5851
            self.session,
Pierre-Yves Chibon 73d120
            group_name="devs",
Pierre-Yves Chibon 73d120
            display_name="devs group",
Pierre-Yves Chibon ce6666
            description=None,
Pierre-Yves Chibon 73d120
            group_type="user",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 6f5851
            is_admin=False,
Pierre-Yves Chibon d4d101
            blacklist=[],
Pierre-Yves Chibon 6f5851
        )
Pierre-Yves Chibon 6f5851
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User `pingou` added to the group `devs`.")
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 6f5851
        # Associate these groups to a project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group_to_project(
Pierre-Yves Chibon 4fc47a
            session=self.session,
Pierre-Yves Chibon 4fc47a
            project=repo,
Pierre-Yves Chibon 73d120
            new_group="sysadmin",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 4fc47a
        )
Pierre-Yves Chibon 4fc47a
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_group="devs", user="pingou"
Pierre-Yves Chibon 6f5851
        )
Pierre-Yves Chibon 6f5851
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
        # Add an user to a project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_user="foo", user="pingou"
Pierre-Yves Chibon 4fc47a
        )
Pierre-Yves Chibon 4fc47a
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Pierre-Yves Chibon 4fc47a
        # Add a forked project
Pierre-Yves Chibon 4fc47a
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 4fc47a
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test2",
Pierre-Yves Chibon 73d120
            description="test project #2",
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon 4fc47a
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Pierre-Yves Chibon 4fc47a
        )
Pierre-Yves Chibon 4fc47a
        self.session.add(item)
Pierre-Yves Chibon 4fc47a
        self.session.commit()
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
        with open(outputconf) as stream:
Pierre-Yves Chibon 4fc47a
            data = stream.read()
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon ccb160
        exp = """@devs  = pingou
Pierre-Yves Chibon ccb160
@sysadmin  = pingou
Pierre-Yves Chibon ccb160
# end of groups
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo test
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
  RW+ = foo
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo docs/test
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
  RW+ = foo
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo tickets/test
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
  RW+ = foo
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo requests/test
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
  RW+ = foo
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo test2
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo docs/test2
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo tickets/test2
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo requests/test2
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
clime afed57
repo somenamespace/test3
clime afed57
  R   = @all
clime afed57
  RW+ = pingou
clime afed57
clime afed57
repo docs/somenamespace/test3
clime afed57
  R   = @all
clime afed57
  RW+ = pingou
clime afed57
clime afed57
repo tickets/somenamespace/test3
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo requests/somenamespace/test3
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo forks/pingou/test2
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo docs/forks/pingou/test2
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo tickets/forks/pingou/test2
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo requests/forks/pingou/test2
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Pierre-Yves Chibon ccb160
# end of body
Vivek Anand 1edd2c
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon 73d120
        self.assertEqual(data.split("\n"), exp.split("\n"))
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        os.unlink(outputconf)
Vivek Anand 1edd2c
        self.assertFalse(os.path.exists(outputconf))
Vivek Anand 1edd2c
Vivek Anand 1edd2c
    def test_write_gitolite_acls_groups_ticket(self):
Vivek Anand 1edd2c
        """ Test the write_gitolite_acls function of pagure.lib.git with
Vivek Anand 1edd2c
        groups as ticketers
Vivek Anand 1edd2c
        """
Vivek Anand 1edd2c
        tests.create_projects(self.session)
Vivek Anand 1edd2c
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        # Add a couple of groups
Vivek Anand 1edd2c
        # They would be ticketers
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group(
Vivek Anand 1edd2c
            self.session,
Pierre-Yves Chibon 73d120
            group_name="sysadmin",
Pierre-Yves Chibon 73d120
            display_name="sysadmin group",
Vivek Anand 1edd2c
            description=None,
Pierre-Yves Chibon 73d120
            group_type="user",
Pierre-Yves Chibon 73d120
            user="pingou",
Vivek Anand 1edd2c
            is_admin=False,
Vivek Anand 1edd2c
            blacklist=[],
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User `pingou` added to the group `sysadmin`.")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group(
Vivek Anand 1edd2c
            self.session,
Pierre-Yves Chibon 73d120
            group_name="devs",
Pierre-Yves Chibon 73d120
            display_name="devs group",
Vivek Anand 1edd2c
            description=None,
Pierre-Yves Chibon 73d120
            group_type="user",
Pierre-Yves Chibon 73d120
            user="pingou",
Vivek Anand 1edd2c
            is_admin=False,
Vivek Anand 1edd2c
            blacklist=[],
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User `pingou` added to the group `devs`.")
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        # Associate these groups to a project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group_to_project(
Vivek Anand 1edd2c
            session=self.session,
Vivek Anand 1edd2c
            project=repo,
Pierre-Yves Chibon 73d120
            new_group="sysadmin",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            access="ticket",
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group_to_project(
Vivek Anand 1edd2c
            session=self.session,
Vivek Anand 1edd2c
            project=repo,
Pierre-Yves Chibon 73d120
            new_group="devs",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            access="ticket",
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        # Add an user to a project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_user="foo", user="pingou"
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Vivek Anand 1edd2c
        # Add a forked project
Vivek Anand 1edd2c
        item = pagure.lib.model.Project(
Vivek Anand 1edd2c
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test2",
Pierre-Yves Chibon 73d120
            description="test project #2",
Vivek Anand 1edd2c
            is_fork=True,
Vivek Anand 1edd2c
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.add(item)
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Vivek Anand 1edd2c
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        self.assertTrue(os.path.exists(outputconf))
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        with open(outputconf) as stream:
Vivek Anand 1edd2c
            data = stream.read()
Vivek Anand 1edd2c
Pierre-Yves Chibon ccb160
        exp = """@devs  = pingou
Pierre-Yves Chibon ccb160
@sysadmin  = pingou
Pierre-Yves Chibon ccb160
# end of groups
Pierre-Yves Chibon ccb160
Vivek Anand 1edd2c
repo test
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
  RW+ = foo
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo docs/test
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
  RW+ = foo
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo tickets/test
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
  RW+ = foo
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo requests/test
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
  RW+ = foo
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo test2
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo docs/test2
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo tickets/test2
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo requests/test2
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo somenamespace/test3
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo docs/somenamespace/test3
Vivek Anand 1edd2c
  R   = @all
Vivek Anand 1edd2c
  RW+ = pingou
Vivek Anand 1edd2c
Vivek Anand 1edd2c
repo tickets/somenamespace/test3
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo requests/somenamespace/test3
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo forks/pingou/test2
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo docs/forks/pingou/test2
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo tickets/forks/pingou/test2
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo requests/forks/pingou/test2
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Pierre-Yves Chibon ccb160
# end of body
Vivek Anand 5827c9
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon 73d120
        self.assertEqual(data.split("\n"), exp.split("\n"))
Vivek Anand 5827c9
Vivek Anand 5827c9
        os.unlink(outputconf)
Vivek Anand 5827c9
        self.assertFalse(os.path.exists(outputconf))
Vivek Anand 5827c9
Vivek Anand 5827c9
    def test_write_gitolite_acls_groups_commit(self):
Vivek Anand 5827c9
        """ Test the write_gitolite_acls function of pagure.lib.git with
Vivek Anand 5827c9
        groups as committers
Vivek Anand 5827c9
        """
Vivek Anand 5827c9
        tests.create_projects(self.session)
Vivek Anand 5827c9
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Vivek Anand 5827c9
Vivek Anand 5827c9
        # Add a couple of groups
Vivek Anand 5827c9
        # They would be committers
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group(
Vivek Anand 5827c9
            self.session,
Pierre-Yves Chibon 73d120
            group_name="sysadmin",
Pierre-Yves Chibon 73d120
            display_name="sysadmin group",
Vivek Anand 5827c9
            description=None,
Pierre-Yves Chibon 73d120
            group_type="user",
Pierre-Yves Chibon 73d120
            user="pingou",
Vivek Anand 5827c9
            is_admin=False,
Vivek Anand 5827c9
            blacklist=[],
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User `pingou` added to the group `sysadmin`.")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group(
Vivek Anand 5827c9
            self.session,
Pierre-Yves Chibon 73d120
            group_name="devs",
Pierre-Yves Chibon 73d120
            display_name="devs group",
Vivek Anand 5827c9
            description=None,
Pierre-Yves Chibon 73d120
            group_type="user",
Pierre-Yves Chibon 73d120
            user="pingou",
Vivek Anand 5827c9
            is_admin=False,
Vivek Anand 5827c9
            blacklist=[],
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User `pingou` added to the group `devs`.")
Vivek Anand 5827c9
Vivek Anand 5827c9
        # Associate these groups to a project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group_to_project(
Vivek Anand 5827c9
            session=self.session,
Vivek Anand 5827c9
            project=repo,
Pierre-Yves Chibon 73d120
            new_group="sysadmin",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            access="commit",
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_group_to_project(
Vivek Anand 5827c9
            session=self.session,
Vivek Anand 5827c9
            project=repo,
Pierre-Yves Chibon 73d120
            new_group="devs",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            access="commit",
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Vivek Anand 5827c9
Vivek Anand 5827c9
        # Add an user to a project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_user="foo", user="pingou"
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Vivek Anand 5827c9
        # Add a forked project
Vivek Anand 5827c9
        item = pagure.lib.model.Project(
Vivek Anand 5827c9
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test2",
Pierre-Yves Chibon 73d120
            description="test project #2",
Vivek Anand 5827c9
            is_fork=True,
Vivek Anand 5827c9
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.add(item)
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Vivek Anand 5827c9
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Vivek Anand 5827c9
Vivek Anand 5827c9
        self.assertTrue(os.path.exists(outputconf))
Vivek Anand 5827c9
Vivek Anand 5827c9
        with open(outputconf) as stream:
Vivek Anand 5827c9
            data = stream.read()
Vivek Anand 5827c9
Pierre-Yves Chibon ccb160
        exp = """@devs  = pingou
Pierre-Yves Chibon ccb160
@sysadmin  = pingou
Pierre-Yves Chibon ccb160
# end of groups
Vivek Anand 5827c9
Vivek Anand 5827c9
repo test
Vivek Anand 5827c9
  R   = @all
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo docs/test
Vivek Anand 5827c9
  R   = @all
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo tickets/test
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo requests/test
Pierre-Yves Chibon a3901b
  RW+ = @devs @sysadmin
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo test2
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo docs/test2
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo tickets/test2
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo requests/test2
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo somenamespace/test3
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo docs/somenamespace/test3
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo tickets/somenamespace/test3
clime afed57
  RW+ = pingou
clime afed57
clime afed57
repo requests/somenamespace/test3
clime afed57
  RW+ = pingou
clime afed57
Pierre-Yves Chibon 4fc47a
repo forks/pingou/test2
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 59a1eb
repo docs/forks/pingou/test2
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 59a1eb
repo tickets/forks/pingou/test2
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 59a1eb
repo requests/forks/pingou/test2
Pierre-Yves Chibon 4fc47a
  RW+ = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 4fc47a
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon 73d120
        self.assertEqual(data.split("\n"), exp.split("\n"))
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
        os.unlink(outputconf)
Pierre-Yves Chibon 4fc47a
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 499752
    def test_write_gitolite_project_pr_only(self):
Pierre-Yves Chibon 499752
        """ Test the write_gitolite_acls function of pagure.lib.git.
Pierre-Yves Chibon 499752
        when the project enforces the PR approach.
Pierre-Yves Chibon 499752
        """
Pierre-Yves Chibon 499752
        tests.create_projects(self.session)
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon 499752
        # Make the project enforce the PR workflow
Pierre-Yves Chibon 499752
        settings = repo.settings
Pierre-Yves Chibon 73d120
        settings["pull_request_access_only"] = True
Pierre-Yves Chibon 499752
        repo.settings = settings
Pierre-Yves Chibon 499752
        self.session.add(repo)
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        # Add an user to a project
Pierre-Yves Chibon 499752
        # The user will be an admin of the project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_user="foo", user="pingou"
Pierre-Yves Chibon 499752
        )
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Pierre-Yves Chibon 499752
        # Add a forked project
Pierre-Yves Chibon 499752
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 499752
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test3",
Pierre-Yves Chibon 73d120
            description="test project #2",
Pierre-Yves Chibon 499752
            is_fork=True,
Pierre-Yves Chibon 499752
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Pierre-Yves Chibon 499752
        )
Pierre-Yves Chibon 499752
        self.session.add(item)
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        with open(outputconf) as stream:
Pierre-Yves Chibon 499752
            data = stream.read()
Pierre-Yves Chibon 499752
Pierre-Yves Chibon ccb160
        exp = """repo docs/test
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
  RW+ = foo
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/test
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
  RW+ = foo
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/test
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
  RW+ = foo
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo test2
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo docs/test2
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/test2
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/test2
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo somenamespace/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo docs/somenamespace/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/somenamespace/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/somenamespace/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo forks/pingou/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo docs/forks/pingou/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/forks/pingou/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/forks/pingou/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 499752
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon 499752
        self.assertEqual(data, exp)
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        os.unlink(outputconf)
Pierre-Yves Chibon 499752
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"PR_ONLY": True})
Pierre-Yves Chibon 499752
    def test_write_gitolite_global_pr_only(self):
Pierre-Yves Chibon 499752
        """ Test the write_gitolite_acls function of pagure.lib.git.
Pierre-Yves Chibon 73f4b5
        when the pagure instance enforces the PR approach.
Pierre-Yves Chibon 499752
        """
Pierre-Yves Chibon 499752
        tests.create_projects(self.session)
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon 73d120
        self.assertFalse(repo.settings["pull_request_access_only"])
Pierre-Yves Chibon 897409
Pierre-Yves Chibon 499752
        # Add an user to a project
Pierre-Yves Chibon 499752
        # The user will be an admin of the project
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_user_to_project(
Pierre-Yves Chibon 73d120
            session=self.session, project=repo, new_user="foo", user="pingou"
Pierre-Yves Chibon 499752
        )
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "User added")
Pierre-Yves Chibon 499752
        # Add a forked project
Pierre-Yves Chibon 499752
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 499752
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test3",
Pierre-Yves Chibon 73d120
            description="test project #2",
Pierre-Yves Chibon 499752
            is_fork=True,
Pierre-Yves Chibon 499752
            parent_id=1,
Pierre-Yves Chibon 73d120
            hook_token="aaabbbvvv",
Pierre-Yves Chibon 499752
        )
Pierre-Yves Chibon 499752
        self.session.add(item)
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
        outputconf = os.path.join(self.path, "test_gitolite.conf")
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(self.session, outputconf, project=-1)
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        with open(outputconf) as stream:
Pierre-Yves Chibon 499752
            data = stream.read()
Pierre-Yves Chibon 499752
Pierre-Yves Chibon ccb160
        exp = """repo docs/test
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
  RW+ = foo
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/test
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
  RW+ = foo
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/test
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
  RW+ = foo
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo docs/test2
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/test2
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/test2
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo docs/somenamespace/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/somenamespace/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/somenamespace/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo forks/pingou/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo docs/forks/pingou/test3
Pierre-Yves Chibon 499752
  R   = @all
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo tickets/forks/pingou/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
repo requests/forks/pingou/test3
Pierre-Yves Chibon 499752
  RW+ = pingou
Pierre-Yves Chibon 499752
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 499752
"""
Pierre-Yves Chibon 73d120
        # print data
Pierre-Yves Chibon 499752
        self.assertEqual(data, exp)
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 499752
        os.unlink(outputconf)
Pierre-Yves Chibon 499752
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Patrick Uiterwijk b4c473
    def test_update_git(self, email_f):
Pierre-Yves Chibon fe5017
        """ Test the update_git of pagure.lib.git. """
Pierre-Yves Chibon c009bb
        email_f.return_value = True
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Create project
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon c009bb
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test_ticket_repo",
Pierre-Yves Chibon 73d120
            description="test project for ticket",
Pierre-Yves Chibon 73d120
            hook_token="aaabbbwww",
Pierre-Yves Chibon c009bb
        )
Pierre-Yves Chibon c009bb
        self.session.add(item)
Pierre-Yves Chibon c009bb
        self.session.commit()
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Create repo
Pierre-Yves Chibon 73d120
        self.gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "tickets", "test_ticket_repo.git"
Pierre-Yves Chibon 73d120
        )
Patrick Uiterwijk 170974
        pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test_ticket_repo"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c009bb
        # Create an issue to play with
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.new_issue(
Pierre-Yves Chibon c009bb
            session=self.session,
Pierre-Yves Chibon c009bb
            repo=repo,
Pierre-Yves Chibon 73d120
            title="Test issue",
Pierre-Yves Chibon 73d120
            content="We should work on this",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon c009bb
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(msg.title, "Test issue")
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
Patrick Uiterwijk 3f97f6
        pagure.lib.git.update_git(issue, repo).get()
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon 73d120
        commit = repo.revparse_single("HEAD")
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Use patch to validate the repo
Slavek Kabrda adea20
        commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
Karsten Hopp b310af
        exp = r"""Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon fe5017
From: pagure <pagure></pagure>
Pierre-Yves Chibon e64141
Subject: Updated issue <hash>: Test issue</hash>
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
---
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
diff --git a/123 b/456
Pierre-Yves Chibon c009bb
new file mode 100644
Pierre-Yves Chibon c009bb
index 0000000..60f7480
Pierre-Yves Chibon c009bb
--- /dev/null
Pierre-Yves Chibon c009bb
+++ b/456
Clement Verna 81c130
@@ -0,0 +1,29 @@
Pierre-Yves Chibon 2e900f
+{
Pierre-Yves Chibon 2e900f
+    "assignee": null,
Pierre-Yves Chibon 2e900f
+    "blocks": [],
Pierre-Yves Chibon a71f76
+    "close_status": null,
Vivek Anand d7285b
+    "closed_at": null,
Pierre-Yves Chibon 2e900f
+    "comments": [],
Pierre-Yves Chibon 2e900f
+    "content": "We should work on this",
Pierre-Yves Chibon 022564
+    "custom_fields": [],
Pierre-Yves Chibon 2e900f
+    "date_created": null,
Pierre-Yves Chibon 2e900f
+    "depends": [],
Pierre-Yves Chibon 2e900f
+    "id": 1,
Mark Reynolds 23b4d2
+    "last_updated": null,
Pierre-Yves Chibon 725fca
+    "milestone": null,
Pierre-Yves Chibon b5c8b4
+    "priority": null,
Pierre-Yves Chibon 2e900f
+    "private": false,
Pierre-Yves Chibon 2e900f
+    "status": "Open",
Pierre-Yves Chibon 2e900f
+    "tags": [],
Pierre-Yves Chibon 2e900f
+    "title": "Test issue",
Pierre-Yves Chibon 2e900f
+    "user": {
Pierre-Yves Chibon 2e900f
+        "default_email": "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+        "emails": [
Pierre-Yves Chibon 2e900f
+            "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+            "foo@pingou.com"
Pierre-Yves Chibon 2e900f
+        ],
Pierre-Yves Chibon 2e900f
+        "fullname": "PY C",
Pierre-Yves Chibon 2e900f
+        "name": "pingou"
Pierre-Yves Chibon 2e900f
+    }
Pierre-Yves Chibon 2e900f
+}
Pierre-Yves Chibon c009bb
\ No newline at end of file
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
"""
Pierre-Yves Chibon c009bb
        npatch = []
Pierre-Yves Chibon 73d120
        for row in commit_patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon c009bb
                continue
Pierre-Yves Chibon 73d120
            elif row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 73d120
            elif row.startswith("diff --git "):
Pierre-Yves Chibon 73d120
                row = row.split(" ")
Pierre-Yves Chibon 73d120
                row[2] = "a/123"
Pierre-Yves Chibon 73d120
                row[3] = "b/456"
Pierre-Yves Chibon 73d120
                row = " ".join(row)
Pierre-Yves Chibon 73d120
            elif "Updated issue" in row:
Pierre-Yves Chibon c009bb
                row = row.split()
Pierre-Yves Chibon 73d120
                row[3] = "<hash>:"</hash>
Pierre-Yves Chibon 73d120
                row = " ".join(row)
Pierre-Yves Chibon 73d120
            elif "date_created" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "last_updated" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "closed_at" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "closed_by" in row:
Clement Verna 81c130
                continue
Pierre-Yves Chibon 73d120
            elif row.startswith("index 00"):
Pierre-Yves Chibon 73d120
                row = "index 0000000..60f7480"
Pierre-Yves Chibon 73d120
            elif row.startswith("+++ b/"):
Pierre-Yves Chibon 73d120
                row = "+++ b/456"
Pierre-Yves Chibon c009bb
            npatch.append(row)
Pierre-Yves Chibon 73d120
        commit_patch = "\n".join(npatch)
Pierre-Yves Chibon 73d120
        # print commit_patch
Slavek Kabrda adea20
        self.assertEqual(commit_patch, exp)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon b63f28
        # Enforce having a different last_updated field
Pierre-Yves Chibon b63f28
        # This is required as the test run fine and fast with sqlite but is
Pierre-Yves Chibon b63f28
        # much slower with postgresql so we end-up with an updated
Pierre-Yves Chibon b63f28
        # last_updated in postgresql but not with sqlite
Pierre-Yves Chibon b63f28
        time.sleep(1)
Pierre-Yves Chibon b63f28
Pierre-Yves Chibon c009bb
        # Test again after adding a comment
Slavek Kabrda adea20
        # We need to make sure we wait for worker to commit the comment
Pierre-Yves Chibon 73d120
        with patch("pagure.lib.git._maybe_wait", tests.definitely_wait):
Pierre-Yves Chibon 930073
            msg = pagure.lib.query.add_issue_comment(
Slavek Kabrda adea20
                session=self.session,
Slavek Kabrda adea20
                issue=issue,
Pierre-Yves Chibon 73d120
                comment="Hey look a comment!",
Pierre-Yves Chibon 73d120
                user="foo",
Slavek Kabrda adea20
            )
Pierre-Yves Chibon c009bb
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Comment added")
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Use patch to validate the repo
Pierre-Yves Chibon c009bb
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon 73d120
        commit = repo.revparse_single("HEAD")
Slavek Kabrda adea20
        commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
Karsten Hopp b310af
        exp = r"""Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon fe5017
From: pagure <pagure></pagure>
Pierre-Yves Chibon e64141
Subject: Updated issue <hash>: Test issue</hash>
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
---
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
diff --git a/123 b/456
Pierre-Yves Chibon c009bb
index 458821a..77674a8
Pierre-Yves Chibon c009bb
--- a/123
Pierre-Yves Chibon c009bb
+++ b/456
Clement Verna 81c130
@@ -4,13 +4,32 @@
Pierre-Yves Chibon a71f76
     "close_status": null,
Vivek Anand d7285b
     "closed_at": null,
Pierre-Yves Chibon 2e900f
-    "comments": [],
Pierre-Yves Chibon 2e900f
+    "comments": [
Pierre-Yves Chibon 2e900f
+        {
Pierre-Yves Chibon 2e900f
+            "comment": "Hey look a comment!",
Pierre-Yves Chibon 2e900f
+            "date_created": null,
Pierre-Yves Chibon e64141
+            "edited_on": null,
Pierre-Yves Chibon e64141
+            "editor": null,
Pierre-Yves Chibon 2e900f
+            "id": 1,
Pierre-Yves Chibon bda7f1
+            "notification": false,
Pierre-Yves Chibon 2e900f
+            "parent": null,
LubomĂ­r SedlĂ¡Å™ 59889e
+            "reactions": {},
Pierre-Yves Chibon 2e900f
+            "user": {
Pierre-Yves Chibon 2e900f
+                "default_email": "foo@bar.com",
Pierre-Yves Chibon 2e900f
+                "emails": [
Pierre-Yves Chibon 2e900f
+                    "foo@bar.com"
Pierre-Yves Chibon 2e900f
+                ],
Pierre-Yves Chibon 2e900f
+                "fullname": "foo bar",
Pierre-Yves Chibon 2e900f
+                "name": "foo"
Pierre-Yves Chibon 2e900f
+            }
Pierre-Yves Chibon 2e900f
+        }
Pierre-Yves Chibon 2e900f
+    ],
Pierre-Yves Chibon 2e900f
     "content": "We should work on this",
Pierre-Yves Chibon e5e9eb
     "custom_fields": [],
Pierre-Yves Chibon 2e900f
     "date_created": null,
Pierre-Yves Chibon b63f28
     "depends": [],
Pierre-Yves Chibon b63f28
     "id": 1,
Pierre-Yves Chibon b63f28
-    "last_updated": "<date>",</date>
Pierre-Yves Chibon b63f28
+    "last_updated": "<date>",</date>
Pierre-Yves Chibon b63f28
     "milestone": null,
Pierre-Yves Chibon b63f28
     "priority": null,
Pierre-Yves Chibon b63f28
     "private": false,
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
"""
Pierre-Yves Chibon c009bb
        npatch = []
Pierre-Yves Chibon 73d120
        for row in commit_patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon c009bb
                continue
Pierre-Yves Chibon 73d120
            elif row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 73d120
            elif row.startswith("diff --git "):
Pierre-Yves Chibon 73d120
                row = row.split(" ")
Pierre-Yves Chibon 73d120
                row[2] = "a/123"
Pierre-Yves Chibon 73d120
                row[3] = "b/456"
Pierre-Yves Chibon 73d120
                row = " ".join(row)
Pierre-Yves Chibon 73d120
            elif "Updated issue" in row:
Pierre-Yves Chibon c009bb
                row = row.split()
Pierre-Yves Chibon 73d120
                row[3] = "<hash>:"</hash>
Pierre-Yves Chibon 73d120
                row = " ".join(row)
Pierre-Yves Chibon 73d120
            elif "date_created" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "closed_at" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "closed_by" in row:
Clement Verna 81c130
                continue
Pierre-Yves Chibon 73d120
            elif row.startswith("index"):
Pierre-Yves Chibon 73d120
                row = "index 458821a..77674a8"
Pierre-Yves Chibon 73d120
            elif row.startswith("--- a/"):
Pierre-Yves Chibon 73d120
                row = "--- a/123"
Pierre-Yves Chibon 73d120
            elif row.startswith("+++ b/"):
Pierre-Yves Chibon 73d120
                row = "+++ b/456"
Pierre-Yves Chibon 73d120
            elif "last_updated" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon b63f28
                row = '%s: "<date>",' % t</date>
Pierre-Yves Chibon c009bb
            npatch.append(row)
Pierre-Yves Chibon 73d120
        commit_patch = "\n".join(npatch)
Slavek Kabrda adea20
        # print commit_patch
Slavek Kabrda adea20
        self.assertEqual(commit_patch, exp)
Pierre-Yves Chibon c009bb
Patrick Uiterwijk b4c473
    def test_clean_git(self):
Pierre-Yves Chibon e88bd7
        """ Test the clean_git method of pagure.lib.git. """
Pierre-Yves Chibon e88bd7
        self.test_update_git()
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon 73d120
        gitpath = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "tickets", "test_ticket_repo.git"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon e88bd7
        gitrepo = pygit2.init_repository(gitpath, bare=True)
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon e88bd7
        # Get the uid of the ticket created
Pierre-Yves Chibon 73d120
        commit = gitrepo.revparse_single("HEAD")
Pierre-Yves Chibon e88bd7
        patch = pagure.lib.git.commit_to_patch(gitrepo, commit)
Pierre-Yves Chibon e88bd7
        hash_file = None
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("+++ b/"):
Pierre-Yves Chibon 73d120
                hash_file = row.split("+++ b/")[-1]
Pierre-Yves Chibon e88bd7
                break
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon e88bd7
        # The only file in git is the one of that ticket
Pierre-Yves Chibon e88bd7
        files = [entry.name for entry in commit.tree]
Pierre-Yves Chibon e88bd7
        self.assertEqual(files, [hash_file])
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test_ticket_repo"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
Patrick Uiterwijk 3f97f6
        pagure.lib.git.clean_git(repo, issue.repotype, issue.uid).get()
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon e88bd7
        # No more files in the git repo
Pierre-Yves Chibon 73d120
        commit = gitrepo.revparse_single("HEAD")
Pierre-Yves Chibon e88bd7
        files = [entry.name for entry in commit.tree]
Pierre-Yves Chibon e88bd7
        self.assertEqual(files, [])
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Patrick Uiterwijk b4c473
    def test_update_git_requests(self, email_f):
Pierre-Yves Chibon c070b4
        """ Test the update_git of pagure.lib.git for pull-requests. """
Pierre-Yves Chibon c070b4
        email_f.return_value = True
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        # Create project
Pierre-Yves Chibon c070b4
        item = pagure.lib.model.Project(
Pierre-Yves Chibon c070b4
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test_ticket_repo",
Pierre-Yves Chibon 73d120
            description="test project for ticket",
Pierre-Yves Chibon 73d120
            hook_token="aaabbbxxx",
Pierre-Yves Chibon c070b4
        )
Pierre-Yves Chibon c070b4
        self.session.add(item)
Pierre-Yves Chibon c070b4
        self.session.commit()
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        # Create repo
Pierre-Yves Chibon 73d120
        self.gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "requests", "test_ticket_repo.git"
Pierre-Yves Chibon 73d120
        )
Patrick Uiterwijk 170974
        pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon a3fe59
        # Create a PR to play with
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test_ticket_repo"
Pierre-Yves Chibon 73d120
        )
Farhaan Bukhsh 72e9db
        # Create an issue to play with
Pierre-Yves Chibon 930073
        req = pagure.lib.query.new_pull_request(
Pierre-Yves Chibon c070b4
            session=self.session,
Pierre-Yves Chibon c070b4
            repo_from=repo,
Pierre-Yves Chibon 73d120
            branch_from="feature",
Pierre-Yves Chibon c070b4
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="test PR",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            requestuid="foobar",
Pierre-Yves Chibon c070b4
            requestid=None,
Pierre-Yves Chibon 73d120
            status="Open",
Pierre-Yves Chibon 73d120
            notify=True,
Pierre-Yves Chibon c070b4
        )
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(req.title, "test PR")
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        request = repo.requests[0]
Pierre-Yves Chibon 73d120
        self.assertEqual(request.title, "test PR")
Patrick Uiterwijk 3f97f6
        pagure.lib.git.update_git(request, request.project).get()
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon 73d120
        commit = repo.revparse_single("HEAD")
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        # Use patch to validate the repo
Pierre-Yves Chibon c070b4
        patch = pagure.lib.git.commit_to_patch(repo, commit)
Karsten Hopp b310af
        exp = r"""Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon c070b4
From: pagure <pagure></pagure>
Pierre-Yves Chibon e64141
Subject: Updated pull-request <hash>: test PR</hash>
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
---
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
diff --git a/123 b/456
Pierre-Yves Chibon c070b4
new file mode 100644
Pierre-Yves Chibon c070b4
index 0000000..60f7480
Pierre-Yves Chibon c070b4
--- /dev/null
Pierre-Yves Chibon c070b4
+++ b/456
Pierre-Yves Chibon 31a638
@@ -0,0 +1,147 @@
Pierre-Yves Chibon 2e900f
+{
Pierre-Yves Chibon 2e900f
+    "assignee": null,
Pierre-Yves Chibon 2e900f
+    "branch": "master",
Pierre-Yves Chibon 2e900f
+    "branch_from": "feature",
Pierre-Yves Chibon f21734
+    "cached_merge_status": "unknown",
Pierre-Yves Chibon bf72a2
+    "closed_at": null,
Pierre-Yves Chibon 2e900f
+    "closed_by": null,
Pierre-Yves Chibon 2e900f
+    "comments": [],
Pierre-Yves Chibon 2e900f
+    "commit_start": null,
Pierre-Yves Chibon 2e900f
+    "commit_stop": null,
Pierre-Yves Chibon 2e900f
+    "date_created": null,
Pierre-Yves Chibon 2e900f
+    "id": 1,
Pierre-Yves Chibon 10ca8a
+    "initial_comment": null,
Mark Reynolds 23b4d2
+    "last_updated": null,
Pierre-Yves Chibon 2e900f
+    "project": {
Matt Prahl 6bf79a
+        "access_groups": {
Matt Prahl 6bf79a
+            "admin": [],
Matt Prahl 6bf79a
+            "commit": [],
Matt Prahl 6bf79a
+            "ticket": []
Matt Prahl 6bf79a
+        },
Matt Prahl 6bf79a
+        "access_users": {
Matt Prahl 6bf79a
+            "admin": [],
Matt Prahl 6bf79a
+            "commit": [],
Matt Prahl 6bf79a
+            "owner": [
Matt Prahl 6bf79a
+                "pingou"
Matt Prahl 6bf79a
+            ],
Matt Prahl 6bf79a
+            "ticket": []
Matt Prahl 6bf79a
+        },
Pierre-Yves Chibon f254bf
+        "close_status": [],
Pierre-Yves Chibon 022564
+        "custom_keys": [],
Pierre-Yves Chibon 2e900f
+        "date_created": null,
Clement Verna cd6e30
+        "date_modified": null,
Pierre-Yves Chibon 2e900f
+        "description": "test project for ticket",
Pierre-Yves Chibon c9e619
+        "fullname": "test_ticket_repo",
Pierre-Yves Chibon 2e900f
+        "id": 1,
Pierre-Yves Chibon f254bf
+        "milestones": {},
Pierre-Yves Chibon 2e900f
+        "name": "test_ticket_repo",
Pierre-Yves Chibon 733a9d
+        "namespace": null,
Pierre-Yves Chibon 2e900f
+        "parent": null,
Pierre-Yves Chibon 14bde2
+        "priorities": {},
Pierre-Yves Chibon 2e900f
+        "settings": {
Pierre-Yves Chibon 2e900f
+            "Enforce_signed-off_commits_in_pull-request": false,
Pierre-Yves Chibon 2e900f
+            "Minimum_score_to_merge_pull-request": -1,
Pierre-Yves Chibon 2e900f
+            "Only_assignee_can_merge_pull-request": false,
Pierre-Yves Chibon 2e900f
+            "Web-hooks": null,
Pierre-Yves Chibon 1709b9
+            "always_merge": false,
Pierre-Yves Chibon 98d023
+            "disable_non_fast-forward_merges": false,
Pierre-Yves Chibon 9d1556
+            "fedmsg_notifications": true,
Pierre-Yves Chibon 2e900f
+            "issue_tracker": true,
Pierre-Yves Chibon b59748
+            "issue_tracker_read_only": false,
Pierre-Yves Chibon d0e87d
+            "issues_default_to_private": false,
Pierre-Yves Chibon 4eda2c
+            "mqtt_notifications": true,
Pierre-Yves Chibon baaf54
+            "notify_on_commit_flag": false,
Pierre-Yves Chibon baaf54
+            "notify_on_pull-request_flag": false,
Pierre-Yves Chibon 3821e6
+            "open_metadata_access_to_all": false,
Pierre-Yves Chibon e994c4
+            "project_documentation": false,
Pierre-Yves Chibon 499752
+            "pull_request_access_only": false,
Pierre-Yves Chibon 960e1e
+            "pull_requests": true,
Slavek Kabrda c8fc0d
+            "stomp_notifications": true
Pierre-Yves Chibon 2e900f
+        },
Pierre-Yves Chibon a30916
+        "tags": [],
Pierre-Yves Chibon 421aa4
+        "url_path": "test_ticket_repo",
Pierre-Yves Chibon 2e900f
+        "user": {
Pierre-Yves Chibon 2e900f
+            "default_email": "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+            "emails": [
Pierre-Yves Chibon 2e900f
+                "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+                "foo@pingou.com"
Pierre-Yves Chibon 2e900f
+            ],
Pierre-Yves Chibon 2e900f
+            "fullname": "PY C",
Pierre-Yves Chibon 2e900f
+            "name": "pingou"
Pierre-Yves Chibon 2e900f
+        }
Pierre-Yves Chibon 2e900f
+    },
Pierre-Yves Chibon ee5445
+    "remote_git": null,
Pierre-Yves Chibon 2e900f
+    "repo_from": {
Matt Prahl 6bf79a
+        "access_groups": {
Matt Prahl 6bf79a
+            "admin": [],
Matt Prahl 6bf79a
+            "commit": [],
Matt Prahl 6bf79a
+            "ticket": []
Matt Prahl 6bf79a
+        },
Matt Prahl 6bf79a
+        "access_users": {
Matt Prahl 6bf79a
+            "admin": [],
Matt Prahl 6bf79a
+            "commit": [],
Matt Prahl 6bf79a
+            "owner": [
Matt Prahl 6bf79a
+                "pingou"
Matt Prahl 6bf79a
+            ],
Matt Prahl 6bf79a
+            "ticket": []
Matt Prahl 6bf79a
+        },
Pierre-Yves Chibon f254bf
+        "close_status": [],
Pierre-Yves Chibon 022564
+        "custom_keys": [],
Pierre-Yves Chibon 2e900f
+        "date_created": null,
Clement Verna cd6e30
+        "date_modified": null,
Pierre-Yves Chibon 2e900f
+        "description": "test project for ticket",
Pierre-Yves Chibon c9e619
+        "fullname": "test_ticket_repo",
Pierre-Yves Chibon 2e900f
+        "id": 1,
Pierre-Yves Chibon f254bf
+        "milestones": {},
Pierre-Yves Chibon 2e900f
+        "name": "test_ticket_repo",
Pierre-Yves Chibon 733a9d
+        "namespace": null,
Pierre-Yves Chibon 2e900f
+        "parent": null,
Pierre-Yves Chibon 14bde2
+        "priorities": {},
Pierre-Yves Chibon 2e900f
+        "settings": {
Pierre-Yves Chibon 2e900f
+            "Enforce_signed-off_commits_in_pull-request": false,
Pierre-Yves Chibon 2e900f
+            "Minimum_score_to_merge_pull-request": -1,
Pierre-Yves Chibon 2e900f
+            "Only_assignee_can_merge_pull-request": false,
Pierre-Yves Chibon 2e900f
+            "Web-hooks": null,
Pierre-Yves Chibon 1709b9
+            "always_merge": false,
Pierre-Yves Chibon 98d023
+            "disable_non_fast-forward_merges": false,
Pierre-Yves Chibon 9d1556
+            "fedmsg_notifications": true,
Pierre-Yves Chibon 2e900f
+            "issue_tracker": true,
Pierre-Yves Chibon b59748
+            "issue_tracker_read_only": false,
Pierre-Yves Chibon d0e87d
+            "issues_default_to_private": false,
Pierre-Yves Chibon 4eda2c
+            "mqtt_notifications": true,
Pierre-Yves Chibon baaf54
+            "notify_on_commit_flag": false,
Pierre-Yves Chibon baaf54
+            "notify_on_pull-request_flag": false,
Pierre-Yves Chibon 3821e6
+            "open_metadata_access_to_all": false,
Pierre-Yves Chibon e994c4
+            "project_documentation": false,
Pierre-Yves Chibon 499752
+            "pull_request_access_only": false,
Pierre-Yves Chibon 960e1e
+            "pull_requests": true,
Slavek Kabrda c8fc0d
+            "stomp_notifications": true
Pierre-Yves Chibon 2e900f
+        },
Pierre-Yves Chibon a30916
+        "tags": [],
Pierre-Yves Chibon 421aa4
+        "url_path": "test_ticket_repo",
Pierre-Yves Chibon 2e900f
+        "user": {
Pierre-Yves Chibon 2e900f
+            "default_email": "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+            "emails": [
Pierre-Yves Chibon 2e900f
+                "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+                "foo@pingou.com"
Pierre-Yves Chibon 2e900f
+            ],
Pierre-Yves Chibon 2e900f
+            "fullname": "PY C",
Pierre-Yves Chibon 2e900f
+            "name": "pingou"
Pierre-Yves Chibon 2e900f
+        }
Pierre-Yves Chibon 2e900f
+    },
Pierre-Yves Chibon 2e900f
+    "status": "Open",
Pierre-Yves Chibon 31a638
+    "tags": [],
Pierre-Yves Chibon 2233c1
+    "threshold_reached": null,
Pierre-Yves Chibon 2e900f
+    "title": "test PR",
Pierre-Yves Chibon 2e900f
+    "uid": "foobar",
Pierre-Yves Chibon 44258a
+    "updated_on": null,
Pierre-Yves Chibon 2e900f
+    "user": {
Pierre-Yves Chibon 2e900f
+        "default_email": "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+        "emails": [
Pierre-Yves Chibon 2e900f
+            "bar@pingou.com",
Pierre-Yves Chibon 2e900f
+            "foo@pingou.com"
Pierre-Yves Chibon 2e900f
+        ],
Pierre-Yves Chibon 2e900f
+        "fullname": "PY C",
Pierre-Yves Chibon 2e900f
+        "name": "pingou"
Pierre-Yves Chibon 2e900f
+    }
Pierre-Yves Chibon 2e900f
+}
Pierre-Yves Chibon c070b4
\ No newline at end of file
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
"""
Pierre-Yves Chibon c070b4
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon c070b4
                continue
Pierre-Yves Chibon 73d120
            elif row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 73d120
            elif row.startswith("diff --git "):
Pierre-Yves Chibon 73d120
                row = row.split(" ")
Pierre-Yves Chibon 73d120
                row[2] = "a/123"
Pierre-Yves Chibon 73d120
                row[3] = "b/456"
Pierre-Yves Chibon 73d120
                row = " ".join(row)
Pierre-Yves Chibon 73d120
            elif "Updated pull-request" in row:
Pierre-Yves Chibon c070b4
                row = row.split()
Pierre-Yves Chibon 73d120
                row[3] = "<hash>:"</hash>
Pierre-Yves Chibon 73d120
                row = " ".join(row)
Pierre-Yves Chibon 73d120
            elif "date_created" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "date_modified" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "last_updated" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif "updated_on" in row:
Pierre-Yves Chibon 73d120
                t = row.split(": ")[0]
Pierre-Yves Chibon 73d120
                row = "%s: null," % t
Pierre-Yves Chibon 73d120
            elif row.startswith("index 00"):
Pierre-Yves Chibon 73d120
                row = "index 0000000..60f7480"
Pierre-Yves Chibon 73d120
            elif row.startswith("+++ b/"):
Pierre-Yves Chibon 73d120
                row = "+++ b/456"
Pierre-Yves Chibon c070b4
            npatch.append(row)
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Aurélien Bompard 626417
        print(patch)
Pierre-Yves Chibon c070b4
        self.assertEqual(patch, exp)
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon 0a1494
    def test_update_ticket_from_git_no_priority(self):
Pierre-Yves Chibon 0a1494
        """ Test the update_ticket_from_git method from pagure.lib.git. """
Pierre-Yves Chibon 0a1494
        tests.create_projects(self.session)
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon 0a1494
        # Before
Pierre-Yves Chibon 0a1494
        self.assertEqual(len(repo.issues), 0)
Pierre-Yves Chibon 0a1494
        self.assertEqual(repo.issues, [])
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon 0a1494
        data = {
Pierre-Yves Chibon 73d120
            "status": "Open",
Pierre-Yves Chibon 73d120
            "title": "foo",
Pierre-Yves Chibon 73d120
            "comments": [],
Pierre-Yves Chibon 73d120
            "content": "bar",
Pierre-Yves Chibon 73d120
            "date_created": "1426500263",
Pierre-Yves Chibon 73d120
            "user": {"name": "pingou", "emails": ["pingou@fedoraproject.org"]},
Pierre-Yves Chibon 0a1494
            "milestone": "Next Release",
Pierre-Yves Chibon 0a1494
            "priority": 1,
Pierre-Yves Chibon 0a1494
        }
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon a3901b
        # Invalid project
Pierre-Yves Chibon 7a6733
        self.assertRaises(
Pierre-Yves Chibon 7a6733
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 7a6733
            pagure.lib.git.update_ticket_from_git,
Pierre-Yves Chibon 7a6733
            self.session,
Pierre-Yves Chibon 73d120
            reponame="foobar",
Pierre-Yves Chibon 7a6733
            namespace=None,
Pierre-Yves Chibon 7a6733
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon b7eec1
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 7a6733
        )
Pierre-Yves Chibon 7a6733
Pierre-Yves Chibon 46750b
        # Create the issue
Pierre-Yves Chibon 7a6733
        data = {
Pierre-Yves Chibon 73d120
            "status": "Open",
Pierre-Yves Chibon 73d120
            "title": "foo",
Pierre-Yves Chibon 73d120
            "comments": [],
Pierre-Yves Chibon 73d120
            "content": "bar",
Pierre-Yves Chibon 73d120
            "date_created": "1426500263",
Pierre-Yves Chibon 73d120
            "user": {"name": "pingou", "emails": ["pingou@fedoraproject.org"]},
Pierre-Yves Chibon 7a6733
            "milestone": "Next Release",
Pierre-Yves Chibon 7a6733
        }
Pierre-Yves Chibon 7a6733
Pierre-Yves Chibon 46750b
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 46750b
        )
Pierre-Yves Chibon 46750b
        self.session.commit()
Pierre-Yves Chibon 46750b
Pierre-Yves Chibon 46750b
        # Edit the issue
Pierre-Yves Chibon 7a6733
        data = {
Pierre-Yves Chibon 73d120
            "status": "Open",
Pierre-Yves Chibon 73d120
            "title": "foo",
Pierre-Yves Chibon 73d120
            "comments": [],
Pierre-Yves Chibon 73d120
            "content": "bar",
Pierre-Yves Chibon 73d120
            "date_created": "1426500263",
Pierre-Yves Chibon 73d120
            "user": {"name": "pingou", "emails": ["pingou@fedoraproject.org"]},
Pierre-Yves Chibon 7a6733
            "milestone": "Next Release",
Pierre-Yves Chibon 7a6733
            "priority": 1,
Pierre-Yves Chibon 7a6733
        }
Pierre-Yves Chibon 7a6733
Pierre-Yves Chibon 0a1494
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 0a1494
        )
Pierre-Yves Chibon 0a1494
        self.session.commit()
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon 0a1494
        # Data contained a priority but not the project, so bailing
Pierre-Yves Chibon 0a1494
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon 0a1494
        self.assertEqual(repo.issues[0].id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].uid, "foobar")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].title, "foo")
Pierre-Yves Chibon 0a1494
        self.assertEqual(repo.issues[0].depending_text, [])
Pierre-Yves Chibon 0a1494
        self.assertEqual(repo.issues[0].blocking_text, [])
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].milestone, "Next Release")
Pierre-Yves Chibon 0a1494
        self.assertEqual(repo.issues[0].priority, None)
Pierre-Yves Chibon 75b7f9
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.milestones, {"Next Release": {"active": True, "date": None}}
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
Pierre-Yves Chibon b7eec1
    def test_update_ticket_from_git_close_ticket(self):
Pierre-Yves Chibon b7eec1
        """ Test the update_ticket_from_git method from pagure.lib.git. """
Pierre-Yves Chibon b7eec1
        tests.create_projects(self.session)
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon b7eec1
        # Before
Pierre-Yves Chibon b7eec1
        self.assertEqual(len(repo.issues), 0)
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues, [])
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon b7eec1
        # Create the issue
Pierre-Yves Chibon b7eec1
        data = {
Pierre-Yves Chibon b7eec1
            "status": "Open",
Pierre-Yves Chibon b7eec1
            "title": "foo",
Pierre-Yves Chibon b7eec1
            "comments": [],
Pierre-Yves Chibon b7eec1
            "content": "bar",
Pierre-Yves Chibon b7eec1
            "date_created": "1426500263",
Pierre-Yves Chibon 73d120
            "user": {"name": "foo", "emails": ["foo@fedoraproject.org"]},
Pierre-Yves Chibon b7eec1
            "milestone": "Next Release",
Pierre-Yves Chibon b7eec1
        }
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon b7eec1
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon b7eec1
        )
Pierre-Yves Chibon b7eec1
        self.session.commit()
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon b7eec1
        # Edit the issue
Pierre-Yves Chibon b7eec1
        data = {
Pierre-Yves Chibon b7eec1
            "status": "Closed",
Pierre-Yves Chibon b7eec1
            "close_status": "Fixed",
Pierre-Yves Chibon b7eec1
            "title": "foo",
Pierre-Yves Chibon b7eec1
            "comments": [],
Pierre-Yves Chibon b7eec1
            "content": "bar",
Pierre-Yves Chibon b7eec1
            "date_created": "1426500263",
Pierre-Yves Chibon 73d120
            "user": {"name": "foo", "emails": ["foo@fedoraproject.org"]},
Pierre-Yves Chibon b7eec1
            "milestone": "Next Release",
Pierre-Yves Chibon b7eec1
        }
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon b7eec1
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon b7eec1
        )
Pierre-Yves Chibon b7eec1
        self.session.commit()
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon b7eec1
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues[0].id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].uid, "foobar")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].title, "foo")
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues[0].depending_text, [])
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues[0].blocking_text, [])
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].milestone, "Next Release")
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues[0].priority, None)
Pierre-Yves Chibon 75b7f9
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.milestones, {"Next Release": {"active": True, "date": None}}
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].status, "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].close_status, "Fixed")
Pierre-Yves Chibon 323e55
        self.assertIsNotNone(repo.issues[0].closed_at)
Pierre-Yves Chibon b7eec1
        self.assertEqual(
Pierre-Yves Chibon b7eec1
            repo.issues[0].comments[-1].comment,
Pierre-Yves Chibon 73d120
            "**Metadata Update from @pingou**:\n"
Pierre-Yves Chibon 73d120
            "- Issue close_status updated to: Fixed\n"
Pierre-Yves Chibon 73d120
            "- Issue status updated to: Closed (was: Open)",
Pierre-Yves Chibon b7eec1
        )
Pierre-Yves Chibon b7eec1
Pierre-Yves Chibon 2bf847
    def test_update_ticket_from_git(self):
Pierre-Yves Chibon fe5017
        """ Test the update_ticket_from_git method from pagure.lib.git. """
Pierre-Yves Chibon 2bf847
        tests.create_projects(self.session)
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 0a1494
        # Set some priorities to the project
Pierre-Yves Chibon 73d120
        repo.priorities = {"1": "High", "2": "Normal"}
Pierre-Yves Chibon 0a1494
        self.session.add(repo)
Pierre-Yves Chibon 0a1494
        self.session.commit()
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        # Before
Pierre-Yves Chibon 2bf847
        self.assertEqual(len(repo.issues), 0)
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues, [])
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        data = {
Pierre-Yves Chibon 73d120
            "status": "Open",
Pierre-Yves Chibon 73d120
            "title": "foo",
Pierre-Yves Chibon 73d120
            "comments": [],
Pierre-Yves Chibon 73d120
            "content": "bar",
Pierre-Yves Chibon 73d120
            "date_created": "1426500263",
Pierre-Yves Chibon 73d120
            "user": {"name": "pingou", "emails": ["pingou@fedoraproject.org"]},
Clement Verna b30f33
            "milestone": "Next Release",
Mark Reynolds 7974f7
            "priority": 1,
Pierre-Yves Chibon 2bf847
        }
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.git.update_ticket_from_git,
Pierre-Yves Chibon 2bf847
            self.session,
Pierre-Yves Chibon 73d120
            reponame="foobar",
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon 2bf847
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon b7eec1
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 2bf847
        )
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 2bf847
        )
Pierre-Yves Chibon 2bf847
        self.session.commit()
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        # After 1 insertion
Pierre-Yves Chibon 2bf847
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[0].id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].uid, "foobar")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].title, "foo")
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[0].depending_text, [])
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[0].blocking_text, [])
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].milestone, "Next Release")
Mark Reynolds 7974f7
        self.assertEqual(repo.issues[0].priority, 1)
Pierre-Yves Chibon 323e55
        self.assertIsNone(repo.issues[0].closed_at)
Pierre-Yves Chibon 75b7f9
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.milestones, {"Next Release": {"active": True, "date": None}}
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        data["title"] = "fake issue for tests"
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 2bf847
        )
Pierre-Yves Chibon 2bf847
        self.session.commit()
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        # After edit
Pierre-Yves Chibon 2bf847
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[0].id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].uid, "foobar")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].title, "fake issue for tests")
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[0].depending_text, [])
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[0].blocking_text, [])
Mark Reynolds 7974f7
        self.assertEqual(repo.issues[0].priority, 1)
Pierre-Yves Chibon 323e55
        self.assertIsNone(repo.issues[0].closed_at)
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        data = {
Pierre-Yves Chibon 73d120
            "status": "Open",
Pierre-Yves Chibon 73d120
            "title": "Rename pagure",
Pierre-Yves Chibon 73d120
            "private": False,
Pierre-Yves Chibon 2bf847
            "content": "This is too much of a conflict with the book",
Pierre-Yves Chibon 2bf847
            "user": {
Pierre-Yves Chibon ec853d
                "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon ec853d
                "name": "pingou",
Pierre-Yves Chibon ec853d
                "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon 2bf847
            },
Pierre-Yves Chibon 2bf847
            "id": 20,
Pierre-Yves Chibon 2bf847
            "blocks": [1],
Pierre-Yves Chibon 2bf847
            "depends": [3, 4],
Pierre-Yves Chibon 2bf847
            "date_created": "1426595224",
Clement Verna b30f33
            "milestone": "Future",
Mark Reynolds 7974f7
            "priority": 1,
Pierre-Yves Chibon 2bf847
            "comments": [
Pierre-Yves Chibon 2bf847
                {
Pierre-Yves Chibon 2bf847
                    "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
Pierre-Yves Chibon 2bf847
                    "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
Pierre-Yves Chibon 2bf847
                    "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
Pierre-Yves Chibon 2bf847
                    "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
Aurélien Bompard 626417
                    "COLLABORATRON5000\r\n- git-sm\\u00f6rg\\u00e5sbord\r\n- "
Pierre-Yves Chibon 2bf847
                    "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
Pierre-Yves Chibon 2bf847
                    "gitsundheit",
Pierre-Yves Chibon 73d120
                    "date_created": "1426595224",
Pierre-Yves Chibon 73d120
                    "id": 250,
Pierre-Yves Chibon 73d120
                    "parent": None,
Pierre-Yves Chibon 2bf847
                    "user": {
Pierre-Yves Chibon 2bf847
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 2bf847
                        "name": "pingou",
Pierre-Yves Chibon ec853d
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon 73d120
                    },
Pierre-Yves Chibon 2bf847
                },
Pierre-Yves Chibon 2bf847
                {
Pierre-Yves Chibon 2bf847
                    "comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
Pierre-Yves Chibon 2bf847
                    "gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
Pierre-Yves Chibon 2bf847
                    "gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
Pierre-Yves Chibon 2bf847
                    "cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
Aurélien Bompard 626417
                    "COLLABORATRON5000\r\n- git-sm\\u00f6rg\\u00e5sbord\r\n- "
Pierre-Yves Chibon 2bf847
                    "thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
Pierre-Yves Chibon 2bf847
                    "gitsundheit",
Pierre-Yves Chibon 73d120
                    "date_created": "1426595340",
Pierre-Yves Chibon 73d120
                    "id": 324,
Pierre-Yves Chibon 73d120
                    "parent": None,
Pierre-Yves Chibon 2bf847
                    "user": {
Pierre-Yves Chibon 2bf847
                        "fullname": "Ralph Bean",
Pierre-Yves Chibon 2bf847
                        "name": "ralph",
Pierre-Yves Chibon ec853d
                        "default_email": "ralph@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["ralph@fedoraproject.org"],
Pierre-Yves Chibon 73d120
                    },
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
            ],
Pierre-Yves Chibon 2bf847
        }
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 73d120
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 73d120
            namespace=None,
Pierre-Yves Chibon 73d120
            username=None,
Pierre-Yves Chibon 73d120
            issue_uid="foobar2",
Pierre-Yves Chibon 73d120
            json_data=data,
Pierre-Yves Chibon 73d120
            agent="pingou",
Pierre-Yves Chibon 2bf847
        )
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon 2bf847
        # After second insertion
Pierre-Yves Chibon 2bf847
        self.assertEqual(len(repo.issues), 2)
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].uid, "foobar")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[0].title, "fake issue for tests")
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[0].depending_text, [20])
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[0].blocking_text, [])
Pierre-Yves Chibon 323e55
        self.assertIsNone(repo.issues[0].closed_at)
Pierre-Yves Chibon 2bf847
        # New one
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[1].uid, "foobar2")
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[1].title, "Rename pagure")
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[1].depending_text, [])
Pierre-Yves Chibon 215f54
        self.assertEqual(repo.issues[1].blocking_text, [1])
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.issues[1].milestone, "Future")
Pierre-Yves Chibon 323e55
        self.assertIsNone(repo.issues[1].closed_at)
Aurélien Bompard f61bb3
        self.assertDictEqual(
Pierre-Yves Chibon 75b7f9
            repo.milestones,
Pierre-Yves Chibon 75b7f9
            {
Pierre-Yves Chibon 73d120
                "Future": {"active": True, "date": None},
Pierre-Yves Chibon 73d120
                "Next Release": {"active": True, "date": None},
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon 75b7f9
        )
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon f692f5
    def test_update_request_from_git(self):
Pierre-Yves Chibon fe5017
        """ Test the update_request_from_git method from pagure.lib.git. """
Pierre-Yves Chibon f692f5
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"))
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon 73d120
        namespaced_repo = pagure.lib.query._get_project(
Pierre-Yves Chibon 73d120
            self.session, "test3", namespace="somenamespace"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon f692f5
        # Before
Pierre-Yves Chibon f692f5
        self.assertEqual(len(repo.requests), 0)
Pierre-Yves Chibon f692f5
        self.assertEqual(repo.requests, [])
clime afed57
        self.assertEqual(len(namespaced_repo.requests), 0)
clime afed57
        self.assertEqual(namespaced_repo.requests, [])
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon f692f5
        data = {
Pierre-Yves Chibon f692f5
            "status": True,
Pierre-Yves Chibon f692f5
            "uid": "d4182a2ac2d541d884742d3037c26e56",
Pierre-Yves Chibon 4dd52c
            "project": {
Pierre-Yves Chibon 022564
                "custom_keys": [],
Pierre-Yves Chibon f692f5
                "parent": None,
Pierre-Yves Chibon 719bdd
                "settings": {
Pierre-Yves Chibon 719bdd
                    "issue_tracker": True,
Pierre-Yves Chibon 719bdd
                    "project_documentation": True,
Pierre-Yves Chibon 719bdd
                    "pull_requests": True,
Pierre-Yves Chibon 719bdd
                },
Pierre-Yves Chibon f692f5
                "name": "test",
Pierre-Yves Chibon f692f5
                "date_created": "1426500194",
Pierre-Yves Chibon a30916
                "tags": [],
Pierre-Yves Chibon f692f5
                "user": {
Pierre-Yves Chibon 700d02
                    "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 700d02
                    "name": "pingou",
Pierre-Yves Chibon 700d02
                    "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                "id": 1,
Pierre-Yves Chibon 73d120
                "description": "test project",
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
Pierre-Yves Chibon f692f5
            "user": {
Pierre-Yves Chibon f692f5
                "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon f692f5
                "name": "pingou",
Pierre-Yves Chibon ec853d
                "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "id": 7,
Pierre-Yves Chibon f692f5
            "comments": [
Pierre-Yves Chibon f692f5
                {
Pierre-Yves Chibon f692f5
                    "comment": "really?",
Pierre-Yves Chibon f692f5
                    "user": {
Pierre-Yves Chibon f692f5
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon f692f5
                        "name": "pingou",
Pierre-Yves Chibon ec853d
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                    },
Pierre-Yves Chibon f692f5
                    "parent": None,
Pierre-Yves Chibon f692f5
                    "date_created": "1426843778",
Pierre-Yves Chibon f692f5
                    "commit": "fa72f315373ec5f98f2b08c8ffae3645c97aaad2",
Pierre-Yves Chibon f692f5
                    "line": 5,
Pierre-Yves Chibon f692f5
                    "id": 1,
Pierre-Yves Chibon 73d120
                    "filename": "test",
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                {
Pierre-Yves Chibon f692f5
                    "comment": "Again ?",
Pierre-Yves Chibon f692f5
                    "user": {
Pierre-Yves Chibon f692f5
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon f692f5
                        "name": "pingou",
Pierre-Yves Chibon ec853d
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                    },
Pierre-Yves Chibon f692f5
                    "parent": None,
Pierre-Yves Chibon f692f5
                    "date_created": "1426866781",
Pierre-Yves Chibon f692f5
                    "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
Pierre-Yves Chibon f692f5
                    "line": 5,
Pierre-Yves Chibon f692f5
                    "id": 2,
Pierre-Yves Chibon 73d120
                    "filename": "test2",
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                {
Pierre-Yves Chibon f692f5
                    "comment": "Should be fine in fact",
Pierre-Yves Chibon f692f5
                    "user": {
Pierre-Yves Chibon f692f5
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon f692f5
                        "name": "pingou",
Pierre-Yves Chibon ec853d
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                    },
Pierre-Yves Chibon f692f5
                    "parent": None,
Pierre-Yves Chibon f692f5
                    "date_created": "1426866950",
Pierre-Yves Chibon f692f5
                    "commit": "94ebaf900161394059478fd88aec30e59092a1d7",
Pierre-Yves Chibon f692f5
                    "line": 5,
Pierre-Yves Chibon f692f5
                    "id": 3,
Pierre-Yves Chibon 73d120
                    "filename": "test2",
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon f692f5
            ],
Pierre-Yves Chibon f692f5
            "branch_from": "master",
Pierre-Yves Chibon f692f5
            "title": "test request",
Pierre-Yves Chibon f692f5
            "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
Pierre-Yves Chibon f692f5
            "repo_from": {
Pierre-Yves Chibon f692f5
                "parent": {
Pierre-Yves Chibon 022564
                    "custom_keys": [],
Pierre-Yves Chibon f692f5
                    "parent": None,
Pierre-Yves Chibon f692f5
                    "name": "test",
Pierre-Yves Chibon f692f5
                    "date_created": "1426500194",
Pierre-Yves Chibon a30916
                    "tags": [],
Pierre-Yves Chibon f692f5
                    "user": {
Pierre-Yves Chibon 700d02
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 700d02
                        "name": "pingou",
Pierre-Yves Chibon 700d02
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                    },
Pierre-Yves Chibon 719bdd
                    "settings": {
Pierre-Yves Chibon 719bdd
                        "issue_tracker": True,
Pierre-Yves Chibon 719bdd
                        "project_documentation": True,
Pierre-Yves Chibon 719bdd
                        "pull_requests": True,
Pierre-Yves Chibon 719bdd
                    },
Pierre-Yves Chibon f692f5
                    "id": 1,
Pierre-Yves Chibon 73d120
                    "description": "test project",
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon 719bdd
                "settings": {
Pierre-Yves Chibon 719bdd
                    "issue_tracker": True,
Pierre-Yves Chibon 719bdd
                    "project_documentation": True,
Pierre-Yves Chibon 719bdd
                    "pull_requests": True,
Pierre-Yves Chibon 719bdd
                },
Pierre-Yves Chibon f692f5
                "name": "test",
Pierre-Yves Chibon f692f5
                "date_created": "1426843440",
Pierre-Yves Chibon 022564
                "custom_keys": [],
Pierre-Yves Chibon a30916
                "tags": [],
Pierre-Yves Chibon f692f5
                "user": {
Pierre-Yves Chibon 700d02
                    "fullname": "fake user",
Pierre-Yves Chibon 700d02
                    "name": "fake",
Pierre-Yves Chibon 700d02
                    "default_email": "fake@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["fake@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                "id": 6,
Pierre-Yves Chibon 73d120
                "description": "test project",
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "branch": "master",
Pierre-Yves Chibon 73d120
            "date_created": "1426843732",
Pierre-Yves Chibon f692f5
        }
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon f692f5
        self.assertRaises(
Pierre-Yves Chibon fe5017
            pagure.exceptions.PagureException,
Pierre-Yves Chibon fe5017
            pagure.lib.git.update_request_from_git,
Pierre-Yves Chibon f692f5
            self.session,
Pierre-Yves Chibon 73d120
            reponame="foobar",
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon f692f5
            username=None,
Pierre-Yves Chibon 73d120
            request_uid="d4182a2ac2d541d884742d3037c26e56",
Pierre-Yves Chibon f692f5
            json_data=data,
Pierre-Yves Chibon f692f5
        )
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_request_from_git(
Pierre-Yves Chibon f692f5
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon f692f5
            username=None,
Pierre-Yves Chibon 73d120
            request_uid="d4182a2ac2d541d884742d3037c26e56",
Pierre-Yves Chibon f692f5
            json_data=data,
Pierre-Yves Chibon f692f5
        )
Pierre-Yves Chibon f692f5
        self.session.commit()
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon f692f5
        # After 1 st insertion
Pierre-Yves Chibon f692f5
        self.assertEqual(len(repo.requests), 1)
Pierre-Yves Chibon f692f5
        self.assertEqual(repo.requests[0].id, 7)
Pierre-Yves Chibon f692f5
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e56"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.requests[0].title, "test request")
Pierre-Yves Chibon f692f5
        self.assertEqual(len(repo.requests[0].comments), 3)
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon f692f5
        data = {
Pierre-Yves Chibon f692f5
            "status": True,
Pierre-Yves Chibon f692f5
            "uid": "d4182a2ac2d541d884742d3037c26e57",
Pierre-Yves Chibon 4dd52c
            "project": {
Pierre-Yves Chibon f692f5
                "parent": None,
Pierre-Yves Chibon f692f5
                "name": "test",
Pierre-Yves Chibon 022564
                "custom_keys": [],
Pierre-Yves Chibon f692f5
                "date_created": "1426500194",
Pierre-Yves Chibon a30916
                "tags": [],
Pierre-Yves Chibon f692f5
                "user": {
Pierre-Yves Chibon 700d02
                    "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 700d02
                    "name": "pingou",
Pierre-Yves Chibon 700d02
                    "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon 719bdd
                "settings": {
Pierre-Yves Chibon 719bdd
                    "issue_tracker": True,
Pierre-Yves Chibon 719bdd
                    "project_documentation": True,
Pierre-Yves Chibon 719bdd
                    "pull_requests": True,
Pierre-Yves Chibon 719bdd
                },
Pierre-Yves Chibon f692f5
                "id": 1,
Pierre-Yves Chibon 73d120
                "description": "test project",
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
Pierre-Yves Chibon f692f5
            "user": {
Pierre-Yves Chibon f692f5
                "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon f692f5
                "name": "pingou",
Pierre-Yves Chibon ec853d
                "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "id": 4,
Pierre-Yves Chibon f692f5
            "comments": [],
Pierre-Yves Chibon f692f5
            "branch_from": "master",
Pierre-Yves Chibon f692f5
            "title": "test request #2",
Pierre-Yves Chibon f692f5
            "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
Pierre-Yves Chibon f692f5
            "repo_from": {
Pierre-Yves Chibon f692f5
                "parent": {
Pierre-Yves Chibon f692f5
                    "parent": None,
Pierre-Yves Chibon f692f5
                    "name": "test",
Pierre-Yves Chibon 022564
                    "custom_keys": [],
Pierre-Yves Chibon f692f5
                    "date_created": "1426500194",
Pierre-Yves Chibon a30916
                    "tags": [],
Pierre-Yves Chibon f692f5
                    "user": {
Pierre-Yves Chibon 700d02
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 700d02
                        "name": "pingou",
Pierre-Yves Chibon 700d02
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                    },
Pierre-Yves Chibon 719bdd
                    "settings": {
Pierre-Yves Chibon 719bdd
                        "issue_tracker": True,
Pierre-Yves Chibon 719bdd
                        "project_documentation": True,
Pierre-Yves Chibon 719bdd
                        "pull_requests": True,
Pierre-Yves Chibon 719bdd
                    },
Pierre-Yves Chibon f692f5
                    "id": 1,
Pierre-Yves Chibon 73d120
                    "description": "test project",
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon 719bdd
                "settings": {
Pierre-Yves Chibon 719bdd
                    "issue_tracker": True,
Pierre-Yves Chibon 719bdd
                    "project_documentation": True,
Pierre-Yves Chibon 719bdd
                    "pull_requests": True,
Pierre-Yves Chibon 719bdd
                },
Pierre-Yves Chibon f692f5
                "name": "test",
Pierre-Yves Chibon f692f5
                "date_created": "1426843440",
Pierre-Yves Chibon 022564
                "custom_keys": [],
Pierre-Yves Chibon a30916
                "tags": [],
Pierre-Yves Chibon f692f5
                "user": {
Pierre-Yves Chibon 700d02
                    "fullname": "fake user",
Pierre-Yves Chibon 700d02
                    "name": "fake",
Pierre-Yves Chibon 700d02
                    "default_email": "fake@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["fake@fedoraproject.org"],
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                "project_docs": True,
Pierre-Yves Chibon f692f5
                "id": 6,
Pierre-Yves Chibon 73d120
                "description": "test project",
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "branch": "master",
Pierre-Yves Chibon 73d120
            "date_created": "1426843745",
Pierre-Yves Chibon f692f5
        }
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_request_from_git(
Pierre-Yves Chibon f692f5
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon f692f5
            username=None,
Pierre-Yves Chibon 73d120
            request_uid="d4182a2ac2d541d884742d3037c26e57",
Pierre-Yves Chibon f692f5
            json_data=data,
Pierre-Yves Chibon f692f5
        )
Pierre-Yves Chibon f692f5
        self.session.commit()
Pierre-Yves Chibon f692f5
Pierre-Yves Chibon f692f5
        # After 2 nd insertion
Pierre-Yves Chibon f692f5
        self.assertEqual(len(repo.requests), 2)
Pierre-Yves Chibon f692f5
        self.assertEqual(repo.requests[0].id, 7)
Pierre-Yves Chibon f692f5
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e56"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.requests[0].title, "test request")
Pierre-Yves Chibon f692f5
        self.assertEqual(len(repo.requests[0].comments), 3)
Pierre-Yves Chibon f692f5
        # 2 entry
Pierre-Yves Chibon f692f5
        self.assertEqual(repo.requests[1].id, 4)
Pierre-Yves Chibon f692f5
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.requests[1].uid, "d4182a2ac2d541d884742d3037c26e57"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.requests[1].title, "test request #2")
Pierre-Yves Chibon f692f5
        self.assertEqual(len(repo.requests[1].comments), 0)
Pierre-Yves Chibon f692f5
clime afed57
        data = {
clime afed57
            "status": True,
clime afed57
            "uid": "d4182a2ac2d541d884742d3037c26e58",
clime afed57
            "project": {
clime afed57
                "parent": None,
clime afed57
                "name": "test3",
clime afed57
                "custom_keys": [],
clime afed57
                "namespace": "somenamespace",
clime afed57
                "date_created": "1426500194",
clime afed57
                "tags": [],
clime afed57
                "user": {
clime afed57
                    "fullname": "Pierre-YvesChibon",
clime afed57
                    "name": "pingou",
clime afed57
                    "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["pingou@fedoraproject.org"],
clime afed57
                },
clime afed57
                "settings": {
clime afed57
                    "issue_tracker": True,
clime afed57
                    "project_documentation": True,
clime afed57
                    "pull_requests": True,
clime afed57
                },
clime afed57
                "id": 3,
Pierre-Yves Chibon 73d120
                "description": "namespaced test project",
clime afed57
            },
clime afed57
            "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
clime afed57
            "user": {
clime afed57
                "fullname": "Pierre-YvesChibon",
clime afed57
                "name": "pingou",
clime afed57
                "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                "emails": ["pingou@fedoraproject.org"],
clime afed57
            },
clime afed57
            "id": 5,
clime afed57
            "comments": [],
clime afed57
            "branch_from": "master",
clime afed57
            "title": "test request to namespaced repo",
clime afed57
            "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
clime afed57
            "repo_from": {
clime afed57
                "parent": {
clime afed57
                    "parent": None,
clime afed57
                    "name": "test",
clime afed57
                    "custom_keys": [],
clime afed57
                    "date_created": "1426500194",
clime afed57
                    "tags": [],
clime afed57
                    "user": {
clime afed57
                        "fullname": "Pierre-YvesChibon",
clime afed57
                        "name": "pingou",
clime afed57
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
clime afed57
                    },
clime afed57
                    "settings": {
clime afed57
                        "issue_tracker": True,
clime afed57
                        "project_documentation": True,
clime afed57
                        "pull_requests": True,
clime afed57
                    },
clime afed57
                    "id": 1,
Pierre-Yves Chibon 73d120
                    "description": "test project",
clime afed57
                },
clime afed57
                "settings": {
clime afed57
                    "issue_tracker": True,
clime afed57
                    "project_documentation": True,
clime afed57
                    "pull_requests": True,
clime afed57
                },
clime afed57
                "name": "test",
clime afed57
                "date_created": "1426843440",
clime afed57
                "custom_keys": [],
clime afed57
                "tags": [],
clime afed57
                "user": {
clime afed57
                    "fullname": "fake user",
clime afed57
                    "name": "fake",
clime afed57
                    "default_email": "fake@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["fake@fedoraproject.org"],
clime afed57
                },
clime afed57
                "project_docs": True,
clime afed57
                "id": 6,
Pierre-Yves Chibon 73d120
                "description": "test project",
clime afed57
            },
clime afed57
            "branch": "master",
Pierre-Yves Chibon 73d120
            "date_created": "1426843745",
clime afed57
        }
clime afed57
        pagure.lib.git.update_request_from_git(
clime afed57
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test3",
Pierre-Yves Chibon 73d120
            namespace="somenamespace",
clime afed57
            username=None,
Pierre-Yves Chibon 73d120
            request_uid="d4182a2ac2d541d884742d3037c26e58",
clime afed57
            json_data=data,
clime afed57
        )
clime afed57
        self.session.commit()
clime afed57
clime afed57
        self.assertEqual(len(namespaced_repo.requests), 1)
clime afed57
        self.assertEqual(namespaced_repo.requests[0].id, 5)
clime afed57
        self.assertEqual(
Pierre-Yves Chibon 73d120
            namespaced_repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e58"
clime afed57
        )
clime afed57
        self.assertEqual(
clime afed57
            namespaced_repo.requests[0].title,
Pierre-Yves Chibon 73d120
            "test request to namespaced repo",
clime afed57
        )
clime afed57
Pierre-Yves Chibon 31a638
    def test_update_request_from_git(self):
Pierre-Yves Chibon 31a638
        """ Test the update_request_from_git method from pagure.lib.git. """
Pierre-Yves Chibon 31a638
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"))
Pierre-Yves Chibon 31a638
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon 73d120
        namespaced_repo = pagure.lib.query._get_project(
Pierre-Yves Chibon 73d120
            self.session, "test3", namespace="somenamespace"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 31a638
Pierre-Yves Chibon 31a638
        # Before
Pierre-Yves Chibon 31a638
        self.assertEqual(len(repo.requests), 0)
Pierre-Yves Chibon 31a638
        self.assertEqual(repo.requests, [])
Pierre-Yves Chibon 31a638
        self.assertEqual(len(namespaced_repo.requests), 0)
Pierre-Yves Chibon 31a638
        self.assertEqual(namespaced_repo.requests, [])
Pierre-Yves Chibon 31a638
Pierre-Yves Chibon 31a638
        data = {
Pierre-Yves Chibon 31a638
            "status": True,
Pierre-Yves Chibon 31a638
            "uid": "d4182a2ac2d541d884742d3037c26e57",
Pierre-Yves Chibon 31a638
            "project": {
Pierre-Yves Chibon 31a638
                "parent": None,
Pierre-Yves Chibon 31a638
                "name": "test",
Pierre-Yves Chibon 31a638
                "custom_keys": [],
Pierre-Yves Chibon 31a638
                "date_created": "1426500194",
Pierre-Yves Chibon 31a638
                "tags": [],
Pierre-Yves Chibon 31a638
                "user": {
Pierre-Yves Chibon 31a638
                    "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 31a638
                    "name": "pingou",
Pierre-Yves Chibon 31a638
                    "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon 31a638
                },
Pierre-Yves Chibon 31a638
                "settings": {
Pierre-Yves Chibon 31a638
                    "issue_tracker": True,
Pierre-Yves Chibon 31a638
                    "project_documentation": True,
Pierre-Yves Chibon 31a638
                    "pull_requests": True,
Pierre-Yves Chibon 31a638
                },
Pierre-Yves Chibon 31a638
                "id": 1,
Pierre-Yves Chibon 73d120
                "description": "test project",
Pierre-Yves Chibon 31a638
            },
Pierre-Yves Chibon 31a638
            "commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
Pierre-Yves Chibon 31a638
            "user": {
Pierre-Yves Chibon 31a638
                "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 31a638
                "name": "pingou",
Pierre-Yves Chibon 31a638
                "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon 31a638
            },
Pierre-Yves Chibon 31a638
            "id": 4,
Pierre-Yves Chibon 31a638
            "comments": [],
Pierre-Yves Chibon 31a638
            "branch_from": "master",
Pierre-Yves Chibon 31a638
            "title": "test request #2",
Pierre-Yves Chibon 31a638
            "commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
Pierre-Yves Chibon 31a638
            "repo_from": {
Pierre-Yves Chibon 31a638
                "parent": {
Pierre-Yves Chibon 31a638
                    "parent": None,
Pierre-Yves Chibon 31a638
                    "name": "test",
Pierre-Yves Chibon 31a638
                    "custom_keys": [],
Pierre-Yves Chibon 31a638
                    "date_created": "1426500194",
Pierre-Yves Chibon 31a638
                    "tags": [],
Pierre-Yves Chibon 31a638
                    "user": {
Pierre-Yves Chibon 31a638
                        "fullname": "Pierre-YvesChibon",
Pierre-Yves Chibon 31a638
                        "name": "pingou",
Pierre-Yves Chibon 31a638
                        "default_email": "pingou@fedoraproject.org",
Pierre-Yves Chibon 73d120
                        "emails": ["pingou@fedoraproject.org"],
Pierre-Yves Chibon 31a638
                    },
Pierre-Yves Chibon 31a638
                    "settings": {
Pierre-Yves Chibon 31a638
                        "issue_tracker": True,
Pierre-Yves Chibon 31a638
                        "project_documentation": True,
Pierre-Yves Chibon 31a638
                        "pull_requests": True,
Pierre-Yves Chibon 31a638
                    },
Pierre-Yves Chibon 31a638
                    "id": 1,
Pierre-Yves Chibon 73d120
                    "description": "test project",
Pierre-Yves Chibon 31a638
                },
Pierre-Yves Chibon 31a638
                "settings": {
Pierre-Yves Chibon 31a638
                    "issue_tracker": True,
Pierre-Yves Chibon 31a638
                    "project_documentation": True,
Pierre-Yves Chibon 31a638
                    "pull_requests": True,
Pierre-Yves Chibon 31a638
                },
Pierre-Yves Chibon 31a638
                "name": "test",
Pierre-Yves Chibon 31a638
                "date_created": "1426843440",
Pierre-Yves Chibon 31a638
                "custom_keys": [],
Pierre-Yves Chibon 31a638
                "tags": [],
Pierre-Yves Chibon 31a638
                "user": {
Pierre-Yves Chibon 31a638
                    "fullname": "fake user",
Pierre-Yves Chibon 31a638
                    "name": "fake",
Pierre-Yves Chibon 31a638
                    "default_email": "fake@fedoraproject.org",
Pierre-Yves Chibon 73d120
                    "emails": ["fake@fedoraproject.org"],
Pierre-Yves Chibon 31a638
                },
Pierre-Yves Chibon 31a638
                "project_docs": True,
Pierre-Yves Chibon 31a638
                "id": 6,
Pierre-Yves Chibon 73d120
                "description": "test project",
Pierre-Yves Chibon 31a638
            },
Pierre-Yves Chibon 31a638
            "branch": "master",
Pierre-Yves Chibon 31a638
            "date_created": "1426843745",
Pierre-Yves Chibon 31a638
            "tags": ["WIP", "core"],
Pierre-Yves Chibon 31a638
        }
Pierre-Yves Chibon 31a638
Pierre-Yves Chibon 31a638
        pagure.lib.git.update_request_from_git(
Pierre-Yves Chibon 31a638
            self.session,
Pierre-Yves Chibon 73d120
            reponame="test",
Pierre-Yves Chibon 31a638
            namespace=None,
Pierre-Yves Chibon 31a638
            username=None,
Pierre-Yves Chibon 73d120
            request_uid="d4182a2ac2d541d884742d3037c26e57",
Pierre-Yves Chibon 31a638
            json_data=data,
Pierre-Yves Chibon 31a638
        )
Pierre-Yves Chibon 31a638
        self.session.commit()
Pierre-Yves Chibon 31a638
Pierre-Yves Chibon 31a638
        # After insertion
Pierre-Yves Chibon 31a638
        self.assertEqual(repo.requests[0].id, 4)
Pierre-Yves Chibon 31a638
        self.assertEqual(
Pierre-Yves Chibon 73d120
            repo.requests[0].uid, "d4182a2ac2d541d884742d3037c26e57"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.requests[0].title, "test request #2")
Pierre-Yves Chibon 31a638
        self.assertEqual(len(repo.requests[0].comments), 0)
Pierre-Yves Chibon 73d120
        self.assertEqual(repo.requests[0].tags_text, ["WIP", "core"])
Pierre-Yves Chibon 31a638
Patrick Uiterwijk b4c473
    def test_read_git_lines(self):
Pierre-Yves Chibon 858b9d
        """ Test the read_git_lines method of pagure.lib.git. """
Pierre-Yves Chibon 858b9d
        self.test_update_git()
Pierre-Yves Chibon 858b9d
Pierre-Yves Chibon 73d120
        gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "tickets", "test_ticket_repo.git"
Pierre-Yves Chibon 858b9d
        )
Pierre-Yves Chibon 73d120
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 73d120
            ["log", "-1", "--pretty='%s'"], gitrepo
Pierre-Yves Chibon 858b9d
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(len(output), 1)
Pierre-Yves Chibon 73d120
        self.assertTrue(output[0].startswith("'Updated issue "))
Pierre-Yves Chibon 73d120
        self.assertTrue(output[0].endswith(": Test issue'"))
Pierre-Yves Chibon 858b9d
Pierre-Yves Chibon 858b9d
        # Keeping the new line symbol
Pierre-Yves Chibon 858b9d
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 73d120
            ["log", "-1", "--pretty='%s'"], gitrepo, keepends=True
Pierre-Yves Chibon 858b9d
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(len(output), 1)
Pierre-Yves Chibon 73d120
        self.assertTrue(output[0].endswith(": Test issue'\n"))
Pierre-Yves Chibon 858b9d
Patrick Uiterwijk b4c473
    def test_get_revs_between(self):
Pierre-Yves Chibon 32fce0
        """ Test the get_revs_between method of pagure.lib.git. """
Pierre-Yves Chibon 32fce0
Pierre-Yves Chibon 32fce0
        self.test_update_git()
Pierre-Yves Chibon 32fce0
Pierre-Yves Chibon 73d120
        gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "tickets", "test_ticket_repo.git"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 32fce0
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 73d120
            ["log", "-3", "--pretty='%H'"], gitrepo
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 32fce0
        self.assertEqual(len(output), 2)
Pierre-Yves Chibon 73d120
        from_hash = output[1].replace("'", "")
Pierre-Yves Chibon 32fce0
Clement Verna 1901d5
        # Case 1, repo BASE is null and HEAD is equal to from_hash
Pierre-Yves Chibon 73d120
        to_hash = "0"
Pierre-Yves Chibon 32fce0
        output1 = pagure.lib.git.get_revs_between(
Pierre-Yves Chibon 73d120
            to_hash, from_hash, gitrepo, "refs/heads/master"
Pierre-Yves Chibon 73d120
        )
Clement Verna 990b72
        self.assertEqual(output1, [from_hash])
Pierre-Yves Chibon 32fce0
Clement Verna 1901d5
        # Case 2, get revs between two commits (to_hash, from_hash)
Pierre-Yves Chibon 73d120
        to_hash = output[0].replace("'", "")
Pierre-Yves Chibon 32fce0
        output2 = pagure.lib.git.get_revs_between(
Pierre-Yves Chibon 73d120
            to_hash, from_hash, gitrepo, "refs/heads/master"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 32fce0
        self.assertEqual(output2, [to_hash])
Pierre-Yves Chibon 32fce0
Clement Verna 1901d5
        # Case 3, get revs between two commits (from_hash, to_hash)
Clement Verna 1901d5
        output3 = pagure.lib.git.get_revs_between(
Pierre-Yves Chibon 73d120
            from_hash, to_hash, gitrepo, "refs/heads/master"
Pierre-Yves Chibon 73d120
        )
Clement Verna 1901d5
        self.assertEqual(output3, [to_hash])
Clement Verna 1901d5
Clement Verna 469e2c
        # Case 4, get revs between two commits on two different branches
Pierre-Yves Chibon 73d120
        newgitrepo = tempfile.mkdtemp(prefix="pagure-")
Clement Verna 469e2c
        newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
Pierre-Yves Chibon 73d120
        newrepo.create_branch("feature", newrepo.head.peel())
Clement Verna 469e2c
Pierre-Yves Chibon 73d120
        with open(os.path.join(newgitrepo, "sources"), "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("foo\n bar")
Pierre-Yves Chibon 73d120
        newrepo.index.add("sources")
Clement Verna 469e2c
        newrepo.index.write()
Clement Verna 469e2c
Clement Verna 469e2c
        # Commits the files added
Clement Verna 469e2c
        tree = newrepo.index.write_tree()
Pierre-Yves Chibon 73d120
        author = pygit2.Signature("Alice Author", "alice@authors.tld")
Pierre-Yves Chibon 73d120
        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
Clement Verna 469e2c
        newrepo.create_commit(
Pierre-Yves Chibon 73d120
            "refs/heads/feature",  # the name of the reference to update
Clement Verna 469e2c
            author,
Clement Verna 469e2c
            committer,
Pierre-Yves Chibon 73d120
            "Add sources file for testing",
Clement Verna 469e2c
            # binary string representing the tree object ID
Clement Verna 469e2c
            tree,
Clement Verna 469e2c
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 73d120
            [to_hash],
Clement Verna 469e2c
        )
Pierre-Yves Chibon 73d120
        branch_commit = newrepo.revparse_single("refs/heads/feature")
Clement Verna 469e2c
Clement Verna 469e2c
        # Push to origin
Clement Verna 469e2c
        ori_remote = newrepo.remotes[0]
Pierre-Yves Chibon 73d120
        PagureRepo.push(ori_remote, "refs/heads/feature")
Clement Verna 469e2c
Clement Verna 469e2c
        # Remove the clone
Clement Verna 469e2c
        shutil.rmtree(newgitrepo)
Clement Verna 469e2c
Clement Verna 469e2c
        output4 = pagure.lib.git.get_revs_between(
Pierre-Yves Chibon 73d120
            "0", branch_commit.oid.hex, gitrepo, "refs/heads/feature"
Pierre-Yves Chibon 73d120
        )
Clement Verna 469e2c
        self.assertEqual(output4, [branch_commit.oid.hex])
Clement Verna 469e2c
Patrick Uiterwijk b4c473
    def test_get_author(self):
Pierre-Yves Chibon ad3d68
        """ Test the get_author method of pagure.lib.git. """
Pierre-Yves Chibon 84cd98
Pierre-Yves Chibon 84cd98
        self.test_update_git()
Pierre-Yves Chibon 84cd98
Pierre-Yves Chibon 73d120
        gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "tickets", "test_ticket_repo.git"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 84cd98
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 73d120
            ["log", "-3", "--pretty='%H'"], gitrepo
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 84cd98
        self.assertEqual(len(output), 2)
Pierre-Yves Chibon 84cd98
        for githash in output:
Pierre-Yves Chibon 73d120
            githash = githash.replace("'", "")
Pierre-Yves Chibon ad3d68
            output = pagure.lib.git.get_author(githash, gitrepo)
Pierre-Yves Chibon 73d120
            self.assertEqual(output, "pagure")
Pierre-Yves Chibon 84cd98
Pierre-Yves Chibon ad3d68
    def get_author_email(self):
Pierre-Yves Chibon ad3d68
        """ Test the get_author_email method of pagure.lib.git. """
Pierre-Yves Chibon f69b11
Pierre-Yves Chibon f69b11
        self.test_update_git()
Pierre-Yves Chibon f69b11
Pierre-Yves Chibon 73d120
        gitrepo = os.path.join(self.path, "tickets", "test_ticket_repo.git")
Pierre-Yves Chibon f69b11
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 73d120
            ["log", "-3", "--pretty='%H'"], gitrepo
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon f69b11
        self.assertEqual(len(output), 2)
Pierre-Yves Chibon f69b11
        for githash in output:
Pierre-Yves Chibon 73d120
            githash = githash.replace("'", "")
Pierre-Yves Chibon ad3d68
            output = pagure.lib.git.get_author_email(githash, gitrepo)
Pierre-Yves Chibon 73d120
            self.assertEqual(output, "pagure")
Pierre-Yves Chibon f69b11
Pierre-Yves Chibon cf28b3
    def test_get_repo_name(self):
Pierre-Yves Chibon cf28b3
        """ Test the get_repo_name method of pagure.lib.git. """
Pierre-Yves Chibon cf28b3
Patrick Uiterwijk 4012dc
        def runtest(reponame, *path):
Pierre-Yves Chibon 73d120
            gitrepo = os.path.join(self.path, "repos", *path)
Patrick Uiterwijk 4012dc
            os.makedirs(gitrepo)
Patrick Uiterwijk 4012dc
            repo_name = pagure.lib.git.get_repo_name(gitrepo)
Patrick Uiterwijk 4012dc
            self.assertEqual(repo_name, reponame)
Pierre-Yves Chibon cf28b3
Pierre-Yves Chibon 73d120
        runtest("test_ticket_repo", "tickets", "test_ticket_repo.git")
Pierre-Yves Chibon 73d120
        runtest("test", "test.git")
Pierre-Yves Chibon 73d120
        runtest("foo.test", "foo.test.git")
Pierre-Yves Chibon cf28b3
Pierre-Yves Chibon a7c15a
    def test_get_username(self):
Pierre-Yves Chibon a7c15a
        """ Test the get_username method of pagure.lib.git. """
Pierre-Yves Chibon 73d120
Patrick Uiterwijk 4012dc
        def runtest(username, *path):
Pierre-Yves Chibon 73d120
            gitrepo = os.path.join(self.path, "repos", *path)
Patrick Uiterwijk 4012dc
            os.makedirs(gitrepo)
Patrick Uiterwijk 4012dc
            repo_username = pagure.lib.git.get_username(gitrepo)
Patrick Uiterwijk 4012dc
            self.assertEqual(repo_username, username)
Patrick Uiterwijk 4012dc
Pierre-Yves Chibon 73d120
        runtest(None, "tickets", "test_ticket_repo.git")
Pierre-Yves Chibon 73d120
        runtest(None, "test.git")
Pierre-Yves Chibon 73d120
        runtest(None, "foo.test.git")
Pierre-Yves Chibon 73d120
        runtest("pingou", "forks", "pingou", "foo.test.git")
Pierre-Yves Chibon 73d120
        runtest("pingou", "forks", "pingou", "bar/foo.test.git")
Pierre-Yves Chibon 826fb9
Pierre-Yves Chibon 0eb3ee
    def test_get_repo_namespace(self):
Pierre-Yves Chibon 0eb3ee
        """ Test the get_repo_namespace method of pagure.lib.git. """
Pierre-Yves Chibon 73d120
Patrick Uiterwijk 4012dc
        def runtest(namespace, *path):
Pierre-Yves Chibon 73d120
            gitrepo = os.path.join(self.path, "repos", *path)
Patrick Uiterwijk 4012dc
            if not os.path.exists(gitrepo):
Patrick Uiterwijk 4012dc
                os.makedirs(gitrepo)
Patrick Uiterwijk 4012dc
            repo_namespace = pagure.lib.git.get_repo_namespace(gitrepo)
Patrick Uiterwijk 4012dc
            self.assertEqual(repo_namespace, namespace)
Patrick Uiterwijk 4012dc
Pierre-Yves Chibon 73d120
        runtest(None, "test_ticket_repo.git")
Pierre-Yves Chibon 73d120
        runtest("foo/bar/baz", "foo", "bar", "baz", "test.git")
Pierre-Yves Chibon 73d120
        runtest(None, "foo.test.git")
Pierre-Yves Chibon 73d120
        runtest(None, "forks", "user", "foo.test.git")
Pierre-Yves Chibon 73d120
        runtest("bar", "forks", "user", "bar", "foo.test.git")
Pierre-Yves Chibon 73d120
        runtest("ns/bar", "forks", "user", "ns", "bar", "foo.test.git")
Pierre-Yves Chibon 73d120
        runtest("bar", "forks", "user", "bar", "foo.test.git")
Pierre-Yves Chibon 0eb3ee
Vivek Anand 763ae5
    def test_update_custom_fields_from_json(self):
Vivek Anand 763ae5
        """ Test the update_custom_fields_from_json method of lib.git """
Vivek Anand 763ae5
Vivek Anand 763ae5
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Vivek Anand 763ae5
Vivek Anand 763ae5
        # Create issues to play with
Pierre-Yves Chibon 930073
        pagure.lib.query.new_issue(
Vivek Anand 763ae5
            session=self.session,
Vivek Anand 763ae5
            repo=repo,
Pierre-Yves Chibon 73d120
            title="Test issue",
Pierre-Yves Chibon 73d120
            content="We should work on this",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            issue_uid="someuid",
Vivek Anand 763ae5
        )
Vivek Anand 763ae5
        self.session.commit()
Vivek Anand 763ae5
Pierre-Yves Chibon 73d120
        issue = pagure.lib.query.get_issue_by_uid(self.session, "someuid")
Vivek Anand 763ae5
Vivek Anand 763ae5
        # Fake json data, currently without custom_fields
Vivek Anand 763ae5
        # This should bring no new custom_fields to the issue
Vivek Anand 763ae5
        json_data = {
Vivek Anand 763ae5
            "status": "Open",
Vivek Anand 763ae5
            "title": "Test issue",
Vivek Anand 763ae5
            "private": False,
Vivek Anand 763ae5
            "content": "We should work on this",
Vivek Anand 763ae5
            "user": {
Vivek Anand 763ae5
                "fullname": "PY C",
Vivek Anand 763ae5
                "name": "pingou",
Vivek Anand 763ae5
                "default_email": "bar@pingou.com",
Pierre-Yves Chibon 73d120
                "emails": ["bar@pingou.com"],
Vivek Anand 763ae5
            },
Vivek Anand 763ae5
            "id": 1,
Vivek Anand 763ae5
            "blocks": [],
Vivek Anand 763ae5
            "depends": [],
Vivek Anand 763ae5
            "date_created": "1234567",
Vivek Anand 763ae5
            "comments": [],
Vivek Anand 763ae5
        }
Vivek Anand 763ae5
Vivek Anand 763ae5
        pagure.lib.git.update_custom_field_from_json(
Pierre-Yves Chibon 73d120
            self.session, repo, issue, json_data
Pierre-Yves Chibon 73d120
        )
Vivek Anand 763ae5
Pierre-Yves Chibon 73d120
        updated_issue = pagure.lib.query.get_issue_by_uid(
Pierre-Yves Chibon 73d120
            self.session, "someuid"
Pierre-Yves Chibon 73d120
        )
Vivek Anand 763ae5
Pierre-Yves Chibon 73d120
        self.assertEqual(updated_issue.to_json().get("custom_fields"), [])
Vivek Anand 763ae5
        custom_fields = [
Pierre-Yves Chibon 73d120
            {
Pierre-Yves Chibon 73d120
                "name": "custom1",
Pierre-Yves Chibon 73d120
                "key_type": "text",
Pierre-Yves Chibon 73d120
                "value": "value1",
Pierre-Yves Chibon 73d120
                "key_data": None,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon 73d120
            {
Pierre-Yves Chibon 73d120
                "name": "custom2",
Pierre-Yves Chibon 73d120
                "key_type": "text",
Pierre-Yves Chibon 73d120
                "value": "value2",
Pierre-Yves Chibon 73d120
                "key_data": None,
Pierre-Yves Chibon 73d120
            },
Vivek Anand 763ae5
        ]
Vivek Anand 763ae5
Vivek Anand 763ae5
        # Again, Fake the json data but, with custom_fields in it
Vivek Anand 763ae5
        # The updated issue should have the custom_fields as
Vivek Anand 763ae5
        # was in the json_data
Vivek Anand 763ae5
        json_data = {
Vivek Anand 763ae5
            "status": "Open",
Vivek Anand 763ae5
            "title": "Test issue",
Vivek Anand 763ae5
            "private": False,
Vivek Anand 763ae5
            "content": "We should work on this",
Vivek Anand 763ae5
            "user": {
Vivek Anand 763ae5
                "fullname": "PY C",
Vivek Anand 763ae5
                "name": "pingou",
Vivek Anand 763ae5
                "default_email": "bar@pingou.com",
Pierre-Yves Chibon 73d120
                "emails": ["bar@pingou.com"],
Vivek Anand 763ae5
            },
Vivek Anand 763ae5
            "id": 1,
Vivek Anand 763ae5
            "blocks": [],
Vivek Anand 763ae5
            "depends": [],
Vivek Anand 763ae5
            "date_created": "1234567",
Vivek Anand 763ae5
            "comments": [],
Vivek Anand 763ae5
            "custom_fields": custom_fields,
Vivek Anand 763ae5
        }
Vivek Anand 763ae5
Vivek Anand 763ae5
        pagure.lib.git.update_custom_field_from_json(
Pierre-Yves Chibon 73d120
            self.session, repo, issue, json_data
Pierre-Yves Chibon 73d120
        )
Vivek Anand 763ae5
Pierre-Yves Chibon 73d120
        updated_issue = pagure.lib.query.get_issue_by_uid(
Pierre-Yves Chibon 73d120
            self.session, "someuid"
Pierre-Yves Chibon 73d120
        )
Vivek Anand 763ae5
Pierre-Yves Chibon 73d120
        custom_fields_of_issue = updated_issue.to_json().get("custom_fields")
Vivek Anand 763ae5
        self.assertEqual(custom_fields_of_issue, custom_fields)
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.git.update_git")
Pierre-Yves Chibon a3fe59
    def test_merge_pull_request_no_master(self, email_f, up_git):
Pierre-Yves Chibon a3fe59
        """ Test the merge_pull_request function when there are no master
Pierre-Yves Chibon a3fe59
        branch in the repo. """
Pierre-Yves Chibon a3fe59
        email_f.return_value = True
Pierre-Yves Chibon a3fe59
        up_git.return_value = True
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon 73d120
        gitfolder = os.path.join(self.path, "repos")
Pierre-Yves Chibon 73d120
        docfolder = os.path.join(self.path, "docs")
Pierre-Yves Chibon 73d120
        ticketfolder = os.path.join(self.path, "tickets")
Pierre-Yves Chibon 73d120
        requestfolder = os.path.join(self.path, "requests")
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon a3fe59
        # Create project
Pierre-Yves Chibon a3fe59
        item = pagure.lib.model.Project(
Pierre-Yves Chibon a3fe59
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test",
Pierre-Yves Chibon 73d120
            description="test project",
Pierre-Yves Chibon 73d120
            hook_token="aaabbbwww",
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon a3fe59
        self.session.add(item)
Pierre-Yves Chibon a3fe59
        self.session.commit()
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon a3fe59
        gitrepo = os.path.join(gitfolder, repo.path)
Pierre-Yves Chibon a3fe59
        docrepo = os.path.join(docfolder, repo.path)
Pierre-Yves Chibon a3fe59
        ticketrepo = os.path.join(ticketfolder, repo.path)
Pierre-Yves Chibon a3fe59
        requestrepo = os.path.join(requestfolder, repo.path)
Pierre-Yves Chibon 73d120
        os.makedirs(os.path.join(self.path, "repos", "forks", "foo"))
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon 73d120
        self.gitrepo = os.path.join(self.path, "repos", "test.git")
Pierre-Yves Chibon a3fe59
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon a3fe59
        repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon a3fe59
        # Fork the project
Pierre-Yves Chibon 930073
        task = pagure.lib.query.fork_project(
Pierre-Yves Chibon 73d120
            session=self.session, user="foo", repo=repo
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon a3fe59
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            task.get(),
Pierre-Yves Chibon 73d120
            {
Pierre-Yves Chibon 73d120
                "endpoint": "ui_ns.view_repo",
Pierre-Yves Chibon 73d120
                "repo": "test",
Pierre-Yves Chibon 73d120
                "username": "foo",
Pierre-Yves Chibon 73d120
                "namespace": None,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon a3fe59
        # Create repo, with some content
Pierre-Yves Chibon a3fe59
        self.gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "forks", "foo", "test.git"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        tests.add_content_git_repo(self.gitrepo, branch="feature")
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon 73d120
        fork_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test", user="foo"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon a3fe59
        # Create a PR to play with
Pierre-Yves Chibon 930073
        req = pagure.lib.query.new_pull_request(
Pierre-Yves Chibon a3fe59
            session=self.session,
Pierre-Yves Chibon a3fe59
            repo_from=fork_repo,
Pierre-Yves Chibon 73d120
            branch_from="feature",
Pierre-Yves Chibon a3fe59
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="test PR",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            requestuid="foobar",
Pierre-Yves Chibon a3fe59
            requestid=None,
Pierre-Yves Chibon 73d120
            status="Open",
Pierre-Yves Chibon 73d120
            notify=True,
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon a3fe59
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(req.title, "test PR")
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon d972d9
        # `master` branch not found
Pierre-Yves Chibon 59f36c
        msg = pagure.lib.git.merge_pull_request(
Pierre-Yves Chibon 73d120
            self.session, request=req, username="pingou", domerge=False
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "FFORWARD")
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.git.update_git")
Pierre-Yves Chibon 99d493
    def test_merge_pull_request_closed(self, email_f, up_git):
Pierre-Yves Chibon 99d493
        """ Test the merge_pull_request function when the PR was already
Pierre-Yves Chibon 99d493
        closed/merged. """
Pierre-Yves Chibon 99d493
        email_f.return_value = True
Pierre-Yves Chibon 99d493
        up_git.return_value = True
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 73d120
        gitfolder = os.path.join(self.path, "repos")
Pierre-Yves Chibon 73d120
        docfolder = os.path.join(self.path, "docs")
Pierre-Yves Chibon 73d120
        ticketfolder = os.path.join(self.path, "tickets")
Pierre-Yves Chibon 73d120
        requestfolder = os.path.join(self.path, "requests")
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        # Create project
Pierre-Yves Chibon 99d493
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 99d493
            user_id=1,  # pingou
Pierre-Yves Chibon 73d120
            name="test",
Pierre-Yves Chibon 73d120
            description="test project",
Pierre-Yves Chibon 73d120
            hook_token="aaabbbwww",
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
        self.session.add(item)
Pierre-Yves Chibon 99d493
        self.session.commit()
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        os.makedirs(os.path.join(self.path, "repos", "forks", "foo"))
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 73d120
        self.gitrepo = os.path.join(self.path, "repos", "test.git")
Pierre-Yves Chibon 99d493
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon 99d493
        repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon 73d120
        tests.add_content_git_repo(self.gitrepo, branch="master")
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        # Fork the project
Pierre-Yves Chibon 930073
        task = pagure.lib.query.fork_project(
Pierre-Yves Chibon 73d120
            session=self.session, user="foo", repo=repo
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            task.get(),
Pierre-Yves Chibon 73d120
            {
Pierre-Yves Chibon 73d120
                "endpoint": "ui_ns.view_repo",
Pierre-Yves Chibon 73d120
                "repo": "test",
Pierre-Yves Chibon 73d120
                "username": "foo",
Pierre-Yves Chibon 73d120
                "namespace": None,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        # Create repo, with some content
Pierre-Yves Chibon 99d493
        self.gitrepo = os.path.join(
Pierre-Yves Chibon 73d120
            self.path, "repos", "forks", "foo", "test.git"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        tests.add_content_git_repo(self.gitrepo, branch="feature")
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 73d120
        fork_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test", user="foo"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 99d493
        # Create a PR to play with
Pierre-Yves Chibon 930073
        req = pagure.lib.query.new_pull_request(
Pierre-Yves Chibon 99d493
            session=self.session,
Pierre-Yves Chibon 99d493
            repo_from=fork_repo,
Pierre-Yves Chibon 73d120
            branch_from="feature",
Pierre-Yves Chibon 99d493
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="test PR",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 73d120
            requestuid="foobar",
Pierre-Yves Chibon 99d493
            requestid=None,
Pierre-Yves Chibon 73d120
            status="Open",
Pierre-Yves Chibon 73d120
            notify=True,
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(req.title, "test PR")
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        # Close the PR before we ask to merge it
Pierre-Yves Chibon 73d120
        req.status = "Closed"
Pierre-Yves Chibon 99d493
        req.closed_by_id = 2  # id:2 == foo
Pierre-Yves Chibon 99d493
        req.closed_at = datetime.datetime(2017, 10, 20, 12, 32, 10)
Pierre-Yves Chibon 99d493
        self.session.add(req)
Pierre-Yves Chibon 99d493
        self.session.commit()
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        # PR already closed
Aurélien Bompard 626417
        six.assertRaisesRegex(
Aurélien Bompard 626417
            self,
Pierre-Yves Chibon 99d493
            pagure.exceptions.PagureException,
Pierre-Yves Chibon 73d120
            "This pull-request was merged or closed by foo",
Pierre-Yves Chibon 99d493
            pagure.lib.git.merge_pull_request,
Pierre-Yves Chibon 99d493
            self.session,
Pierre-Yves Chibon 99d493
            request=req,
Pierre-Yves Chibon 73d120
            username="pingou",
Pierre-Yves Chibon 73d120
            domerge=False,
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 73d120
    @patch("subprocess.Popen")
Pierre-Yves Chibon be6a91
    def test_generate_gitolite_acls(self, popen):
Pierre-Yves Chibon be6a91
        """ Test calling generate_gitolite_acls. """
Pierre-Yves Chibon be6a91
        pagure.SESSION = self.session
Pierre-Yves Chibon be6a91
        pagure.lib.git.SESSION = self.session
Pierre-Yves Chibon 73d120
        pagure.config.config["GITOLITE_HOME"] = "/tmp"
Pierre-Yves Chibon be6a91
Pierre-Yves Chibon 145998
        proc = MagicMock()
Pierre-Yves Chibon 145998
        proc.communicate.return_value = (1, 2)
Pierre-Yves Chibon 145998
        proc.returncode = 0
Pierre-Yves Chibon 145998
        popen.return_value = proc
Pierre-Yves Chibon 73d120
        helper = pagure.lib.git_auth.get_git_auth_helper("gitolite3")
Pierre-Yves Chibon 274e60
        helper.generate_acls(project=None)
Pierre-Yves Chibon be6a91
        popen.assert_called_with(
Pierre-Yves Chibon 73d120
            "HOME=/tmp gitolite compile && "
Pierre-Yves Chibon 73d120
            "HOME=/tmp gitolite trigger POST_COMPILE",
Pierre-Yves Chibon 73d120
            cwd="/tmp",
Pierre-Yves Chibon 73d120
            shell=True,
Pierre-Yves Chibon 73d120
            stderr=-1,
Pierre-Yves Chibon 73d120
            stdout=-1,
Pierre-Yves Chibon be6a91
        )
Pierre-Yves Chibon be6a91
Slavek Kabrda 595b6f
    def test_is_forced_push_new_branch(self):
Slavek Kabrda 595b6f
        self.assertFalse(
Slavek Kabrda 595b6f
            pagure.lib.git.is_forced_push(
Pierre-Yves Chibon 73d120
                "0000000000000000000000000000000000000000",
Pierre-Yves Chibon 73d120
                "^0e6e0b6c931d65ee22f67205a53933d841c6eeff",
Pierre-Yves Chibon 73d120
                "path/is/not/important",
Slavek Kabrda 595b6f
            )
Slavek Kabrda 595b6f
        )
Slavek Kabrda 595b6f
Slavek Kabrda 197fa2
    @patch("pagure.utils.get_repo_path")
Slavek Kabrda 197fa2
    def test_update_pull_ref(self, get_repo_path):
Slavek Kabrda 197fa2
        fake_pr = MagicMock()
Slavek Kabrda 197fa2
        fake_pr.uid = "1234567"
Slavek Kabrda 197fa2
        fake_pr.branch_from = "master"
Slavek Kabrda 197fa2
        fake_pr.id = 6
Slavek Kabrda 197fa2
        fake_pr.user = MagicMock()
Slavek Kabrda 197fa2
        fake_pr.user.user = "pingou"
Slavek Kabrda 197fa2
        fake_pr.project = "doesnt_matter_mocked_out"
Slavek Kabrda 197fa2
        projects = tests.create_projects_git(
Pierre-Yves Chibon 73d120
            os.path.join(self.path, "repos"), bare=True
Slavek Kabrda 197fa2
        )
Slavek Kabrda 197fa2
        tests.add_content_git_repo(projects[0])
Slavek Kabrda 197fa2
        tests.add_content_git_repo(projects[1])
Slavek Kabrda 197fa2
        orig = pygit2.Repository(projects[0])
Slavek Kabrda 197fa2
        fork = pygit2.Repository(projects[1])
Slavek Kabrda 197fa2
        get_repo_path.return_value = projects[0]
Slavek Kabrda 197fa2
Slavek Kabrda 197fa2
        # make sure that creating works the first time
Slavek Kabrda 197fa2
        pagure.lib.git.update_pull_ref(fake_pr, fork)
Pierre-Yves Chibon 29ff0a
        oldhex = fork.references["refs/heads/master"].peel().hex
Slavek Kabrda 197fa2
        self.assertEqual(
Pierre-Yves Chibon 73d120
            orig.references["refs/pull/6/head"].peel().hex, oldhex
Slavek Kabrda 197fa2
        )
Slavek Kabrda 197fa2
Slavek Kabrda 197fa2
        # make sure that updating works correctly
Slavek Kabrda 197fa2
        tests.add_content_git_repo(projects[1], append="foobar")
Pierre-Yves Chibon 29ff0a
        newhex = fork.references["refs/heads/master"].peel().hex
Slavek Kabrda 197fa2
        self.assertNotEqual(oldhex, newhex)
Slavek Kabrda 197fa2
        pagure.lib.git.update_pull_ref(fake_pr, fork)
Slavek Kabrda 197fa2
        self.assertEqual(
Pierre-Yves Chibon 73d120
            orig.references["refs/pull/6/head"].peel().hex, newhex
Slavek Kabrda 197fa2
        )
Slavek Kabrda 197fa2
Slavek Kabrda 197fa2
        # make sure the function works fine even if there's a leftover
Slavek Kabrda 197fa2
        # ref from previous failed run of the function
Slavek Kabrda 197fa2
        with patch("pygit2.remote.RemoteCollection.delete"):
Slavek Kabrda 197fa2
            pagure.lib.git.update_pull_ref(fake_pr, fork)
Slavek Kabrda 197fa2
        self.assertIsNotNone(fork.remotes["pingou_1234567"])
Slavek Kabrda 197fa2
        tests.add_content_git_repo(projects[1], append="foobarbaz")
Pierre-Yves Chibon 29ff0a
        newesthex = fork.references["refs/heads/master"].peel().hex
Slavek Kabrda 197fa2
        self.assertNotEqual(newhex, newesthex)
Slavek Kabrda 197fa2
        pagure.lib.git.update_pull_ref(fake_pr, fork)
Slavek Kabrda 197fa2
        self.assertEqual(
Pierre-Yves Chibon 73d120
            orig.references["refs/pull/6/head"].peel().hex, newesthex
Slavek Kabrda 197fa2
        )
Slavek Kabrda 197fa2
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 86e455
class PagureLibGitCommitToPatchtests(tests.Modeltests):
Pierre-Yves Chibon 86e455
    """ Tests for pagure.lib.git """
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    maxDiff = None
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def setUp(self):
Pierre-Yves Chibon 86e455
        """ Set up the environment for the tests. """
Pierre-Yves Chibon 86e455
        super(PagureLibGitCommitToPatchtests, self).setUp()
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        # Create a git repo to play with
Pierre-Yves Chibon 73d120
        self.gitrepo = os.path.join(self.path, "repos", "test_repo.git")
Pierre-Yves Chibon 86e455
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        # Create a file in that git repo
Pierre-Yves Chibon 73d120
        with open(os.path.join(self.gitrepo, "sources"), "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("foo\n bar")
Pierre-Yves Chibon 73d120
        repo.index.add("sources")
Pierre-Yves Chibon 86e455
        repo.index.write()
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        # Commits the files added
Pierre-Yves Chibon 86e455
        tree = repo.index.write_tree()
Pierre-Yves Chibon 73d120
        author = pygit2.Signature("Alice Author", "alice@authors.tld")
Pierre-Yves Chibon 73d120
        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
Pierre-Yves Chibon 86e455
        repo.create_commit(
Pierre-Yves Chibon 73d120
            "refs/heads/master",  # the name of the reference to update
Pierre-Yves Chibon 86e455
            author,
Pierre-Yves Chibon 86e455
            committer,
Pierre-Yves Chibon 73d120
            "Add sources file for testing",
Pierre-Yves Chibon 86e455
            # binary string representing the tree object ID
Pierre-Yves Chibon 86e455
            tree,
Pierre-Yves Chibon 86e455
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 73d120
            [],
Pierre-Yves Chibon 86e455
        )
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        self.first_commit = repo.revparse_single("HEAD")
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        # Edit the sources file again
Pierre-Yves Chibon 73d120
        with open(os.path.join(self.gitrepo, "sources"), "w") as stream:
Pierre-Yves Chibon 73d120
            stream.write("foo\n bar\nbaz\n boose")
Pierre-Yves Chibon 73d120
        repo.index.add("sources")
Pierre-Yves Chibon 86e455
        repo.index.write()
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        # Commits the files added
Pierre-Yves Chibon 86e455
        tree = repo.index.write_tree()
Pierre-Yves Chibon 73d120
        author = pygit2.Signature("Alice Author", "alice@authors.tld")
Pierre-Yves Chibon 73d120
        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
Pierre-Yves Chibon 86e455
        repo.create_commit(
Pierre-Yves Chibon 73d120
            "refs/heads/master",  # the name of the reference to update
Pierre-Yves Chibon 86e455
            author,
Pierre-Yves Chibon 86e455
            committer,
Pierre-Yves Chibon 73d120
            "Add baz and boose to the sources\n\n There are more objects to "
Pierre-Yves Chibon 73d120
            "consider",
Pierre-Yves Chibon 86e455
            # binary string representing the tree object ID
Pierre-Yves Chibon 86e455
            tree,
Pierre-Yves Chibon 86e455
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 73d120
            [self.first_commit.oid.hex],
Pierre-Yves Chibon 86e455
        )
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        self.second_commit = repo.revparse_single("HEAD")
Pierre-Yves Chibon 86e455
Julen Landa Alustiza 05156b
        # Add empty commit
Julen Landa Alustiza 05156b
        repo.create_commit(
Julen Landa Alustiza 05156b
            "refs/heads/master",  # the name of the reference to update
Julen Landa Alustiza 05156b
            author,
Julen Landa Alustiza 05156b
            committer,
Julen Landa Alustiza 05156b
            "Empty commit",
Julen Landa Alustiza 05156b
            # binary string representing the tree object ID
Julen Landa Alustiza 05156b
            tree,
Julen Landa Alustiza 05156b
            # list of binary strings representing parents of the new commit
Julen Landa Alustiza 05156b
            [self.second_commit.oid.hex],
Julen Landa Alustiza 05156b
        )
Julen Landa Alustiza 05156b
Julen Landa Alustiza 05156b
        self.third_commit = repo.revparse_single("HEAD")
Julen Landa Alustiza 05156b
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_first_commit(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patch = pagure.lib.git.commit_to_patch(repo, self.first_commit)
Karsten Hopp b310af
        exp = r"""Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 86e455
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 86e455
Subject: Add sources file for testing
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
---
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
new file mode 100644
Pierre-Yves Chibon 86e455
index 0000000..9f44358
Pierre-Yves Chibon 86e455
--- /dev/null
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 86e455
+foo
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                continue
Pierre-Yves Chibon 73d120
            if row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
            npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_single_commit(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patch = pagure.lib.git.commit_to_patch(repo, self.second_commit)
Karsten Hopp b310af
        exp = r"""Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 86e455
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 86e455
Subject: Add baz and boose to the sources
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
 There are more objects to consider
Pierre-Yves Chibon 86e455
---
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 86e455
--- a/sources
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 86e455
 foo
Pierre-Yves Chibon 86e455
- bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
+baz
Pierre-Yves Chibon 86e455
+ boose
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                continue
Pierre-Yves Chibon 73d120
            if row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
            npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_2_commits(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patch = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo, [self.first_commit, self.second_commit]
Pierre-Yves Chibon 73d120
        )
Karsten Hopp b310af
        exp = r"""Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 86e455
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 86e455
Subject: [PATCH 1/2] Add sources file for testing
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
---
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
new file mode 100644
Pierre-Yves Chibon 86e455
index 0000000..9f44358
Pierre-Yves Chibon 86e455
--- /dev/null
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 86e455
+foo
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 86e455
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 86e455
Subject: [PATCH 2/2] Add baz and boose to the sources
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
 There are more objects to consider
Pierre-Yves Chibon 86e455
---
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 86e455
--- a/sources
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 86e455
 foo
Pierre-Yves Chibon 86e455
- bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
+baz
Pierre-Yves Chibon 86e455
+ boose
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                continue
Pierre-Yves Chibon 73d120
            if row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
            npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_first_commit_diff(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patch = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo, self.first_commit, diff_view=True
Pierre-Yves Chibon 73d120
        )
Karsten Hopp b310af
        exp = r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
new file mode 100644
Pierre-Yves Chibon 86e455
index 0000000..9f44358
Pierre-Yves Chibon 86e455
--- /dev/null
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 86e455
+foo
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                continue
Pierre-Yves Chibon 73d120
            if row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
            npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_single_commit_diff(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patch = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo, self.second_commit, diff_view=True
Pierre-Yves Chibon 73d120
        )
Karsten Hopp b310af
        exp = r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 86e455
--- a/sources
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 86e455
 foo
Pierre-Yves Chibon 86e455
- bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
+baz
Pierre-Yves Chibon 86e455
+ boose
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                continue
Pierre-Yves Chibon 73d120
            if row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
            npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_two_commits_diff(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patch = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo, [self.first_commit, self.second_commit], diff_view=True
Pierre-Yves Chibon 73d120
        )
Karsten Hopp b310af
        exp = r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
new file mode 100644
Pierre-Yves Chibon 86e455
index 0000000..9f44358
Pierre-Yves Chibon 86e455
--- /dev/null
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 86e455
+foo
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 86e455
--- a/sources
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 86e455
 foo
Pierre-Yves Chibon 86e455
- bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
+baz
Pierre-Yves Chibon 86e455
+ boose
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        npatch = []
Pierre-Yves Chibon 73d120
        for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
            if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                continue
Pierre-Yves Chibon 73d120
            if row.startswith("From "):
Pierre-Yves Chibon 73d120
                row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
            npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
        patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_first_commit_diff_separated(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patches = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo, self.first_commit, diff_view=True, separated=True
Pierre-Yves Chibon 73d120
        )
Karsten Hopp b310af
        exp = r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
new file mode 100644
Pierre-Yves Chibon 86e455
index 0000000..9f44358
Pierre-Yves Chibon 86e455
--- /dev/null
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 86e455
+foo
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        output = []
Pierre-Yves Chibon 86e455
        for patch in patches:
Pierre-Yves Chibon 86e455
            npatch = []
Pierre-Yves Chibon 73d120
            for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
                if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                    continue
Pierre-Yves Chibon 73d120
                if row.startswith("From "):
Pierre-Yves Chibon 73d120
                    row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
                npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
            patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
            output.append(patch)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        self.assertEqual(output, [exp])
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_single_commit_diff_separated(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patches = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo, self.second_commit, diff_view=True, separated=True
Pierre-Yves Chibon 73d120
        )
Karsten Hopp b310af
        exp = r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 86e455
--- a/sources
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 86e455
 foo
Pierre-Yves Chibon 86e455
- bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
+baz
Pierre-Yves Chibon 86e455
+ boose
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
"""
Pierre-Yves Chibon 86e455
        output = []
Pierre-Yves Chibon 86e455
        for patch in patches:
Pierre-Yves Chibon 86e455
            npatch = []
Pierre-Yves Chibon 73d120
            for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
                if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                    continue
Pierre-Yves Chibon 73d120
                if row.startswith("From "):
Pierre-Yves Chibon 73d120
                    row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
                npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
            patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
            output.append(patch)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        self.assertEqual(output, [exp])
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
    def test_commit_to_patch_two_commits_diff_separated(self):
Pierre-Yves Chibon 86e455
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 86e455
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        patches = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 73d120
            repo,
Pierre-Yves Chibon 73d120
            [self.first_commit, self.second_commit],
Pierre-Yves Chibon 73d120
            diff_view=True,
Pierre-Yves Chibon 73d120
            separated=True,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        exp = [
Pierre-Yves Chibon 73d120
            r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
new file mode 100644
Pierre-Yves Chibon 86e455
index 0000000..9f44358
Pierre-Yves Chibon 86e455
--- /dev/null
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 86e455
+foo
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
""",
Pierre-Yves Chibon 73d120
            r"""diff --git a/sources b/sources
Pierre-Yves Chibon 86e455
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 86e455
--- a/sources
Pierre-Yves Chibon 86e455
+++ b/sources
Pierre-Yves Chibon 86e455
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 86e455
 foo
Pierre-Yves Chibon 86e455
- bar
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 86e455
+ bar
Pierre-Yves Chibon 86e455
+baz
Pierre-Yves Chibon 86e455
+ boose
Pierre-Yves Chibon 86e455
\ No newline at end of file
Pierre-Yves Chibon 73d120
""",
Pierre-Yves Chibon 73d120
        ]
Pierre-Yves Chibon 86e455
        output = []
Pierre-Yves Chibon 86e455
        for patch in patches:
Pierre-Yves Chibon 86e455
            npatch = []
Pierre-Yves Chibon 73d120
            for row in patch.split("\n"):
Pierre-Yves Chibon 73d120
                if row.startswith("Date:"):
Pierre-Yves Chibon 86e455
                    continue
Pierre-Yves Chibon 73d120
                if row.startswith("From "):
Pierre-Yves Chibon 73d120
                    row = row.split(" ", 2)[2]
Pierre-Yves Chibon 86e455
                npatch.append(row)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
            patch = "\n".join(npatch)
Pierre-Yves Chibon 86e455
            output.append(patch)
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 86e455
        self.assertEqual(output, exp)
Pierre-Yves Chibon 86e455
Julen Landa Alustiza 05156b
    def test_commit_to_patch_empty_commit(self):
Julen Landa Alustiza 05156b
        """ Test the commit_to_path function of pagure.lib.git. """
Julen Landa Alustiza 05156b
        repo = pygit2.init_repository(self.gitrepo)
Julen Landa Alustiza 05156b
Julen Landa Alustiza 05156b
        patch = pagure.lib.git.commit_to_patch(repo, self.third_commit)
Julen Landa Alustiza 05156b
        exp = ""
Julen Landa Alustiza 05156b
        self.assertEqual(patch, exp)
Julen Landa Alustiza 05156b
Julen Landa Alustiza 05156b
    def test_commit_to_patch_empty_commit_diff(self):
Julen Landa Alustiza 05156b
        """ Test the commit_to_patch function of pagure.lib.git. """
Julen Landa Alustiza 05156b
        repo = pygit2.init_repository(self.gitrepo)
Julen Landa Alustiza 05156b
Julen Landa Alustiza 05156b
        patch = pagure.lib.git.commit_to_patch(
Julen Landa Alustiza 05156b
            repo, self.third_commit, diff_view=True
Julen Landa Alustiza 05156b
        )
Julen Landa Alustiza 05156b
        exp = ""
Julen Landa Alustiza 05156b
        self.assertEqual(patch, exp)
Julen Landa Alustiza 05156b
Pierre-Yves Chibon 86e455
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon be6a91
    unittest.main(verbosity=2)