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 b63f28
 (c) 2015-2017 - Copyright Red Hat Inc
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
 Authors:
Pierre-Yves Chibon a945ba
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
"""
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 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
Pierre-Yves Chibon a945ba
from mock import patch
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
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 a7c15a
    def setUp(self):
Pierre-Yves Chibon a7c15a
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon a7c15a
        super(PagureLibGittests, self).setUp()
Pierre-Yves Chibon a7c15a
Pierre-Yves Chibon fd747d
        pagure.lib.git.SESSION = self.session
Pierre-Yves Chibon fd747d
        pagure.APP.config['GIT_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'repos')
Pierre-Yves Chibon fd747d
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'tickets')
Pierre-Yves Chibon fd747d
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'docs')
Pierre-Yves Chibon fd747d
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'requests')
Pierre-Yves Chibon a7c15a
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 fe5017
        repo = pagure.lib.get_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 fe5017
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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 0c1d74
        exp = """
Pierre-Yves Chibon 0c1d74
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 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
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
Patrick Uiterwijk faa79d
        repo = pagure.lib.get_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
Patrick Uiterwijk faa79d
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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
Patrick Uiterwijk faa79d
        exp = """
Patrick Uiterwijk faa79d
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
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
Vivek Anand 2897c2
        repo = pagure.lib.get_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
Vivek Anand 2897c2
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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
Vivek Anand 2897c2
        exp = """
Vivek Anand 2897c2
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
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
Vivek Anand 994729
        repo = pagure.lib.get_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
Vivek Anand 994729
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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
Vivek Anand 994729
        exp = """
Vivek Anand 994729
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
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 4fc47a
        repo = pagure.lib.get_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 4fc47a
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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 4fc47a
        exp = """@sysadmin   = pingou
Pierre-Yves Chibon 6f5851
@devs   = pingou
Pierre-Yves Chibon 4fc47a
Pierre-Yves Chibon 4fc47a
repo test
Pierre-Yves Chibon 4fc47a
  R   = @all
Pierre-Yves Chibon 6f5851
  RW+ = @sysadmin @devs
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 6f5851
  RW+ = @sysadmin @devs
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 6f5851
  RW+ = @sysadmin @devs
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 6f5851
  RW+ = @sysadmin @devs
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
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
Vivek Anand 1edd2c
        repo = pagure.lib.get_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
Vivek Anand 1edd2c
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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
Vivek Anand 1edd2c
        exp = """
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
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
Vivek Anand 5827c9
        repo = pagure.lib.get_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
Vivek Anand 5827c9
        pagure.lib.git.write_gitolite_acls(self.session, outputconf)
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
Vivek Anand 5827c9
        exp = """@sysadmin   = pingou
Vivek Anand 5827c9
@devs   = pingou
Vivek Anand 5827c9
Vivek Anand 5827c9
repo test
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = @sysadmin @devs
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo docs/test
Vivek Anand 5827c9
  R   = @all
Vivek Anand 5827c9
  RW+ = @sysadmin @devs
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo tickets/test
Vivek Anand 5827c9
  RW+ = @sysadmin @devs
Vivek Anand 5827c9
  RW+ = pingou
Vivek Anand 5827c9
  RW+ = foo
Vivek Anand 5827c9
Vivek Anand 5827c9
repo requests/test
Vivek Anand 5827c9
  RW+ = @sysadmin @devs
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 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 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
Jeremy Cline 20109f
        self.gitrepo = os.path.join(self.path, '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')
Pierre-Yves Chibon d2faf2
    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
Jeremy Cline 20109f
        self.gitrepo = os.path.join(self.path, 'test_ticket_repo.git')
Pierre-Yves Chibon c009bb
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon c009bb
        repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_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',
Jeremy Cline 20109f
            ticketfolder=self.path
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)
Jeremy Cline 20109f
        pagure.lib.git.update_git(issue, repo, self.path)
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
Pierre-Yves Chibon fe5017
        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 = []
Pierre-Yves Chibon c009bb
        for row in 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)
Pierre-Yves Chibon c009bb
        patch = '\n'.join(npatch)
Pierre-Yves Chibon df35d8
        #print patch
Pierre-Yves Chibon c009bb
        self.assertEqual(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
Pierre-Yves Chibon fe5017
        msg = pagure.lib.add_issue_comment(
Pierre-Yves Chibon c009bb
            session=self.session,
Pierre-Yves Chibon c009bb
            issue=issue,
Pierre-Yves Chibon c009bb
            comment='Hey look a comment!',
Pierre-Yves Chibon c009bb
            user='foo',
Jeremy Cline 20109f
            ticketfolder=self.path
Pierre-Yves Chibon c009bb
        )
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')
Pierre-Yves Chibon fe5017
        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 = []
Pierre-Yves Chibon c009bb
        for row in 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)
Pierre-Yves Chibon c009bb
        patch = '\n'.join(npatch)
Pierre-Yves Chibon 3fe986
        #print patch
Pierre-Yves Chibon c009bb
        self.assertEqual(patch, exp)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon e88bd7
    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
