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
Aurélien Bompard 626417
from __future__ import unicode_literals
Aurélien Bompard 626417
Pierre-Yves Chibon a945ba
__requires__ = ['SQLAlchemy >= 0.8']
Vivek Anand 937d3e
Pierre-Yves Chibon a945ba
import pkg_resources
Pierre-Yves Chibon a945ba
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 a945ba
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon a945ba
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon a945ba
Farhaan Bukhsh 72e9db
import pagure
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 b130e5
        repo = pagure.lib.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 fe5017
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon ead0df
            session=self.session,
Pierre-Yves Chibon ead0df
            project=repo,
Pierre-Yves Chibon a5a9ad
            new_user='foo',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon ead0df
        )
Pierre-Yves Chibon ead0df
        self.session.commit()
Pierre-Yves Chibon ead0df
        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 ead0df
            name='test3',
Pierre-Yves Chibon ead0df
            description='test project #2',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon e2259d
            parent_id=1,
Pierre-Yves Chibon e2259d
            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
Jeremy Cline 20109f
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 145998
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 274e60
            self.session, configfile=outputconf, project=-1)
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 59a1eb
        #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 d1fe6f
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon d1fe6f
        preconf = os.path.join(self.path, 'header_gitolite')
Pierre-Yves Chibon d1fe6f
        with open(preconf, 'w') as stream:
Pierre-Yves Chibon d1fe6f
            stream.write('# this is a header that is manually added')
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 145998
        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 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 d1fe6f
        #print data
Pierre-Yves Chibon ccb160
        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 d1fe6f
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        preconf = os.path.join(self.path, 'header_gitolite')
Pierre-Yves Chibon d1fe6f
        with open(preconf, 'w') as stream:
Pierre-Yves Chibon d1fe6f
            stream.write('# this is a header that is manually added')
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon d1fe6f
        postconf = os.path.join(self.path, 'footer_gitolite')
Pierre-Yves Chibon d1fe6f
        with open(postconf, 'w') as stream:
Pierre-Yves Chibon d1fe6f
            stream.write('# end of generated configuration')
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 145998
        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 d1fe6f
            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 d1fe6f
        #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 d1fe6f
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon d1fe6f
        postconf = os.path.join(self.path, 'footer_gitolite')
Pierre-Yves Chibon d1fe6f
        with open(postconf, 'w') as stream:
Pierre-Yves Chibon d1fe6f
            stream.write('# end of generated configuration')
Pierre-Yves Chibon d1fe6f
Pierre-Yves Chibon 145998
        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
            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 d1fe6f
        #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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Patrick Uiterwijk faa79d
        # Add two deploy keys (one readonly one push)
Patrick Uiterwijk faa79d
        msg1 = pagure.lib.add_deploykey_to_project(
Patrick Uiterwijk faa79d
            session=self.session,
Patrick Uiterwijk faa79d
            project=repo,
Patrick Uiterwijk faa79d
            ssh_key='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==',
Patrick Uiterwijk faa79d
            pushaccess=False,
Patrick Uiterwijk faa79d
            user='pingou'
Patrick Uiterwijk faa79d
        )
Patrick Uiterwijk faa79d
        msg2 = pagure.lib.add_deploykey_to_project(
Patrick Uiterwijk faa79d
            session=self.session,
Patrick Uiterwijk faa79d
            project=repo,
Patrick Uiterwijk faa79d
            ssh_key='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9Xwc2RDzPBhlEDARfHldGjudIVoa04tqT1JVKGQmyllTFz7Rb8CngQL3e7zyNzotnhwYKHdoiLlPkVEiDee4dWMUe48ilqId+FJZQGhyv8fu4BoFdE1AJUVylzmltbLg14VqG5gjTpXgtlrEva9arKwBMHJjRYc8ScaSn3OgyQw==',
Patrick Uiterwijk faa79d
            pushaccess=True,
Patrick Uiterwijk faa79d
            user='pingou'
Patrick Uiterwijk faa79d
        )
Patrick Uiterwijk faa79d
        self.session.commit()
Patrick Uiterwijk faa79d
        self.assertEqual(msg1, 'Deploy key added')
Patrick Uiterwijk faa79d
        self.assertEqual(msg2, 'Deploy key added')
Patrick Uiterwijk faa79d
        # Add a forked project
Patrick Uiterwijk faa79d
        item = pagure.lib.model.Project(
Patrick Uiterwijk faa79d
            user_id=1,  # pingou
Patrick Uiterwijk faa79d
            name='test3',
Patrick Uiterwijk faa79d
            description='test project #2',
Patrick Uiterwijk faa79d
            is_fork=True,
Patrick Uiterwijk faa79d
            parent_id=1,
Patrick Uiterwijk faa79d
            hook_token='aaabbbvvv',
Patrick Uiterwijk faa79d
        )
Patrick Uiterwijk faa79d
        self.session.add(item)
Patrick Uiterwijk faa79d
        self.session.commit()
Patrick Uiterwijk faa79d
Patrick Uiterwijk faa79d
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Patrick Uiterwijk faa79d
Pierre-Yves Chibon 145998
        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
"""
Patrick Uiterwijk faa79d
        #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 b130e5
        repo = pagure.lib.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
Vivek Anand 2897c2
        msg = pagure.lib.add_user_to_project(
Vivek Anand 2897c2
            session=self.session,
Vivek Anand 2897c2
            project=repo,
Vivek Anand 2897c2
            new_user='foo',
Vivek Anand 2897c2
            user='pingou',
Vivek Anand 2897c2
            access='ticket'
Vivek Anand 2897c2
        )
Vivek Anand 2897c2
        self.session.commit()
Vivek Anand 2897c2
        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
Vivek Anand 2897c2
            name='test3',
Vivek Anand 2897c2
            description='test project #2',
Vivek Anand 2897c2
            is_fork=True,
Vivek Anand 2897c2
            parent_id=1,
Vivek Anand 2897c2
            hook_token='aaabbbvvv',
Vivek Anand 2897c2
        )
Vivek Anand 2897c2
        self.session.add(item)
Vivek Anand 2897c2
        self.session.commit()
Vivek Anand 2897c2
Vivek Anand 2897c2
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Vivek Anand 2897c2
Pierre-Yves Chibon 145998
        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
"""
Vivek Anand 2897c2
        #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 b130e5
        repo = pagure.lib.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
Vivek Anand 994729
        msg = pagure.lib.add_user_to_project(
Vivek Anand 994729
            session=self.session,
Vivek Anand 994729
            project=repo,
Vivek Anand 994729
            new_user='foo',
Vivek Anand 994729
            user='pingou',
Vivek Anand 994729
            access='commit'
Vivek Anand 994729
        )
Vivek Anand 994729
        self.session.commit()
Vivek Anand 994729
        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
Vivek Anand 994729
            name='test3',
Vivek Anand 994729
            description='test project #2',
Vivek Anand 994729
            is_fork=True,
Vivek Anand 994729
            parent_id=1,
Vivek Anand 994729
            hook_token='aaabbbvvv',
Vivek Anand 994729
        )
Vivek Anand 994729
        self.session.add(item)
Vivek Anand 994729
        self.session.commit()
Vivek Anand 994729
Vivek Anand 994729
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Vivek Anand 994729
Pierre-Yves Chibon 145998
        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
