Blame tests/test_pagure_lib_gitolite_config.py

Pierre-Yves Chibon 274e60
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
"""
Pierre-Yves Chibon 274e60
 (c) 2017 - Copyright Red Hat Inc
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
 Authors:
Pierre-Yves Chibon 274e60
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
"""
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
import pkg_resources
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
import datetime
Pierre-Yves Chibon 274e60
import os
Pierre-Yves Chibon 274e60
import shutil
Pierre-Yves Chibon 274e60
import sys
Pierre-Yves Chibon 274e60
import tempfile
Pierre-Yves Chibon 274e60
import time
Pierre-Yves Chibon 274e60
import unittest
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
import pygit2
Pierre-Yves Chibon 274e60
from mock import patch, MagicMock
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 274e60
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
import pagure
Pierre-Yves Chibon 274e60
import pagure.lib.git
Pierre-Yves Chibon 274e60
import tests
Pierre-Yves Chibon 274e60
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
CORE_CONFIG = """repo test
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/test
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/test
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/test
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo test2
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/test2
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/test2
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/test2
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo somenamespace/test3
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/somenamespace/test3
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/somenamespace/test3
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/somenamespace/test3
Pierre-Yves Chibon 274e60
  RW+ = pingou"""
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
class PagureLibGitoliteConfigtests(tests.Modeltests):
Pierre-Yves Chibon 274e60
    """ Tests for pagure.lib.git """
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
    maxDiff = None
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon 274e60
    def setUp(self):
Pierre-Yves Chibon 274e60
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 274e60
        super(PagureLibGitoliteConfigtests, self).setUp()
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        tests.create_projects(self.session)
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        self.outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        self.preconf = os.path.join(self.path, 'header_gitolite')
Pierre-Yves Chibon 274e60
        with open(self.preconf, 'w') as stream:
Pierre-Yves Chibon 274e60
            stream.write('# this is a header that is manually added\n')
Pierre-Yves Chibon 274e60
            stream.write('\n')
Pierre-Yves Chibon 274e60
            stream.write('@group1 = foo bar baz\n')
Pierre-Yves Chibon 274e60
            stream.write('@group2 = threebean puiterwijk kevin pingou\n')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        self.postconf = os.path.join(self.path, 'footer_gitolite')
Pierre-Yves Chibon 274e60
        with open(self.postconf, 'w') as stream:
Pierre-Yves Chibon 274e60
            stream.write('# end of generated configuration\n')
Pierre-Yves Chibon 274e60
            stream.write('# \ó/\n')
Pierre-Yves Chibon 274e60
            stream.write('# end of footer\n')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
    def tearDown(self):
Pierre-Yves Chibon 274e60
        """ Tearn down the environnment, ran before every tests. """
Pierre-Yves Chibon 274e60
        super(PagureLibGitoliteConfigtests, self).tearDown()
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        if os.path.exists(self.outputconf):
Pierre-Yves Chibon 274e60
            os.unlink(self.outputconf)
Pierre-Yves Chibon 274e60
        self.assertFalse(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
    def test_write_gitolite_pre_post_projectNone(self):
Pierre-Yves Chibon 274e60
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon 274e60
        a postconf set """
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 274e60
            self.session,
Pierre-Yves Chibon 274e60
            self.outputconf,
Pierre-Yves Chibon 274e60
            project=None,
Pierre-Yves Chibon 274e60
            preconf=self.preconf,
Pierre-Yves Chibon 274e60
            postconf=self.postconf
Pierre-Yves Chibon 274e60
        )
Pierre-Yves Chibon 274e60
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
@group1 = foo bar baz
Pierre-Yves Chibon 274e60
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon 274e60
%s
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 274e60
# end of generated configuration
Pierre-Yves Chibon 274e60
# \ó/
Pierre-Yves Chibon 274e60
# end of footer
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
""" % CORE_CONFIG
Pierre-Yves Chibon 274e60
        #print data
Pierre-Yves Chibon 274e60
        self.assertEqual(data, exp)
Pierre-Yves Chibon 274e60
Lubomír Sedlář a25e58
    def test_write_gitolite_pre_post_projectNone_to_existing_file(self):
Pierre-Yves Chibon 274e60
        """ Test the write_gitolite_acls function of pagure.lib.git with
Lubomír Sedlář a25e58
        a postconf set with existing output file """
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon 274e60
            pass
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 274e60
            self.session,
Pierre-Yves Chibon 274e60
            self.outputconf,
Pierre-Yves Chibon 274e60
            project=None,
Pierre-Yves Chibon 274e60
            preconf=self.preconf,
Pierre-Yves Chibon 274e60
            postconf=self.postconf
Pierre-Yves Chibon 274e60
        )