Jeremy Cline 20109f
        gitpath = os.path.join(self.path, '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 e88bd7
        repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
Pierre-Yves Chibon e88bd7
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Jeremy Cline 20109f
        pagure.lib.git.clean_git(issue, repo, self.path)
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')
Pierre-Yves Chibon c070b4
    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
Jeremy Cline 20109f
        self.gitrepo = os.path.join(self.path, 'test_ticket_repo.git')
Pierre-Yves Chibon c070b4
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon c070b4
        repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon c070b4
Pierre-Yves Chibon c070b4
        repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
Pierre-Yves Chibon a3fe59
        # Create a PR 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',
Jeremy Cline 20109f
            requestfolder=self.path,
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')
Jeremy Cline 20109f
        pagure.lib.git.update_git(request, request.project, self.path)
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
Mark Reynolds 23b4d2
@@ -0,0 +1,96 @@
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 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": {
Pierre-Yves Chibon f254bf
+        "close_status": [],
Pierre-Yves Chibon 022564
+        "custom_keys": [],
Pierre-Yves Chibon 2e900f
+        "date_created": null,
Pierre-Yves Chibon 2e900f
+        "description": "test project for ticket",
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 e994c4
+            "project_documentation": false,
Pierre-Yves Chibon 2e900f
+            "pull_requests": true
Pierre-Yves Chibon 2e900f
+        },
Pierre-Yves Chibon a30916
+        "tags": [],
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": {
Pierre-Yves Chibon f254bf
+        "close_status": [],
Pierre-Yves Chibon 022564
+        "custom_keys": [],
Pierre-Yves Chibon 2e900f
+        "date_created": null,
Pierre-Yves Chibon 2e900f
+        "description": "test project for ticket",
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 e994c4
+            "project_documentation": false,
Pierre-Yves Chibon 2e900f
+            "pull_requests": true
Pierre-Yves Chibon 2e900f
+        },
Pierre-Yves Chibon a30916
+        "tags": [],
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
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)
Pierre-Yves Chibon c070b4
        #print patch
Pierre-Yves Chibon c070b4
        self.assertEqual(patch, exp)
Pierre-Yves Chibon c070b4
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 fe5017
        repo = pagure.lib.get_project(self.session, 'test')
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 2bf847
            json_data=data
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 2bf847
            issue_uid='foobar', json_data=data
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 2bf847
        self.assertEqual(repo.issues[0].depends_text, [])
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[0].blocks_text, [])
Clement Verna b30f33
        self.assertEqual(repo.issues[0].milestone, 'Next Release')
Mark Reynolds 7974f7
        self.assertEqual(repo.issues[0].priority, 1)
Clement Verna b30f33
        self.assertEqual(repo.milestones, {'Next Release': 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 2bf847
            issue_uid='foobar', json_data=data
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 2bf847
        self.assertEqual(repo.issues[0].depends_text, [])
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[0].blocks_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- "
Pierre-Yves Chibon 2bf847
                    "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- "
Pierre-Yves Chibon 2bf847
                    "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 2bf847
            issue_uid='foobar2', json_data=data
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 2bf847
        self.assertEqual(repo.issues[0].depends_text, [20])
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[0].blocks_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 2bf847
        self.assertEqual(repo.issues[1].depends_text, [])
Pierre-Yves Chibon 2bf847
        self.assertEqual(repo.issues[1].blocks_text, [1])
Clement Verna b30f33
        self.assertEqual(repo.issues[1].milestone, 'Future')
Clement Verna b30f33
        self.assertEqual(repo.milestones, {'Future': None, 'Next Release': None})
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
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
clime afed57
        namespaced_repo = pagure.lib.get_project(
clime afed57
            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,
Jeremy Cline 20109f
            gitfolder=self.path,
Jeremy Cline 20109f
            docfolder=os.path.join(self.path, 'docs'),
Jeremy Cline 20109f
            ticketfolder=os.path.join(self.path, 'tickets'),
Jeremy Cline 20109f
            requestfolder=os.path.join(self.path, 'requests')
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,
Jeremy Cline 20109f
            gitfolder=self.path,
Jeremy Cline 20109f
            docfolder=os.path.join(self.path, 'docs'),
Jeremy Cline 20109f
            ticketfolder=os.path.join(self.path, 'tickets'),
Jeremy Cline 20109f
            requestfolder=os.path.join(self.path, 'requests')
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,
Jeremy Cline 20109f
            gitfolder=self.path,
Jeremy Cline 20109f
            docfolder=os.path.join(self.path, 'docs'),
Jeremy Cline 20109f
            ticketfolder=os.path.join(self.path, 'tickets'),
Jeremy Cline 20109f
            requestfolder=os.path.join(self.path, 'requests')
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
            gitfolder=self.path,
clime afed57
            docfolder=os.path.join(self.path, 'docs'),
clime afed57
            ticketfolder=os.path.join(self.path, 'tickets'),
clime afed57
            requestfolder=os.path.join(self.path, 'requests')
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
Pierre-Yves Chibon 858b9d
    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
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, '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
Pierre-Yves Chibon 32fce0
    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
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, '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
Pierre-Yves Chibon ad3d68
    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
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, '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
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, '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. """
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, '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. """
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, '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(
Jeremy Cline 20109f
            os.path.join(self.path, '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(
Jeremy Cline 20109f
            os.path.join(self.path, '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(
Jeremy Cline 20109f
            self.path, '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)
Vivek Anand 763ae5
        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 a3fe59
        repo = pagure.lib.get_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
Pierre-Yves Chibon a3fe59
        msg = 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()
Pierre-Yves Chibon a3fe59
        self.assertEqual(
Pierre-Yves Chibon a3fe59
            msg, 'Repo "test" cloned to "foo/test"')
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 a3fe59
        fork_repo = pagure.lib.get_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',
Pierre-Yves Chibon a3fe59
            requestfolder=self.path,
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 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 a945ba
Pierre-Yves Chibon a945ba
if __name__ == '__main__':
Pierre-Yves Chibon fe5017
    SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibGittests)
Pierre-Yves Chibon a945ba
    unittest.TextTestRunner(verbosity=2).run(SUITE)