"""
Vivek Anand 994729
        #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 b130e5
        repo = pagure.lib.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 4fc47a
        msg = pagure.lib.add_group(
Pierre-Yves Chibon 4fc47a
            self.session,
Pierre-Yves Chibon 4fc47a
            group_name='sysadmin',
Pierre-Yves Chibon ce6666
            display_name='sysadmin group',
Pierre-Yves Chibon ce6666
            description=None,
Pierre-Yves Chibon 4fc47a
            group_type='user',
Pierre-Yves Chibon 4fc47a
            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 4fc47a
        self.assertEqual(msg, 'User `pingou` added to the group `sysadmin`.')
Pierre-Yves Chibon 6f5851
        msg = pagure.lib.add_group(
Pierre-Yves Chibon 6f5851
            self.session,
Pierre-Yves Chibon 6f5851
            group_name='devs',
Pierre-Yves Chibon ce6666
            display_name='devs group',
Pierre-Yves Chibon ce6666
            description=None,
Pierre-Yves Chibon 6f5851
            group_type='user',
Pierre-Yves Chibon 6f5851
            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 6f5851
        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 4fc47a
        msg = pagure.lib.add_group_to_project(
Pierre-Yves Chibon 4fc47a
            session=self.session,
Pierre-Yves Chibon 4fc47a
            project=repo,
Pierre-Yves Chibon 4fc47a
            new_group='sysadmin',
Pierre-Yves Chibon 4fc47a
            user='pingou',
Pierre-Yves Chibon 4fc47a
        )
Pierre-Yves Chibon 4fc47a
        self.session.commit()
Pierre-Yves Chibon 4fc47a
        self.assertEqual(msg, 'Group added')
Pierre-Yves Chibon 6f5851
        msg = pagure.lib.add_group_to_project(
Pierre-Yves Chibon 6f5851
            session=self.session,
Pierre-Yves Chibon 6f5851
            project=repo,
Pierre-Yves Chibon 6f5851
            new_group='devs',
Pierre-Yves Chibon 6f5851
            user='pingou',
Pierre-Yves Chibon 6f5851
        )
Pierre-Yves Chibon 6f5851
        self.session.commit()
Pierre-Yves Chibon 6f5851
        self.assertEqual(msg, 'Group added')
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
        # Add an user to a project
Pierre-Yves Chibon 4fc47a
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 4fc47a
            session=self.session,
Pierre-Yves Chibon 4fc47a
            project=repo,
Pierre-Yves Chibon 4fc47a
            new_user='foo',
Pierre-Yves Chibon 4fc47a
            user='pingou',
Pierre-Yves Chibon 4fc47a
        )
Pierre-Yves Chibon 4fc47a
        self.session.commit()
Pierre-Yves Chibon 4fc47a
        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 4fc47a
            name='test2',
Pierre-Yves Chibon 4fc47a
            description='test project #2',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon 4fc47a
            parent_id=1,
Pierre-Yves Chibon 4fc47a
            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
Jeremy Cline 20109f
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 145998
        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
"""
Vivek Anand 1edd2c
        #print data
Vivek Anand 1edd2c
        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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        # Add a couple of groups
Vivek Anand 1edd2c
        # They would be ticketers