Pierre-Yves Chibon 274e60
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf) as stream:
Pierre-Yves Chibon 274e60
            data = stream.read()
Pierre-Yves Chibon 274e60
        self.assertEqual(data, '')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
    def test_write_gitolite_pre_post_project_1(self):
Pierre-Yves Chibon 274e60
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon 274e60
        a postconf set """
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon 274e60
            pass
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 274e60
            self.session,
Pierre-Yves Chibon 274e60
            self.outputconf,
Pierre-Yves Chibon 274e60
            project=-1,
Pierre-Yves Chibon 274e60
            preconf=self.preconf,
Pierre-Yves Chibon 274e60
            postconf=self.postconf
Pierre-Yves Chibon 274e60
        )
Pierre-Yves Chibon 274e60
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
@group1 = foo bar baz
Pierre-Yves Chibon 274e60
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon 274e60
%s
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 274e60
# end of generated configuration
Pierre-Yves Chibon 274e60
# \ó/
Pierre-Yves Chibon 274e60
# end of footer
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
""" % CORE_CONFIG
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        #print data
Pierre-Yves Chibon 274e60
        self.assertEqual(data, exp)
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
    def test_write_gitolite_pre_post_project_test(self):
Pierre-Yves Chibon 274e60
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon 274e60
        a postconf set """
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon 274e60
            pass
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 274e60
            self.session,
Pierre-Yves Chibon 274e60
            self.outputconf,
Pierre-Yves Chibon 274e60
            project=project,
Pierre-Yves Chibon 274e60
            preconf=self.preconf,
Pierre-Yves Chibon 274e60
            postconf=self.postconf
Pierre-Yves Chibon 274e60
        )
Pierre-Yves Chibon 274e60
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
@group1 = foo bar baz
Pierre-Yves Chibon 274e60
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon 274e60
repo test
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/test
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/test
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/test
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 274e60
# end of generated configuration
Pierre-Yves Chibon 274e60
# \ó/
Pierre-Yves Chibon 274e60
# end of footer
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
"""
Pierre-Yves Chibon 274e60
        #print data
Pierre-Yves Chibon 274e60
        self.assertEqual(data, exp)
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
    def test_write_gitolite_pre_post_project_test_full_file(self):
Pierre-Yves Chibon 274e60
        """ Test the write_gitolite_acls function of pagure.lib.git with
Pierre-Yves Chibon 274e60
        a postconf set """
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        # Re-generate the gitolite config for all the projects
Pierre-Yves Chibon 274e60
        self.test_write_gitolite_pre_post_project_1()
Pierre-Yves Chibon 274e60
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 274e60
        project.user_id = 2
Pierre-Yves Chibon 274e60
        self.session.add(project)
Pierre-Yves Chibon 274e60
        self.session.commit()
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 274e60
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 274e60
            self.session,
Pierre-Yves Chibon 274e60
            project=project,
Pierre-Yves Chibon 274e60
            new_user='pingou',
Pierre-Yves Chibon 274e60
            user='foo',
Pierre-Yves Chibon 274e60
            access='commit'
Pierre-Yves Chibon 274e60
        )
Pierre-Yves Chibon 274e60
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 274e60
        self.session.commit()
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 274e60
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 274e60
        helper.write_gitolite_acls(
Pierre-Yves Chibon 274e60
            self.session,
Pierre-Yves Chibon 274e60
            self.outputconf,
Pierre-Yves Chibon 274e60
            project=project,
Pierre-Yves Chibon 274e60
            preconf=self.preconf,
Pierre-Yves Chibon 274e60
            postconf=self.postconf
Pierre-Yves Chibon 274e60
        )