Vivek Anand 1edd2c
        msg = pagure.lib.add_group(
Vivek Anand 1edd2c
            self.session,
Vivek Anand 1edd2c
            group_name='sysadmin',
Vivek Anand 1edd2c
            display_name='sysadmin group',
Vivek Anand 1edd2c
            description=None,
Vivek Anand 1edd2c
            group_type='user',
Vivek Anand 1edd2c
            user='pingou',
Vivek Anand 1edd2c
            is_admin=False,
Vivek Anand 1edd2c
            blacklist=[],
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
        self.assertEqual(msg, 'User `pingou` added to the group `sysadmin`.')
Vivek Anand 1edd2c
        msg = pagure.lib.add_group(
Vivek Anand 1edd2c
            self.session,
Vivek Anand 1edd2c
            group_name='devs',
Vivek Anand 1edd2c
            display_name='devs group',
Vivek Anand 1edd2c
            description=None,
Vivek Anand 1edd2c
            group_type='user',
Vivek Anand 1edd2c
            user='pingou',
Vivek Anand 1edd2c
            is_admin=False,
Vivek Anand 1edd2c
            blacklist=[],
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
        self.assertEqual(msg, 'User `pingou` added to the group `devs`.')
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        # Associate these groups to a project
Vivek Anand 1edd2c
        msg = pagure.lib.add_group_to_project(
Vivek Anand 1edd2c
            session=self.session,
Vivek Anand 1edd2c
            project=repo,
Vivek Anand 1edd2c
            new_group='sysadmin',
Vivek Anand 1edd2c
            user='pingou',
Vivek Anand 1edd2c
            access='ticket',
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
        self.assertEqual(msg, 'Group added')
Vivek Anand 1edd2c
        msg = pagure.lib.add_group_to_project(
Vivek Anand 1edd2c
            session=self.session,
Vivek Anand 1edd2c
            project=repo,
Vivek Anand 1edd2c
            new_group='devs',
Vivek Anand 1edd2c
            user='pingou',
Vivek Anand 1edd2c
            access='ticket'
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
        self.assertEqual(msg, 'Group added')
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        # Add an user to a project
Vivek Anand 1edd2c
        msg = pagure.lib.add_user_to_project(
Vivek Anand 1edd2c
            session=self.session,
Vivek Anand 1edd2c
            project=repo,
Vivek Anand 1edd2c
            new_user='foo',
Vivek Anand 1edd2c
            user='pingou',
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
        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
Vivek Anand 1edd2c
            name='test2',
Vivek Anand 1edd2c
            description='test project #2',
Vivek Anand 1edd2c
            is_fork=True,
Vivek Anand 1edd2c
            parent_id=1,
Vivek Anand 1edd2c
            hook_token='aaabbbvvv',
Vivek Anand 1edd2c
        )
Vivek Anand 1edd2c
        self.session.add(item)
Vivek Anand 1edd2c
        self.session.commit()
Vivek Anand 1edd2c
Vivek Anand 1edd2c
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Vivek Anand 1edd2c
Pierre-Yves Chibon 145998
        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
"""
Vivek Anand 5827c9
        #print data
Vivek Anand 5827c9
        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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Vivek Anand 5827c9
Vivek Anand 5827c9
        # Add a couple of groups
Vivek Anand 5827c9
        # They would be committers
Vivek Anand 5827c9
        msg = pagure.lib.add_group(
Vivek Anand 5827c9
            self.session,
Vivek Anand 5827c9
            group_name='sysadmin',
Vivek Anand 5827c9
            display_name='sysadmin group',
Vivek Anand 5827c9
            description=None,
Vivek Anand 5827c9
            group_type='user',
Vivek Anand 5827c9
            user='pingou',
Vivek Anand 5827c9
            is_admin=False,
Vivek Anand 5827c9
            blacklist=[],
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
        self.assertEqual(msg, 'User `pingou` added to the group `sysadmin`.')
Vivek Anand 5827c9
        msg = pagure.lib.add_group(
Vivek Anand 5827c9
            self.session,
Vivek Anand 5827c9
            group_name='devs',
Vivek Anand 5827c9
            display_name='devs group',
Vivek Anand 5827c9
            description=None,
Vivek Anand 5827c9
            group_type='user',
Vivek Anand 5827c9
            user='pingou',
Vivek Anand 5827c9
            is_admin=False,
Vivek Anand 5827c9
            blacklist=[],
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
        self.assertEqual(msg, 'User `pingou` added to the group `devs`.')
Vivek Anand 5827c9
Vivek Anand 5827c9
        # Associate these groups to a project
Vivek Anand 5827c9
        msg = pagure.lib.add_group_to_project(
Vivek Anand 5827c9
            session=self.session,
Vivek Anand 5827c9
            project=repo,
Vivek Anand 5827c9
            new_group='sysadmin',
Vivek Anand 5827c9
            user='pingou',
Vivek Anand 5827c9
            access='commit'
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
        self.assertEqual(msg, 'Group added')
Vivek Anand 5827c9
        msg = pagure.lib.add_group_to_project(
Vivek Anand 5827c9
            session=self.session,
Vivek Anand 5827c9
            project=repo,
Vivek Anand 5827c9
            new_group='devs',
Vivek Anand 5827c9
            user='pingou',
Vivek Anand 5827c9
            access='commit'
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
        self.assertEqual(msg, 'Group added')
Vivek Anand 5827c9
Vivek Anand 5827c9
        # Add an user to a project
Vivek Anand 5827c9
        msg = pagure.lib.add_user_to_project(
Vivek Anand 5827c9
            session=self.session,
Vivek Anand 5827c9
            project=repo,
Vivek Anand 5827c9
            new_user='foo',
Vivek Anand 5827c9
            user='pingou',
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
        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
Vivek Anand 5827c9
            name='test2',
Vivek Anand 5827c9
            description='test project #2',
Vivek Anand 5827c9
            is_fork=True,
Vivek Anand 5827c9
            parent_id=1,
Vivek Anand 5827c9
            hook_token='aaabbbvvv',
Vivek Anand 5827c9
        )
Vivek Anand 5827c9
        self.session.add(item)
Vivek Anand 5827c9
        self.session.commit()
Vivek Anand 5827c9
Vivek Anand 5827c9
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Vivek Anand 5827c9
Pierre-Yves Chibon 145998
        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 59a1eb
        #print data
Pierre-Yves Chibon 4fc47a
        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
Farhaan Bukhsh 6ccd40
        repo = pagure.lib._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 499752
        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 499752
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 499752
            session=self.session,
Pierre-Yves Chibon 499752
            project=repo,
Pierre-Yves Chibon 499752
            new_user='foo',
Pierre-Yves Chibon 499752
            user='pingou',
Pierre-Yves Chibon 499752
        )
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 499752
        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 499752
            name='test3',
Pierre-Yves Chibon 499752
            description='test project #2',
Pierre-Yves Chibon 499752
            is_fork=True,
Pierre-Yves Chibon 499752
            parent_id=1,
Pierre-Yves Chibon 499752
            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 499752
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 145998
        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 499752
        #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 b130e5
    @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
Farhaan Bukhsh 6ccd40
        repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 897409
        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 499752
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 499752
            session=self.session,
Pierre-Yves Chibon 499752
            project=repo,
Pierre-Yves Chibon 499752
            new_user='foo',
Pierre-Yves Chibon 499752
            user='pingou',
Pierre-Yves Chibon 499752
        )
Pierre-Yves Chibon 499752
        self.session.commit()
Pierre-Yves Chibon 499752
        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 499752
            name='test3',
Pierre-Yves Chibon 499752
            description='test project #2',
Pierre-Yves Chibon 499752
            is_fork=True,
Pierre-Yves Chibon 499752
            parent_id=1,
Pierre-Yves Chibon 499752
            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 499752
        outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon 499752
Pierre-Yves Chibon 145998
        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 499752
        #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 024459
    def test_commit_to_patch(self):
Pierre-Yves Chibon fe5017
        """ Test the commit_to_patch function of pagure.lib.git. """
Pierre-Yves Chibon 024459
        # Create a git repo to play with
Patrick Uiterwijk 170974
        self.gitrepo = os.path.join(self.path, 'repos', 'test_repo.git')
Pierre-Yves Chibon 024459
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon 024459
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Create a file in that git repo
Pierre-Yves Chibon 024459
        with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
Pierre-Yves Chibon 024459
            stream.write('foo\n bar')
Pierre-Yves Chibon 024459
        repo.index.add('sources')
Pierre-Yves Chibon 024459
        repo.index.write()
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Commits the files added
Pierre-Yves Chibon 024459
        tree = repo.index.write_tree()
Pierre-Yves Chibon 024459
        author = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 024459
        committer = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 024459
        repo.create_commit(
Pierre-Yves Chibon 024459
            'refs/heads/master',  # the name of the reference to update
Pierre-Yves Chibon 024459
            author,
Pierre-Yves Chibon 024459
            committer,
Pierre-Yves Chibon 024459
            'Add sources file for testing',
Pierre-Yves Chibon 024459
            # binary string representing the tree object ID
Pierre-Yves Chibon 024459
            tree,
Pierre-Yves Chibon 024459
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 024459
            []
Pierre-Yves Chibon 024459
        )
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        first_commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Edit the sources file again
Pierre-Yves Chibon 024459
        with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
Pierre-Yves Chibon 024459
            stream.write('foo\n bar\nbaz\n boose')
Pierre-Yves Chibon 024459
        repo.index.add('sources')
Pierre-Yves Chibon 024459
        repo.index.write()
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Commits the files added
Pierre-Yves Chibon 024459
        tree = repo.index.write_tree()
Pierre-Yves Chibon 024459
        author = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 024459
        committer = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 024459
        repo.create_commit(
Pierre-Yves Chibon 024459
            'refs/heads/master',  # the name of the reference to update
Pierre-Yves Chibon 024459
            author,
Pierre-Yves Chibon 024459
            committer,
Pierre-Yves Chibon 024459
            'Add baz and boose to the sources\n\n There are more objects to '
Pierre-Yves Chibon 024459
            'consider',
Pierre-Yves Chibon 024459
            # binary string representing the tree object ID
Pierre-Yves Chibon 024459
            tree,
Pierre-Yves Chibon 024459
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 024459
            [first_commit.oid.hex]
Pierre-Yves Chibon 024459
        )
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        second_commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Generate a patch for 2 commits
Pierre-Yves Chibon fe5017
        patch = pagure.lib.git.commit_to_patch(
Pierre-Yves Chibon 024459
            repo, [first_commit, second_commit])
Pierre-Yves Chibon 024459
        exp = """Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 024459
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 024459
Subject: [PATCH 1/2] Add sources file for testing
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
---
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
diff --git a/sources b/sources
Pierre-Yves Chibon 024459
new file mode 100644
Pierre-Yves Chibon 024459
index 0000000..9f44358
Pierre-Yves Chibon 024459
--- /dev/null
Pierre-Yves Chibon 024459
+++ b/sources
Pierre-Yves Chibon 024459
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 024459
+foo
Pierre-Yves Chibon 024459
+ bar
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 024459
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 024459
Subject: [PATCH 2/2] Add baz and boose to the sources
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
 There are more objects to consider
Pierre-Yves Chibon 024459
---
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
diff --git a/sources b/sources
Pierre-Yves Chibon 024459
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 024459
--- a/sources
Pierre-Yves Chibon 024459
+++ b/sources
Pierre-Yves Chibon 024459
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 024459
 foo
Pierre-Yves Chibon 024459
- bar
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
+ bar
Pierre-Yves Chibon 024459
+baz
Pierre-Yves Chibon 024459
+ boose
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
"""
Pierre-Yves Chibon 024459
        npatch = []
Pierre-Yves Chibon 024459
        for row in patch.split('\n'):
Pierre-Yves Chibon 024459
            if row.startswith('Date:'):
Pierre-Yves Chibon 024459
                continue
Pierre-Yves Chibon 024459
            if row.startswith('From '):
Pierre-Yves Chibon 024459
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon 024459
            npatch.append(row)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        patch = '\n'.join(npatch)
Pierre-Yves Chibon 024459
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Generate a patch for a single commit
Pierre-Yves Chibon fe5017
        patch = pagure.lib.git.commit_to_patch(repo, second_commit)
Pierre-Yves Chibon 024459
        exp = """Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 024459
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 024459
Subject: Add baz and boose to the sources
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
 There are more objects to consider
Pierre-Yves Chibon 024459
---
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
diff --git a/sources b/sources
Pierre-Yves Chibon 024459
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 024459
--- a/sources
Pierre-Yves Chibon 024459
+++ b/sources
Pierre-Yves Chibon 024459
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 024459
 foo
Pierre-Yves Chibon 024459
- bar
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
+ bar
Pierre-Yves Chibon 024459
+baz
Pierre-Yves Chibon 024459
+ boose
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
"""
Pierre-Yves Chibon 024459
        npatch = []
Pierre-Yves Chibon 024459
        for row in patch.split('\n'):
Pierre-Yves Chibon 024459
            if row.startswith('Date:'):
Pierre-Yves Chibon 024459
                continue
Pierre-Yves Chibon 024459
            if row.startswith('From '):
Pierre-Yves Chibon 024459
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon 024459
            npatch.append(row)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        patch = '\n'.join(npatch)
Pierre-Yves Chibon 024459
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon fe5017
    @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 c009bb
            name='test_ticket_repo',
Pierre-Yves Chibon c009bb
            description='test project for ticket',
Pierre-Yves Chibon e2259d
            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
Slavek Kabrda adea20
        self.gitrepo = os.path.join(self.path, 'repos', 'tickets',
Patrick Uiterwijk 170974
                                    'test_ticket_repo.git')
Patrick Uiterwijk 170974
        pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test_ticket_repo')
Pierre-Yves Chibon c009bb
        # Create an issue to play with
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon c009bb
            session=self.session,
Pierre-Yves Chibon c009bb
            repo=repo,
Pierre-Yves Chibon c009bb
            title='Test issue',
Pierre-Yves Chibon c009bb
            content='We should work on this',
Pierre-Yves Chibon c009bb
            user='pingou',
Slavek Kabrda adea20
            ticketfolder=os.path.join(self.path, 'repos', 'tickets')
Pierre-Yves Chibon c009bb
        )
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Patrick Uiterwijk 170974
        pagure.lib.git.update_git(issue, repo, os.path.join(self.path,
Slavek Kabrda adea20
                                                            'repos', 'tickets')).get()
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon c009bb
        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)
Pierre-Yves Chibon c009bb
        exp = """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
Mark Reynolds 23b4d2
@@ -0,0 +1,28 @@
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 = []
Slavek Kabrda adea20
        for row in commit_patch.split('\n'):
Pierre-Yves Chibon c009bb
            if row.startswith('Date:'):
Pierre-Yves Chibon c009bb
                continue
Pierre-Yves Chibon c009bb
            elif row.startswith('From '):
Pierre-Yves Chibon c009bb
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon c009bb
            elif row.startswith('diff --git '):
Pierre-Yves Chibon c009bb
                row = row.split(' ')
Pierre-Yves Chibon c009bb
                row[2] = 'a/123'
Pierre-Yves Chibon c009bb
                row[3] = 'b/456'
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon e64141
            elif 'Updated issue' in row:
Pierre-Yves Chibon c009bb
                row = row.split()
Pierre-Yves Chibon c009bb
                row[3] = '<hash>:'</hash>
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon c009bb
            elif 'date_created' in row:
Pierre-Yves Chibon 2e900f
                t = row.split(': ')[0]
Pierre-Yves Chibon 2e900f
                row = '%s: null,' % t
Mark Reynolds 23b4d2
            elif 'last_updated' in row:
Mark Reynolds 23b4d2
                t = row.split(': ')[0]
Mark Reynolds 23b4d2
                row = '%s: null,' % t
Vivek Anand d7285b
            elif 'closed_at' in row:
Vivek Anand d7285b
                t = row.split(': ')[0]
Vivek Anand d7285b
                row = '%s: null,' % t
Pierre-Yves Chibon c009bb
            elif row.startswith('index 00'):
Pierre-Yves Chibon c009bb
                row = 'index 0000000..60f7480'
Pierre-Yves Chibon c009bb
            elif row.startswith('+++ b/'):
Pierre-Yves Chibon c009bb
                row = '+++ b/456'
Pierre-Yves Chibon c009bb
            npatch.append(row)
Slavek Kabrda adea20
        commit_patch = '\n'.join(npatch)
Slavek Kabrda adea20
        #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
Slavek Kabrda adea20
        def _definitely_wait(result):
Slavek Kabrda adea20
            result.wait()
Slavek Kabrda adea20
Slavek Kabrda adea20
        with patch('pagure.lib.git._maybe_wait', _definitely_wait):
Slavek Kabrda adea20
            msg = pagure.lib.add_issue_comment(
Slavek Kabrda adea20
                session=self.session,
Slavek Kabrda adea20
                issue=issue,
Slavek Kabrda adea20
                comment='Hey look a comment!',
Slavek Kabrda adea20
                user='foo',
Slavek Kabrda adea20
                ticketfolder=os.path.join(self.path, 'repos', 'tickets')
Slavek Kabrda adea20
            )
Pierre-Yves Chibon c009bb
        self.session.commit()
Pierre-Yves Chibon c009bb
        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 c009bb
        commit = repo.revparse_single('HEAD')
Slavek Kabrda adea20
        commit_patch = pagure.lib.git.commit_to_patch(repo, commit)
Pierre-Yves Chibon c009bb
        exp = """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
Pierre-Yves Chibon b63f28
@@ -3,13 +3,31 @@
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
+    "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,
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 = []
Slavek Kabrda adea20
        for row in commit_patch.split('\n'):
Pierre-Yves Chibon c009bb
            if row.startswith('Date:'):
Pierre-Yves Chibon c009bb
                continue
Pierre-Yves Chibon c009bb
            elif row.startswith('From '):
Pierre-Yves Chibon c009bb
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon c009bb
            elif row.startswith('diff --git '):
Pierre-Yves Chibon c009bb
                row = row.split(' ')
Pierre-Yves Chibon c009bb
                row[2] = 'a/123'
Pierre-Yves Chibon c009bb
                row[3] = 'b/456'
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon e64141
            elif 'Updated issue' in row:
Pierre-Yves Chibon c009bb
                row = row.split()
Pierre-Yves Chibon c009bb
                row[3] = '<hash>:'</hash>
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon c009bb
            elif 'date_created' in row:
Vivek Anand d7285b
                t = row.split(': ')[0]
Vivek Anand d7285b
                row = '%s: null,' % t
Vivek Anand d7285b
            elif 'closed_at' in row:
Pierre-Yves Chibon 2e900f
                t = row.split(': ')[0]
Pierre-Yves Chibon 2e900f
                row = '%s: null,' % t
Pierre-Yves Chibon c009bb
            elif row.startswith('index'):
Pierre-Yves Chibon c009bb
                row = 'index 458821a..77674a8'
Pierre-Yves Chibon c009bb
            elif row.startswith('--- a/'):
Pierre-Yves Chibon c009bb
                row = '--- a/123'
Pierre-Yves Chibon c009bb
            elif row.startswith('+++ b/'):
Pierre-Yves Chibon c009bb
                row = '+++ b/456'
Pierre-Yves Chibon b63f28
            elif 'last_updated' in row:
Pierre-Yves Chibon b63f28
                t = row.split(': ')[0]
Pierre-Yves Chibon b63f28
                row = '%s: "<date>",' % t</date>
Pierre-Yves Chibon c009bb
            npatch.append(row)
Slavek Kabrda adea20
        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 be8028
        pagure.lib.git.clean_git(None, None, None)
Pierre-Yves Chibon be8028
Pierre-Yves Chibon e88bd7
        self.test_update_git()
Pierre-Yves Chibon e88bd7
Slavek Kabrda adea20
        gitpath = os.path.join(self.path, 'repos', 'tickets',
Slavek Kabrda adea20
                               'test_ticket_repo.git')
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 e88bd7
        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 e88bd7
        for row in patch.split('\n'):
Pierre-Yves Chibon e88bd7
            if row.startswith('+++ b/'):
Pierre-Yves Chibon e88bd7
                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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test_ticket_repo')
Pierre-Yves Chibon e88bd7
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Patrick Uiterwijk 170974
        pagure.lib.git.clean_git(issue, repo,
Patrick Uiterwijk 170974
                                 os.path.join(self.path, 'tickets')).get()
Pierre-Yves Chibon e88bd7
Pierre-Yves Chibon e88bd7
        # No more files in the git repo
Pierre-Yves Chibon e88bd7
        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 c070b4
    @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 c070b4
            name='test_ticket_repo',
Pierre-Yves Chibon c070b4
            description='test project for ticket',
Pierre-Yves Chibon e2259d
            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
Slavek Kabrda adea20
        self.gitrepo = os.path.join(self.path, 'repos', 'requests',
Patrick Uiterwijk 170974
                                    'test_ticket_repo.git')
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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test_ticket_repo')
Farhaan Bukhsh 72e9db
        # Create an issue to play with
Pierre-Yves Chibon f9c5f9
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon c070b4
            session=self.session,
Pierre-Yves Chibon c070b4
            repo_from=repo,
Pierre-Yves Chibon c070b4
            branch_from='feature',
Pierre-Yves Chibon c070b4
            repo_to=repo,
Pierre-Yves Chibon c070b4
            branch_to='master',
Pierre-Yves Chibon c070b4
            title='test PR',
Pierre-Yves Chibon c070b4
            user='pingou',
Patrick Uiterwijk 170974
            requestfolder=os.path.join(self.path, 'requests'),
Pierre-Yves Chibon c070b4
            requestuid='foobar',
Pierre-Yves Chibon c070b4
            requestid=None,
Pierre-Yves Chibon ff2972
            status='Open',
Pierre-Yves Chibon c070b4
            notify=True
Pierre-Yves Chibon c070b4
        )
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon f9c5f9
        self.assertEqual(req.title, 'test PR')
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        request = repo.requests[0]
Pierre-Yves Chibon c070b4
        self.assertEqual(request.title, 'test PR')
Patrick Uiterwijk 170974
        pagure.lib.git.update_git(request, request.project,
Patrick Uiterwijk 170974
                                  os.path.join(self.path, 'requests')).get()
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon c070b4
        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)
Pierre-Yves Chibon c070b4
        exp = """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
Slavek Kabrda c8fc0d
@@ -0,0 +1,139 @@
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 9d1556
+            "fedmsg_notifications": true,
Pierre-Yves Chibon 2e900f
+            "issue_tracker": true,
Pierre-Yves Chibon d0e87d
+            "issues_default_to_private": false,
Pierre-Yves Chibon baaf54
+            "notify_on_commit_flag": false,
Pierre-Yves Chibon baaf54
+            "notify_on_pull-request_flag": 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
+            "roadmap_on_issues_page": false,
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 9d1556
+            "fedmsg_notifications": true,
Pierre-Yves Chibon 2e900f
+            "issue_tracker": true,
Pierre-Yves Chibon d0e87d
+            "issues_default_to_private": false,
Pierre-Yves Chibon baaf54
+            "notify_on_commit_flag": false,
Pierre-Yves Chibon baaf54
+            "notify_on_pull-request_flag": 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
+            "roadmap_on_issues_page": false,
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 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 c070b4
        for row in patch.split('\n'):
Pierre-Yves Chibon c070b4
            if row.startswith('Date:'):
Pierre-Yves Chibon c070b4
                continue
Pierre-Yves Chibon c070b4
            elif row.startswith('From '):
Pierre-Yves Chibon c070b4
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon c070b4
            elif row.startswith('diff --git '):
Pierre-Yves Chibon c070b4
                row = row.split(' ')
Pierre-Yves Chibon c070b4
                row[2] = 'a/123'
Pierre-Yves Chibon c070b4
                row[3] = 'b/456'
Pierre-Yves Chibon c070b4
                row = ' '.join(row)
Pierre-Yves Chibon e64141
            elif 'Updated pull-request' in row:
Pierre-Yves Chibon c070b4
                row = row.split()
Pierre-Yves Chibon c070b4
                row[3] = '<hash>:'</hash>
Pierre-Yves Chibon c070b4
                row = ' '.join(row)
Pierre-Yves Chibon c070b4
            elif 'date_created' in row:
Pierre-Yves Chibon 2e900f
                t = row.split(': ')[0]
Pierre-Yves Chibon 2e900f
                row = '%s: null,' % t
Clement Verna cd6e30
            elif 'date_modified' in row:
Clement Verna cd6e30
                t = row.split(': ')[0]
Clement Verna cd6e30
                row = '%s: null,' % t
Mark Reynolds 23b4d2
            elif 'last_updated' in row:
Mark Reynolds 23b4d2
                t = row.split(': ')[0]
Mark Reynolds 23b4d2
                row = '%s: null,' % t
Pierre-Yves Chibon 44258a
            elif 'updated_on' in row:
Pierre-Yves Chibon 44258a
                t = row.split(': ')[0]
Pierre-Yves Chibon 44258a
                row = '%s: null,' % t
Pierre-Yves Chibon c070b4
            elif row.startswith('index 00'):
Pierre-Yves Chibon c070b4
                row = 'index 0000000..60f7480'
Pierre-Yves Chibon c070b4
            elif row.startswith('+++ b/'):
Pierre-Yves Chibon c070b4
                row = '+++ b/456'
Pierre-Yves Chibon c070b4
            npatch.append(row)
Pierre-Yves Chibon c070b4
        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 b130e5
        repo = pagure.lib.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 0a1494
            "status": "Open", "title": "foo", "comments": [],
Pierre-Yves Chibon 0a1494
            "content": "bar", "date_created": "1426500263",
Pierre-Yves Chibon 0a1494
            "user": {
Pierre-Yves Chibon 0a1494
                "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 7a6733
            reponame='foobar',
Pierre-Yves Chibon 7a6733
            namespace=None,
Pierre-Yves Chibon 7a6733
            username=None,
Pierre-Yves Chibon 7a6733
            issue_uid='foobar',
Pierre-Yves Chibon b7eec1
            json_data=data,
Pierre-Yves Chibon b7eec1
            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 7a6733
            "status": "Open", "title": "foo", "comments": [],
Pierre-Yves Chibon 7a6733
            "content": "bar", "date_created": "1426500263",
Pierre-Yves Chibon 7a6733
            "user": {
Pierre-Yves Chibon 7a6733
                "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 46750b
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar', json_data=data, 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 7a6733
            "status": "Open", "title": "foo", "comments": [],
Pierre-Yves Chibon 7a6733
            "content": "bar", "date_created": "1426500263",
Pierre-Yves Chibon 7a6733
            "user": {
Pierre-Yves Chibon 7a6733
                "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 0a1494
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar', json_data=data, 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 0a1494
        self.assertEqual(repo.issues[0].uid, 'foobar')
Pierre-Yves Chibon 0a1494
        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 0a1494
        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 75b7f9
            repo.milestones,
Aurélien Bompard 626417
            {'Next Release': {'active': True, 'date': None}})
Pierre-Yves Chibon 0a1494
Pierre-Yves Chibon b7eec1
    @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 b130e5
        repo = pagure.lib.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 b7eec1
            "user": {
Pierre-Yves Chibon b7eec1
                "name": "foo",
Pierre-Yves Chibon b7eec1
                "emails": ["foo@fedoraproject.org"]
Pierre-Yves Chibon b7eec1
            },
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 b7eec1
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar', json_data=data, 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 b7eec1
            "user": {
Pierre-Yves Chibon b7eec1
                "name": "foo",
Pierre-Yves Chibon b7eec1
                "emails": ["foo@fedoraproject.org"]
Pierre-Yves Chibon b7eec1
            },
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 b7eec1
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar', json_data=data, 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 b7eec1
        self.assertEqual(repo.issues[0].uid, 'foobar')
Pierre-Yves Chibon b7eec1
        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 b7eec1
        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 75b7f9
            repo.milestones,
Aurélien Bompard 626417
            {'Next Release': {'active': True, 'date': None}})
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues[0].status, 'Closed')
Pierre-Yves Chibon b7eec1
        self.assertEqual(repo.issues[0].close_status, 'Fixed')
Pierre-Yves Chibon b7eec1
        self.assertEqual(
Pierre-Yves Chibon b7eec1
            repo.issues[0].comments[-1].comment,
Pierre-Yves Chibon b7eec1
            '**Metadata Update from @pingou**:\n'
Pierre-Yves Chibon b7eec1
            '- Issue close_status updated to: Fixed\n'
Pierre-Yves Chibon b7eec1
            '- 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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 0a1494
        # Set some priorities to the project
Pierre-Yves Chibon 0a1494
        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 2bf847
            "status": "Open", "title": "foo", "comments": [],
Pierre-Yves Chibon 2bf847
            "content": "bar", "date_created": "1426500263",
Pierre-Yves Chibon 2bf847
            "user": {
Pierre-Yves Chibon 2bf847
                "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 2bf847
            reponame='foobar',
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon 2bf847
            username=None,
Pierre-Yves Chibon 2bf847
            issue_uid='foobar',
Pierre-Yves Chibon b7eec1
            json_data=data,
Pierre-Yves Chibon b7eec1
            agent='pingou',
Pierre-Yves Chibon 2bf847
        )
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 5abfd2
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar', json_data=data, 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 2bf847
        self.assertEqual(repo.issues[0].uid, 'foobar')
Pierre-Yves Chibon 2bf847
        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, [])
Clement Verna b30f33
        self.assertEqual(repo.issues[0].milestone, 'Next Release')
Mark Reynolds 7974f7
        self.assertEqual(repo.issues[0].priority, 1)
Pierre-Yves Chibon 75b7f9
        self.assertEqual(
Pierre-Yves Chibon 75b7f9
            repo.milestones,
Aurélien Bompard 626417
            {'Next Release': {'active': True, 'date': None}})
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 5abfd2
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar', json_data=data, 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 2bf847
        self.assertEqual(repo.issues[0].uid, 'foobar')
Pierre-Yves Chibon 2bf847
        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 2bf847
Pierre-Yves Chibon 2bf847
        data = {
Pierre-Yves Chibon fe5017
            "status": "Open", "title": "Rename pagure", "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 2bf847
                "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 2bf847
                    "date_created": "1426595224", "id": 250, "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 2bf847
                        "emails": ["pingou@fedoraproject.org"]
Pierre-Yves Chibon 2bf847
                    }
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 2bf847
                    "date_created": "1426595340", "id": 324, "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 2bf847
                        "emails": ["ralph@fedoraproject.org"]
Pierre-Yves Chibon 2bf847
                    }
Pierre-Yves Chibon 2bf847
                }
Pierre-Yves Chibon 2bf847
            ]
Pierre-Yves Chibon 2bf847
        }