Pierre-Yves Chibon 274e60
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
@group1 = foo bar baz
Pierre-Yves Chibon 274e60
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon 274e60
repo test2
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/test2
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/test2
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/test2
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo somenamespace/test3
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/somenamespace/test3
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/somenamespace/test3
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/somenamespace/test3
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo test
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = foo
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo docs/test
Pierre-Yves Chibon 274e60
  R   = @all
Pierre-Yves Chibon 274e60
  RW+ = foo
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo tickets/test
Pierre-Yves Chibon 274e60
  RW+ = foo
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
repo requests/test
Pierre-Yves Chibon 274e60
  RW+ = foo
Pierre-Yves Chibon 274e60
  RW+ = pingou
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon ccb160
# end of generated configuration
Pierre-Yves Chibon ccb160
# \ó/
Pierre-Yves Chibon ccb160
# end of footer
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
"""
Pierre-Yves Chibon ccb160
        #print data
Pierre-Yves Chibon ccb160
        self.assertEqual(data, exp)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
class PagureLibGitoliteGroupConfigtests(tests.Modeltests):
Pierre-Yves Chibon ccb160
    """ Tests for generating the gitolite configuration file for a group
Pierre-Yves Chibon ccb160
    change
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    """
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    maxDiff = None
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    def setUp(self):
Pierre-Yves Chibon ccb160
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon ccb160
        super(PagureLibGitoliteGroupConfigtests, self).setUp()
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        pagure.lib.git.SESSION = self.session
Pierre-Yves Chibon ccb160
        tests.create_projects(self.session)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        pagure.lib.add_group(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            group_name='grp',
Pierre-Yves Chibon ccb160
            display_name='grp group',
Pierre-Yves Chibon ccb160
            description=None,
Pierre-Yves Chibon ccb160
            group_type='user',
Pierre-Yves Chibon ccb160
            user='pingou',
Pierre-Yves Chibon ccb160
            is_admin=False,
Pierre-Yves Chibon ccb160
            blacklist=[],
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        pagure.lib.add_group(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            group_name='grp2',
Pierre-Yves Chibon ccb160
            display_name='grp2 group',
Pierre-Yves Chibon ccb160
            description=None,
Pierre-Yves Chibon ccb160
            group_type='user',
Pierre-Yves Chibon ccb160
            user='foo',
Pierre-Yves Chibon ccb160
            is_admin=False,
Pierre-Yves Chibon ccb160
            blacklist=[],
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.session.commit()
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        self.outputconf = os.path.join(self.path, 'test_gitolite.conf')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        self.preconf = os.path.join(self.path, 'header_gitolite')
Pierre-Yves Chibon ccb160
        with open(self.preconf, 'w') as stream:
Pierre-Yves Chibon ccb160
            stream.write('# this is a header that is manually added\n')
Pierre-Yves Chibon ccb160
            stream.write('\n')
Pierre-Yves Chibon ccb160
            stream.write('@group1 = foo bar baz\n')
Pierre-Yves Chibon ccb160
            stream.write('@group2 = threebean puiterwijk kevin pingou\n')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        self.postconf = os.path.join(self.path, 'footer_gitolite')
Pierre-Yves Chibon ccb160
        with open(self.postconf, 'w') as stream:
Pierre-Yves Chibon ccb160
            stream.write('# end of generated configuration\n')
Pierre-Yves Chibon ccb160
            stream.write('# \ó/\n')
Pierre-Yves Chibon ccb160
            stream.write('# end of footer\n')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    def tearDown(self):
Pierre-Yves Chibon ccb160
        """ Tearn down the environnment, ran before every tests. """
Pierre-Yves Chibon ccb160
        super(PagureLibGitoliteGroupConfigtests, self).tearDown()
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        if os.path.exists(self.outputconf):
Pierre-Yves Chibon ccb160
            os.unlink(self.outputconf)
Pierre-Yves Chibon ccb160
        self.assertFalse(os.path.exists(self.outputconf))
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    def test_write_gitolite_project_test_group(self):
Pierre-Yves Chibon ccb160
        """ Test the write_gitolite_acls when updating a single group. """
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon ccb160
            pass
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon ccb160
        group = pagure.lib.search_groups(self.session, group_name='grp')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon ccb160
        helper.write_gitolite_acls(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            self.outputconf,
Pierre-Yves Chibon ccb160
            project=project,
Pierre-Yves Chibon ccb160
            preconf=self.preconf,
Pierre-Yves Chibon ccb160
            postconf=self.postconf,
Pierre-Yves Chibon ccb160
            group=group,
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
@group1 = foo bar baz
Pierre-Yves Chibon ccb160
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon ccb160
@grp  = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo test
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo docs/test
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo tickets/test
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo requests/test
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon ccb160
# end of generated configuration
Pierre-Yves Chibon ccb160
# \ó/
Pierre-Yves Chibon ccb160
# end of footer
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
"""
Pierre-Yves Chibon ccb160
        #print data