Pierre-Yves Chibon 2bf847
Pierre-Yves Chibon fe5017
        pagure.lib.git.update_ticket_from_git(
Pierre-Yves Chibon 5abfd2
            self.session, reponame='test', namespace=None, username=None,
Pierre-Yves Chibon b7eec1
            issue_uid='foobar2', json_data=data, 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 2bf847
        self.assertEqual(repo.issues[0].uid, 'foobar')
Pierre-Yves Chibon 2bf847
        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 2bf847
        # New one
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[1].uid, 'foobar2')
Pierre-Yves Chibon fe5017
        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])
Clement Verna b30f33
        self.assertEqual(repo.issues[1].milestone, 'Future')
Aurélien Bompard f61bb3
        self.assertDictEqual(
Pierre-Yves Chibon 75b7f9
            repo.milestones,
Pierre-Yves Chibon 75b7f9
            {
Aurélien Bompard 626417
                'Future': {'active': True, 'date': None},
Aurélien Bompard 626417
                'Next Release': {'active': True, 'date': None}
Pierre-Yves Chibon 75b7f9
            }
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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon f692f5
Farhaan Bukhsh 83f8bc
        repo = pagure.lib._get_project(self.session, 'test')
Farhaan Bukhsh 83f8bc
        namespaced_repo = pagure.lib._get_project(self.session, 'test3', namespace='somenamespace')
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 700d02
                    "emails": [
Pierre-Yves Chibon 700d02
                        "pingou@fedoraproject.org"
Pierre-Yves Chibon 700d02
                    ]
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                "id": 1,
Pierre-Yves Chibon f692f5
                "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 f692f5
                "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 f692f5
                        "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 f692f5
                    "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 f692f5
                        "emails": [
Pierre-Yves Chibon f692f5
                            "pingou@fedoraproject.org"
Pierre-Yves Chibon f692f5
                        ]
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 f692f5
                    "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 f692f5
                        "emails": [
Pierre-Yves Chibon f692f5
                            "pingou@fedoraproject.org"
Pierre-Yves Chibon f692f5
                        ]
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 f692f5
                    "filename": "test2"
Pierre-Yves Chibon f692f5
                }
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 f692f5
                        "emails": [
Pierre-Yves Chibon 700d02
                            "pingou@fedoraproject.org"
Pierre-Yves Chibon f692f5
                        ]
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 f692f5
                    "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 f692f5
                    "emails": [
Pierre-Yves Chibon 700d02
                        "fake@fedoraproject.org"
Pierre-Yves Chibon f692f5
                    ]
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                "id": 6,
Pierre-Yves Chibon f692f5
                "description": "test project"
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "branch": "master",
Pierre-Yves Chibon f692f5
            "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 f692f5
            reponame='foobar',
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon f692f5
            username=None,
Pierre-Yves Chibon f692f5
            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 f692f5
            reponame='test',
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon f692f5
            username=None,
Pierre-Yves Chibon f692f5
            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 f692f5
            repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
Pierre-Yves Chibon f692f5
        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 700d02
                    "emails": [
Pierre-Yves Chibon 700d02
                        "pingou@fedoraproject.org"
Pierre-Yves Chibon 700d02
                    ]
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 f692f5
                "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 f692f5
                "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 f692f5
                        "emails": [
Pierre-Yves Chibon 700d02
                            "pingou@fedoraproject.org"
Pierre-Yves Chibon f692f5
                        ]
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 f692f5
                    "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 f692f5
                    "emails": [
Pierre-Yves Chibon 700d02
                        "fake@fedoraproject.org"
Pierre-Yves Chibon f692f5
                    ]
Pierre-Yves Chibon f692f5
                },
Pierre-Yves Chibon f692f5
                "project_docs": True,
Pierre-Yves Chibon f692f5
                "id": 6,
Pierre-Yves Chibon f692f5
                "description": "test project"
Pierre-Yves Chibon f692f5
            },
Pierre-Yves Chibon f692f5
            "branch": "master",
Pierre-Yves Chibon f692f5
            "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 f692f5
            reponame='test',
Pierre-Yves Chibon 5abfd2
            namespace=None,