Pierre-Yves Chibon ccb160
        self.assertEqual(data, exp)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    def test_write_gitolite_project_test_all_groups(self):
Pierre-Yves Chibon ccb160
        """ Test the write_gitolite_acls when updating all groups. """
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon ccb160
            pass
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon ccb160
        helper.write_gitolite_acls(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            self.outputconf,
Pierre-Yves Chibon ccb160
            project=project,
Pierre-Yves Chibon ccb160
            preconf=self.preconf,
Pierre-Yves Chibon ccb160
            postconf=self.postconf,
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
@group1 = foo bar baz
Pierre-Yves Chibon ccb160
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon ccb160
@grp  = pingou
Aurélien Bompard f61bb3
@grp2  = foo
Pierre-Yves Chibon ccb160
# end of groups
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo test
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo docs/test
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo tickets/test
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo requests/test
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon ccb160
# end of generated configuration
Pierre-Yves Chibon ccb160
# \ó/
Pierre-Yves Chibon ccb160
# end of footer
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
"""
Pierre-Yves Chibon ccb160
        #print data
Pierre-Yves Chibon ccb160
        self.assertEqual(data, exp)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    def test_write_gitolite_project_all_projects_groups(self):
Pierre-Yves Chibon ccb160
        """ Test the generating the entire gitolite config. """
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon ccb160
            pass
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon ccb160
        helper.write_gitolite_acls(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            self.outputconf,
Pierre-Yves Chibon ccb160
            project=-1,
Pierre-Yves Chibon ccb160
            preconf=self.preconf,
Pierre-Yves Chibon ccb160
            postconf=self.postconf,
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
@group1 = foo bar baz
Pierre-Yves Chibon ccb160
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon ccb160
@grp  = pingou
Aurélien Bompard f61bb3
@grp2  = foo
Pierre-Yves Chibon ccb160
# end of groups
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
%s
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon ccb160
# end of generated configuration
Pierre-Yves Chibon ccb160
# \ó/
Pierre-Yves Chibon ccb160
# end of footer
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
""" % CORE_CONFIG
Pierre-Yves Chibon ccb160
        #print data
Pierre-Yves Chibon ccb160
        self.assertEqual(data, exp)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
    def test_write_gitolite_project_all_projects_one_group(self):
Pierre-Yves Chibon ccb160
        """ Test the generating the entire gitolite config. """
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        # Generate the full gitolite config that we will update
Pierre-Yves Chibon ccb160
        self.test_write_gitolite_project_all_projects_groups()
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon ccb160
        group = pagure.lib.search_groups(self.session, group_name='grp')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        # Let's add `foo` to `grp` so something changes
Pierre-Yves Chibon ccb160
        msg = pagure.lib.add_user_to_group(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            username='foo',
Pierre-Yves Chibon ccb160
            group=group,
Pierre-Yves Chibon ccb160
            user='pingou',
Pierre-Yves Chibon ccb160
            is_admin=False,
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.session.commit()
Pierre-Yves Chibon ccb160
        self.assertEqual(msg, 'User `foo` added to the group `grp`.')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        # Let's add `foo` to `test` so the project changes as well
Pierre-Yves Chibon ccb160
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            project=project,
Pierre-Yves Chibon ccb160
            new_user='foo',
Pierre-Yves Chibon ccb160
            user='pingou',
Pierre-Yves Chibon ccb160
            access='commit'
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon ccb160
        self.session.commit()
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon ccb160
        helper.write_gitolite_acls(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            self.outputconf,
Pierre-Yves Chibon ccb160
            project=project,
Pierre-Yves Chibon ccb160
            group=group,
Pierre-Yves Chibon ccb160
            preconf=self.preconf,
Pierre-Yves Chibon ccb160
            postconf=self.postconf,
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
@group1 = foo bar baz
Pierre-Yves Chibon ccb160
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon ccb160
@grp  = foo pingou
Aurélien Bompard f61bb3
@grp2  = foo
Pierre-Yves Chibon ccb160
# end of groups
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo test2
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo docs/test2
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo tickets/test2
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo requests/test2
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo somenamespace/test3
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo docs/somenamespace/test3
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo tickets/somenamespace/test3
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo requests/somenamespace/test3
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo test
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
  RW+ = foo
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo docs/test
Pierre-Yves Chibon ccb160
  R   = @all
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
  RW+ = foo
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo tickets/test
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
  RW+ = foo
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
repo requests/test
Pierre-Yves Chibon ccb160
  RW+ = pingou
Pierre-Yves Chibon ccb160
  RW+ = foo
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon 274e60
# end of generated configuration
Pierre-Yves Chibon 274e60
# \ó/
Pierre-Yves Chibon 274e60
# end of footer
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
"""
Pierre-Yves Chibon 274e60
        #print data
Pierre-Yves Chibon 274e60
        self.assertEqual(data, exp)
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon ccb160
    def test_write_gitolite_delete_group(self):
Pierre-Yves Chibon ccb160
        """ Test the updating the gitolite config after having
Pierre-Yves Chibon ccb160
        deleted a group.
Pierre-Yves Chibon ccb160
        """
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        # Generate the full gitolite config that we will update
Pierre-Yves Chibon ccb160
        self.test_write_gitolite_project_all_projects_groups()
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        # Delete the group `grp`
Pierre-Yves Chibon ccb160
        self.assertEqual(len(pagure.lib.search_groups(self.session)), 2)
Pierre-Yves Chibon ccb160
        group = pagure.lib.search_groups(self.session, group_name='grp')
Pierre-Yves Chibon ccb160
        self.session.delete(group)
Pierre-Yves Chibon ccb160
        self.session.commit()
Pierre-Yves Chibon ccb160
        self.assertEqual(len(pagure.lib.search_groups(self.session)), 1)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon ccb160
        helper.write_gitolite_acls(
Pierre-Yves Chibon ccb160
            self.session,
Pierre-Yves Chibon ccb160
            self.outputconf,
Pierre-Yves Chibon ccb160
            project=None,
Pierre-Yves Chibon ccb160
            preconf=self.preconf,
Pierre-Yves Chibon ccb160
            postconf=self.postconf,
Pierre-Yves Chibon ccb160
        )
Pierre-Yves Chibon ccb160
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        with open(self.outputconf) as stream:
Pierre-Yves Chibon ccb160
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
        exp = u"""# this is a header that is manually added
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
@group1 = foo bar baz
Pierre-Yves Chibon ccb160
@group2 = threebean puiterwijk kevin pingou
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of header
Pierre-Yves Chibon ccb160
@grp2  = foo
Pierre-Yves Chibon ccb160
# end of groups
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
%s
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
# end of body
Pierre-Yves Chibon ccb160
# end of generated configuration
Pierre-Yves Chibon ccb160
# \ó/
Pierre-Yves Chibon ccb160
# end of footer
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon ccb160
""" % CORE_CONFIG
Pierre-Yves Chibon ccb160
        #print data
Pierre-Yves Chibon ccb160
        self.assertEqual(data, exp)
Pierre-Yves Chibon ccb160
Pierre-Yves Chibon b31a79
    @patch('pagure.lib.git_auth.get_git_auth_helper')
Pierre-Yves Chibon b31a79
    def test_task_generate_gitolite_acls_one_group(self, get_helper):
Pierre-Yves Chibon b31a79
        """ Test the generate_gitolite_acls task to ensure if group is None
Pierre-Yves Chibon b31a79
        then None is passed to the helper. """
Pierre-Yves Chibon b31a79
        helper = MagicMock()
Pierre-Yves Chibon b31a79
        get_helper.return_value = helper
Pierre-Yves Chibon b31a79
        pagure.lib.SESSIONMAKER = self.session.session_factory
Pierre-Yves Chibon b31a79
Pierre-Yves Chibon b31a79
        pagure.lib.tasks.generate_gitolite_acls(
Pierre-Yves Chibon 20a73c
            namespace=None, name='test', user=None, group=None)
Pierre-Yves Chibon b31a79
Pierre-Yves Chibon b31a79
        get_helper.assert_called_with('gitolite3')
Pierre-Yves Chibon b31a79
        args = helper.generate_acls.call_args
Pierre-Yves Chibon b31a79
        self.assertIsNone(args[1].get('group'))
Pierre-Yves Chibon a324b4
        self.assertIsNotNone(args[1].get('project'))
Pierre-Yves Chibon b31a79
Stefan Bühler c92108
    def test_write_gitolite_project_test_private(self):
Stefan Bühler c92108
        """ Test the write_gitolite_acls function of pagure.lib.git with
Stefan Bühler c92108
        a postconf set """
Stefan Bühler c92108
Stefan Bühler c92108
        # Make the test project private
Stefan Bühler c92108
        project = pagure.lib._get_project(self.session, 'test')
Stefan Bühler c92108
        project.private = True
Stefan Bühler c92108
        self.session.add(project)
Stefan Bühler c92108
        self.session.commit()
Stefan Bühler c92108
Stefan Bühler c92108
        # Re-generate the gitolite config just for this project
Stefan Bühler c92108
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Stefan Bühler c92108
        helper.write_gitolite_acls(
Stefan Bühler c92108
            self.session,
Stefan Bühler c92108
            self.outputconf,
Stefan Bühler c92108
            project=None,
Stefan Bühler c92108
        )
Stefan Bühler c92108
        self.assertTrue(os.path.exists(self.outputconf))
Stefan Bühler c92108
Stefan Bühler c92108
        with open(self.outputconf) as stream:
Stefan Bühler c92108
            data = stream.read().decode('utf-8')
Stefan Bühler c92108
Aurélien Bompard f61bb3
        exp = u"""@grp  = pingou
Aurélien Bompard f61bb3
@grp2  = foo
Stefan Bühler c92108
# end of groups
Stefan Bühler c92108
Stefan Bühler c92108
repo test
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo docs/test
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo tickets/test
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo requests/test
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo test2
Stefan Bühler c92108
  R   = @all
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo docs/test2
Stefan Bühler c92108
  R   = @all
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo tickets/test2
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo requests/test2
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo somenamespace/test3
Stefan Bühler c92108
  R   = @all
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo docs/somenamespace/test3
Stefan Bühler c92108
  R   = @all
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo tickets/somenamespace/test3
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
repo requests/somenamespace/test3
Stefan Bühler c92108
  RW+ = pingou
Stefan Bühler c92108
Stefan Bühler c92108
# end of body
Stefan Bühler c92108
"""
Stefan Bühler c92108
        #print data
Stefan Bühler c92108
        self.assertEqual(data, exp)
Stefan Bühler c92108
Pierre-Yves Chibon 5b06f7
    def test_remove_acls(self):
Pierre-Yves Chibon 5b06f7
        """ Test the remove_acls function of pagure.lib.git when deleting
Pierre-Yves Chibon 5b06f7
        a project """
Pierre-Yves Chibon b130e5
        pagure.config.config['GITOLITE_CONFIG'] = self.outputconf
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon 5b06f7
            pass
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 5b06f7
        helper.write_gitolite_acls(
Pierre-Yves Chibon 5b06f7
            self.session,
Pierre-Yves Chibon 5b06f7
            self.outputconf,
Pierre-Yves Chibon 5b06f7
            project=-1,
Pierre-Yves Chibon 5b06f7
        )
Pierre-Yves Chibon 5b06f7
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        with open(self.outputconf) as stream:
Pierre-Yves Chibon 5b06f7
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 5b06f7
Aurélien Bompard f61bb3
        exp = u"""@grp  = pingou
Aurélien Bompard f61bb3
@grp2  = foo
Pierre-Yves Chibon 5b06f7
# end of groups
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
%s
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
# end of body
Pierre-Yves Chibon 5b06f7
""" % CORE_CONFIG
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        #print data
Pierre-Yves Chibon 5b06f7
        self.assertEqual(data, exp)
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        # Test removing a project from the existing config
Pierre-Yves Chibon b130e5
        project = pagure.lib.get_authorized_project(
Pierre-Yves Chibon 5b06f7
            self.session, project_name='test')
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        helper.remove_acls(self.session, project=project)
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        with open(self.outputconf) as stream:
Pierre-Yves Chibon 5b06f7
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 5b06f7
Aurélien Bompard f61bb3
        exp = u"""@grp  = pingou
Aurélien Bompard f61bb3
@grp2  = foo
Pierre-Yves Chibon 5b06f7
# end of groups
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo test2
Pierre-Yves Chibon 5b06f7
  R   = @all
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo docs/test2
Pierre-Yves Chibon 5b06f7
  R   = @all
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo tickets/test2
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo requests/test2
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo somenamespace/test3
Pierre-Yves Chibon 5b06f7
  R   = @all
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo docs/somenamespace/test3
Pierre-Yves Chibon 5b06f7
  R   = @all
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo tickets/somenamespace/test3
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
repo requests/somenamespace/test3
Pierre-Yves Chibon 5b06f7
  RW+ = pingou
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
# end of body
Pierre-Yves Chibon 5b06f7
"""
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        #print data
Pierre-Yves Chibon 5b06f7
        self.assertEqual(data, exp)
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
    def test_remove_acls_no_project(self):
Pierre-Yves Chibon 5b06f7
        """ Test the remove_acls function of pagure.lib.git when no project
Pierre-Yves Chibon 5b06f7
        is specified """
Pierre-Yves Chibon b130e5
        pagure.config.config['GITOLITE_CONFIG'] = self.outputconf
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        with open(self.outputconf, 'w') as stream:
Pierre-Yves Chibon 5b06f7
            pass
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
Pierre-Yves Chibon 5b06f7
        helper.write_gitolite_acls(
Pierre-Yves Chibon 5b06f7
            self.session,
Pierre-Yves Chibon 5b06f7
            self.outputconf,
Pierre-Yves Chibon 5b06f7
            project=-1,
Pierre-Yves Chibon 5b06f7
        )
Pierre-Yves Chibon 5b06f7
        self.assertTrue(os.path.exists(self.outputconf))
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        with open(self.outputconf) as stream:
Pierre-Yves Chibon 5b06f7
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 5b06f7
Aurélien Bompard f61bb3
        exp = u"""@grp  = pingou
Aurélien Bompard f61bb3
@grp2  = foo
Pierre-Yves Chibon 5b06f7
# end of groups
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
%s
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
# end of body
Pierre-Yves Chibon 5b06f7
""" % CORE_CONFIG
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        #print data
Pierre-Yves Chibon 5b06f7
        self.assertEqual(data, exp)
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        # Test nothing changes if no project is specified
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        self.assertRaises(
Pierre-Yves Chibon 5b06f7
            RuntimeError,
Pierre-Yves Chibon 5b06f7
            helper.remove_acls,
Pierre-Yves Chibon 5b06f7
            self.session,
Pierre-Yves Chibon 5b06f7
            project=None
Pierre-Yves Chibon 5b06f7
        )
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        with open(self.outputconf) as stream:
Pierre-Yves Chibon 5b06f7
            data = stream.read().decode('utf-8')
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 5b06f7
        self.assertEqual(data, exp)
Pierre-Yves Chibon 5b06f7
Pierre-Yves Chibon 274e60
Pierre-Yves Chibon 274e60
if __name__ == '__main__':
Pierre-Yves Chibon 274e60
    unittest.main(verbosity=2)