Pierre-Yves Chibon f692f5
            username=None,
Pierre-Yves Chibon f692f5
            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 f692f5
            repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
Pierre-Yves Chibon f692f5
        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 f692f5
            repo.requests[1].uid, 'd4182a2ac2d541d884742d3037c26e57')
Pierre-Yves Chibon f692f5
        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",
clime afed57
                    "emails": [
clime afed57
                        "pingou@fedoraproject.org"
clime afed57
                    ]
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,
clime afed57
                "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",
clime afed57
                "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",
clime afed57
                        "emails": [
clime afed57
                            "pingou@fedoraproject.org"
clime afed57
                        ]
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,
clime afed57
                    "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",
clime afed57
                    "emails": [
clime afed57
                        "fake@fedoraproject.org"
clime afed57
                    ]
clime afed57
                },
clime afed57
                "project_docs": True,
clime afed57
                "id": 6,
clime afed57
                "description": "test project"
clime afed57
            },
clime afed57
            "branch": "master",
clime afed57
            "date_created": "1426843745"
clime afed57
        }
clime afed57
        pagure.lib.git.update_request_from_git(
clime afed57
            self.session,
clime afed57
            reponame='test3',
clime afed57
            namespace='somenamespace',
clime afed57
            username=None,
clime afed57
            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(
clime afed57
            namespaced_repo.requests[0].uid,
clime afed57
            'd4182a2ac2d541d884742d3037c26e58'
clime afed57
        )
clime afed57
        self.assertEqual(
clime afed57
            namespaced_repo.requests[0].title,
clime afed57
            'test request to namespaced repo'
clime afed57
        )
clime afed57
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
Slavek Kabrda adea20
        gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git')
Pierre-Yves Chibon 858b9d
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 858b9d
            ['log', '-1', "--pretty='%s'"], gitrepo)
Pierre-Yves Chibon 858b9d
        self.assertEqual(len(output), 1)
Pierre-Yves Chibon 858b9d
        self.assertTrue(
Pierre-Yves Chibon e64141
            output[0].startswith("'Updated issue ")
Pierre-Yves Chibon 858b9d
        )
Pierre-Yves Chibon 858b9d
        self.assertTrue(
Pierre-Yves Chibon 858b9d
            output[0].endswith(": Test issue'")
Pierre-Yves Chibon 858b9d
        )
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 858b9d
            ['log', '-1', "--pretty='%s'"], gitrepo, keepends=True)
Pierre-Yves Chibon 858b9d
        self.assertEqual(len(output), 1)
Pierre-Yves Chibon 858b9d
        self.assertTrue(
Pierre-Yves Chibon 858b9d
            output[0].endswith(": Test issue'\n")
Pierre-Yves Chibon 858b9d
        )
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
Slavek Kabrda adea20
        gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git')
Pierre-Yves Chibon 32fce0
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 32fce0
            ['log', '-3', "--pretty='%H'"], gitrepo)
Pierre-Yves Chibon 32fce0
        self.assertEqual(len(output), 2)
Pierre-Yves Chibon 32fce0
        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
Clement Verna 1901d5
        to_hash = '0'
Pierre-Yves Chibon 32fce0
        output1 = pagure.lib.git.get_revs_between(
Clement Verna f202e4
            to_hash, from_hash, gitrepo, 'refs/heads/master')
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)
Clement Verna 1901d5
        to_hash = output[0].replace("'", '')
Pierre-Yves Chibon 32fce0
        output2 = pagure.lib.git.get_revs_between(
Clement Verna f202e4
            to_hash, from_hash, gitrepo, 'refs/heads/master')
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(
Clement Verna f202e4
            from_hash, to_hash, gitrepo, 'refs/heads/master')
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
Clement Verna 469e2c
        newgitrepo = tempfile.mkdtemp(prefix='pagure-')
Clement Verna 469e2c
        newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
Clement Verna 469e2c
        newrepo.create_branch('feature', newrepo.head.get_object())
Clement Verna 469e2c
Clement Verna 469e2c
        with open(os.path.join(newgitrepo, 'sources'), 'w') as stream:
Clement Verna 469e2c
            stream.write('foo\n bar')
Clement Verna 469e2c
        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()
Clement Verna 469e2c
        author = pygit2.Signature(
Clement Verna 469e2c
            'Alice Author', 'alice@authors.tld')
Clement Verna 469e2c
        committer = pygit2.Signature(
Clement Verna 469e2c
            'Cecil Committer', 'cecil@committers.tld')
Clement Verna 469e2c
        newrepo.create_commit(
Clement Verna 469e2c
            'refs/heads/feature',  # the name of the reference to update
Clement Verna 469e2c
            author,
Clement Verna 469e2c
            committer,
Clement Verna 469e2c
            '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
Clement Verna 469e2c
            [to_hash]
Clement Verna 469e2c
        )
Clement Verna 469e2c
        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]
Clement Verna 469e2c
        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(
Clement Verna f202e4
            '0', branch_commit.oid.hex, gitrepo, 'refs/heads/feature')
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
Slavek Kabrda adea20
        gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test_ticket_repo.git')
Pierre-Yves Chibon 84cd98
        output = pagure.lib.git.read_git_lines(
Pierre-Yves Chibon 84cd98
            ['log', '-3', "--pretty='%H'"], gitrepo)
Pierre-Yves Chibon 84cd98
        self.assertEqual(len(output), 2)
Pierre-Yves Chibon 84cd98
        for githash in output:
Pierre-Yves Chibon 84cd98
            githash = githash.replace("'", '')
Pierre-Yves Chibon ad3d68
            output = pagure.lib.git.get_author(githash, gitrepo)
Pierre-Yves Chibon 84cd98
            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
Patrick Uiterwijk 170974
        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 f69b11
            ['log', '-3', "--pretty='%H'"], gitrepo)
Pierre-Yves Chibon f69b11
        self.assertEqual(len(output), 2)
Pierre-Yves Chibon f69b11
        for githash in output:
Pierre-Yves Chibon f69b11
            githash = githash.replace("'", '')
Pierre-Yves Chibon ad3d68
            output = pagure.lib.git.get_author_email(githash, gitrepo)
Pierre-Yves Chibon f69b11
            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. """
Patrick Uiterwijk 170974
        gitrepo = os.path.join(self.path, 'tickets', 'test_ticket_repo.git')
Pierre-Yves Chibon cf28b3
        repo_name = pagure.lib.git.get_repo_name(gitrepo)
Pierre-Yves Chibon cf28b3
        self.assertEqual(repo_name, 'test_ticket_repo')
Pierre-Yves Chibon cf28b3
Pierre-Yves Chibon cf28b3
        repo_name = pagure.lib.git.get_repo_name('foo/bar/baz/test.git')
Pierre-Yves Chibon cf28b3
        self.assertEqual(repo_name, 'test')
Pierre-Yves Chibon cf28b3
Pierre-Yves Chibon cf28b3
        repo_name = pagure.lib.git.get_repo_name('foo.test.git')
Pierre-Yves Chibon cf28b3
        self.assertEqual(repo_name, 'foo.test')
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. """
Patrick Uiterwijk 170974
        gitrepo = os.path.join(self.path, 'tickets', 'test_ticket_repo.git')
Pierre-Yves Chibon a7c15a
        repo_name = pagure.lib.git.get_username(gitrepo)
Pierre-Yves Chibon a7c15a
        self.assertEqual(repo_name, None)
Pierre-Yves Chibon a7c15a
Pierre-Yves Chibon a7c15a
        repo_name = pagure.lib.git.get_username('foo/bar/baz/test.git')
Pierre-Yves Chibon a7c15a
        self.assertEqual(repo_name, None)
Pierre-Yves Chibon a7c15a
Pierre-Yves Chibon a7c15a
        repo_name = pagure.lib.git.get_username('foo.test.git')
Pierre-Yves Chibon a7c15a
        self.assertEqual(repo_name, None)
Pierre-Yves Chibon a7c15a
Pierre-Yves Chibon a7c15a
        repo_name = pagure.lib.git.get_username(
Patrick Uiterwijk 170974
            os.path.join(self.path, 'repos', 'forks', 'pingou', 'foo.test.git'))
Pierre-Yves Chibon a7c15a
        self.assertEqual(repo_name, 'pingou')
Pierre-Yves Chibon a7c15a
Pierre-Yves Chibon 826fb9
        repo_name = pagure.lib.git.get_username(
Patrick Uiterwijk 170974
            os.path.join(self.path, 'repos', 'forks', 'pingou', 'bar/foo.test.git'))
Pierre-Yves Chibon 826fb9
        self.assertEqual(repo_name, 'pingou')
Pierre-Yves Chibon 826fb9
Pierre-Yves Chibon 826fb9
        repo_name = pagure.lib.git.get_username(os.path.join(
Patrick Uiterwijk 170974
            self.path, 'repos', 'forks', 'pingou', 'fooo/bar/foo.test.git'))
Pierre-Yves Chibon 826fb9
        self.assertEqual(repo_name, 'pingou')
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 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(
Jeremy Cline 20109f
            os.path.join(self.path, 'repos', 'test_ticket_repo.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, None)
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(
Jeremy Cline 20109f
            os.path.join(self.path, 'repos', 'foo/bar/baz/test.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, 'foo/bar/baz')
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(
Jeremy Cline 20109f
            os.path.join(self.path, 'repos', 'foo.test.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, None)
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
Jeremy Cline 20109f
            self.path, 'repos', 'forks', 'user', 'foo.test.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, None)
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
Jeremy Cline 20109f
            self.path, 'repos', 'forks', 'user', 'bar/foo.test.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, 'bar')
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
Jeremy Cline 20109f
            self.path, 'repos', 'forks', 'user', 'ns/bar/foo.test.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, 'ns/bar')
Pierre-Yves Chibon 0eb3ee
Pierre-Yves Chibon 0eb3ee
        repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
Jeremy Cline 20109f
            self.path, 'repos', 'forks', 'user', '/bar/foo.test.git'))
Pierre-Yves Chibon 0eb3ee
        self.assertEqual(repo_name, 'bar')
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)
Farhaan Bukhsh 940880
        repo = pagure.lib._get_project(self.session, 'test')
Vivek Anand 763ae5
Vivek Anand 763ae5
        # Create issues to play with
Vivek Anand 763ae5
        pagure.lib.new_issue(
Vivek Anand 763ae5
            session=self.session,
Vivek Anand 763ae5
            repo=repo,
Vivek Anand 763ae5
            title='Test issue',
Vivek Anand 763ae5
            content='We should work on this',
Vivek Anand 763ae5
            user='pingou',
Vivek Anand 763ae5
            ticketfolder=None,
Vivek Anand 763ae5
            issue_uid='someuid'
Vivek Anand 763ae5
        )
Vivek Anand 763ae5
        self.session.commit()
Vivek Anand 763ae5
Vivek Anand 763ae5
        issue = pagure.lib.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",
Vivek Anand 763ae5
                "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 a18547
            self.session, repo, issue, json_data)
Vivek Anand 763ae5
Vivek Anand 763ae5
        updated_issue = pagure.lib.get_issue_by_uid(self.session, 'someuid')
Vivek Anand 763ae5
Vivek Anand 763ae5
        self.assertEqual(updated_issue.to_json().get('custom_fields'), [])
Vivek Anand 763ae5
        custom_fields = [
Vivek Anand 763ae5
                {
Vivek Anand 763ae5
                    "name": "custom1",
Vivek Anand 763ae5
                    "key_type": "text",
Vivek Anand 763ae5
                    "value": "value1",
Pierre-Yves Chibon cb755e
                    "key_data": None,
Vivek Anand 763ae5
                },
Vivek Anand 763ae5
                {
Vivek Anand 763ae5
                    "name": "custom2",
Vivek Anand 763ae5
                    "key_type": "text",
Vivek Anand 763ae5
                    "value": "value2",
Pierre-Yves Chibon cb755e
                    "key_data": None,
Vivek Anand 763ae5
                }
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",
Vivek Anand 763ae5
                "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 a18547
            self.session, repo, issue, json_data)
Vivek Anand 763ae5
Vivek Anand 763ae5
        updated_issue = pagure.lib.get_issue_by_uid(self.session, 'someuid')
Vivek Anand 763ae5
Vivek Anand 763ae5
        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 a3fe59
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon a3fe59
    @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 a3fe59
        gitfolder = os.path.join(self.path, 'repos')
Pierre-Yves Chibon a3fe59
        docfolder = os.path.join(self.path, 'docs')
Pierre-Yves Chibon a3fe59
        ticketfolder = os.path.join(self.path, 'tickets')
Pierre-Yves Chibon a3fe59
        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 a3fe59
            name='test',
Pierre-Yves Chibon a3fe59
            description='test project',
Pierre-Yves Chibon a3fe59
            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 b130e5
        repo = pagure.lib.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 a3fe59
        os.makedirs(os.path.join(self.path, 'repos', 'forks', 'foo'))
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon a3fe59
        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
Aurélien Bompard a7f281
        task = pagure.lib.fork_project(
Pierre-Yves Chibon a3fe59
            session=self.session,
Pierre-Yves Chibon a3fe59
            user='foo',
Pierre-Yves Chibon a3fe59
            repo=repo,
Pierre-Yves Chibon a3fe59
            gitfolder=gitfolder,
Pierre-Yves Chibon a3fe59
            docfolder=docfolder,
Pierre-Yves Chibon a3fe59
            ticketfolder=ticketfolder,
Pierre-Yves Chibon a3fe59
            requestfolder=requestfolder,
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon a3fe59
        self.session.commit()
Aurélien Bompard a7f281
        self.assertEqual(task.get(),
Pierre-Yves Chibon b130e5
                         {'endpoint': 'ui_ns.view_repo',
Patrick Uiterwijk 170974
                          'repo': 'test',
Patrick Uiterwijk 170974
                          'username': 'foo',
Patrick Uiterwijk 170974
                          'namespace': None})
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 a3fe59
            self.path, 'repos', 'forks', 'foo', 'test.git')
Pierre-Yves Chibon a3fe59
        tests.add_content_git_repo(self.gitrepo, branch='feature')
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon b130e5
        fork_repo = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
Pierre-Yves Chibon a3fe59
        # Create a PR to play with
Pierre-Yves Chibon a3fe59
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon a3fe59
            session=self.session,
Pierre-Yves Chibon a3fe59
            repo_from=fork_repo,
Pierre-Yves Chibon a3fe59
            branch_from='feature',
Pierre-Yves Chibon a3fe59
            repo_to=repo,
Pierre-Yves Chibon a3fe59
            branch_to='master',
Pierre-Yves Chibon a3fe59
            title='test PR',
Pierre-Yves Chibon a3fe59
            user='pingou',
Patrick Uiterwijk 170974
            requestfolder=os.path.join(self.path, 'requests'),
Pierre-Yves Chibon a3fe59
            requestuid='foobar',
Pierre-Yves Chibon a3fe59
            requestid=None,
Pierre-Yves Chibon a3fe59
            status='Open',
Pierre-Yves Chibon a3fe59
            notify=True
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon a3fe59
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon a3fe59
        self.assertEqual(req.title, 'test PR')
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon d972d9
        # `master` branch not found
Pierre-Yves Chibon a3fe59
        self.assertRaises(
Pierre-Yves Chibon a3fe59
            pagure.exceptions.PagureException,
Pierre-Yves Chibon a3fe59
            pagure.lib.git.merge_pull_request,
Pierre-Yves Chibon a3fe59
            self.session,
Pierre-Yves Chibon a3fe59
            request=req,
Pierre-Yves Chibon a3fe59
            username='pingou',
Pierre-Yves Chibon a3fe59
            request_folder=os.path.join(self.path, 'requests'),
Pierre-Yves Chibon a3fe59
            domerge=False
Pierre-Yves Chibon a3fe59
        )
Pierre-Yves Chibon a3fe59
Pierre-Yves Chibon 99d493
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 99d493
    @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 99d493
        gitfolder = os.path.join(self.path, 'repos')
Pierre-Yves Chibon 99d493
        docfolder = os.path.join(self.path, 'docs')
Pierre-Yves Chibon 99d493
        ticketfolder = os.path.join(self.path, 'tickets')
Pierre-Yves Chibon 99d493
        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 99d493
            name='test',
Pierre-Yves Chibon 99d493
            description='test project',
Pierre-Yves Chibon 99d493
            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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 99d493
        gitrepo = os.path.join(gitfolder, repo.path)
Pierre-Yves Chibon 99d493
        docrepo = os.path.join(docfolder, repo.path)
Pierre-Yves Chibon 99d493
        ticketrepo = os.path.join(ticketfolder, repo.path)
Pierre-Yves Chibon 99d493
        requestrepo = os.path.join(requestfolder, repo.path)
Pierre-Yves Chibon 99d493
        os.makedirs(os.path.join(self.path, 'repos', 'forks', 'foo'))
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        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 99d493
        tests.add_content_git_repo(self.gitrepo, branch='master')
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon 99d493
        # Fork the project
Aurélien Bompard a7f281
        task = pagure.lib.fork_project(
Pierre-Yves Chibon 99d493
            session=self.session,
Pierre-Yves Chibon 99d493
            user='foo',
Pierre-Yves Chibon 99d493
            repo=repo,
Pierre-Yves Chibon 99d493
            gitfolder=gitfolder,
Pierre-Yves Chibon 99d493
            docfolder=docfolder,
Pierre-Yves Chibon 99d493
            ticketfolder=ticketfolder,
Pierre-Yves Chibon 99d493
            requestfolder=requestfolder,
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
        self.session.commit()
Aurélien Bompard a7f281
        self.assertEqual(task.get(),
Pierre-Yves Chibon b130e5
                         {'endpoint': 'ui_ns.view_repo',
Pierre-Yves Chibon 99d493
                          'repo': 'test',
Pierre-Yves Chibon 99d493
                          'username': 'foo',
Pierre-Yves Chibon 99d493
                          'namespace': None})
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 99d493
            self.path, 'repos', 'forks', 'foo', 'test.git')
Pierre-Yves Chibon 99d493
        tests.add_content_git_repo(self.gitrepo, branch='feature')
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon b130e5
        fork_repo = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
Pierre-Yves Chibon 99d493
        # Create a PR to play with
Pierre-Yves Chibon 99d493
        req = pagure.lib.new_pull_request(
Pierre-Yves Chibon 99d493
            session=self.session,
Pierre-Yves Chibon 99d493
            repo_from=fork_repo,
Pierre-Yves Chibon 99d493
            branch_from='feature',
Pierre-Yves Chibon 99d493
            repo_to=repo,
Pierre-Yves Chibon 99d493
            branch_to='master',
Pierre-Yves Chibon 99d493
            title='test PR',
Pierre-Yves Chibon 99d493
            user='pingou',
Pierre-Yves Chibon 99d493
            requestfolder=os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 99d493
            requestuid='foobar',
Pierre-Yves Chibon 99d493
            requestid=None,
Pierre-Yves Chibon 99d493
            status='Open',
Pierre-Yves Chibon 99d493
            notify=True
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 99d493
        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 99d493
        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 99d493
            '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 99d493
            username='pingou',
Pierre-Yves Chibon 99d493
            request_folder=os.path.join(self.path, 'requests'),
Pierre-Yves Chibon 99d493
            domerge=False
Pierre-Yves Chibon 99d493
        )
Pierre-Yves Chibon 99d493
Pierre-Yves Chibon be6a91
    @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 b130e5
        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 145998
        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 be6a91
            'HOME=/tmp gitolite compile && '
Pierre-Yves Chibon be6a91
            'HOME=/tmp gitolite trigger POST_COMPILE',
Pierre-Yves Chibon be6a91
            cwd='/tmp', shell=True, stderr=-1, 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(
Slavek Kabrda 595b6f
                '0000000000000000000000000000000000000000',
Slavek Kabrda 595b6f
                '^0e6e0b6c931d65ee22f67205a53933d841c6eeff',
Slavek Kabrda 595b6f
                'path/is/not/important'
Slavek Kabrda 595b6f
            )
Slavek Kabrda 595b6f
        )
Slavek Kabrda 595b6f
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
if __name__ == '__main__':
Pierre-Yves Chibon be6a91
    unittest.main(verbosity=2)