#22 Simplify the gitolite rules for forks and add tests for them and flake8 fixes
Merged 7 years ago by pingou. Opened 7 years ago by pingou.

file modified
+7 -4
@@ -116,13 +116,16 @@ 

              if project.is_fork:

                  access = 'RW+C'

  

-             if repos == '':

+             if repos == '' and not project.is_fork:

                  # First, whitelist the supported branches from PDC

-                 for branch in get_supported_branches(project.namespace, project.name):

-                     config.append('  %s %s = %s' % (access, branch, project.user.user))

+                 for branch in get_supported_branches(

+                         project.namespace, project.name):

+                     config.append('  %s %s = %s' % (

+                         access, branch, project.user.user))

                      for user in project.committers:

                          if user != project.user:

-                             config.append('  %s %s = %s' % (access, branch, user.user))

+                             config.append('  %s %s = %s' % (

+                                 access, branch, user.user))

  

                  # Then, blacklist a pattern over that (after).

                  config.append(_blacklist)

file modified
+88 -2
@@ -6,7 +6,8 @@ 

  import mock

  

  # These are the tests from the pagure/ git repo.

- # Run with PYTHONPATH=.:/path/to/pagure/checkout nosetests dist_git_auth_tests.py

+ # Run with:

+ # PYTHONPATH=.:/path/to/pagure/checkout nosetests dist_git_auth_tests.py

  import pagure

  import tests

  
@@ -211,7 +212,7 @@ 

  

      def test_get_supported_branches(self):

          """ Test for real what is returned by PDC. """

-         expected = ['master', 'f26', 'f25', 'f24', 'el6']

+         expected = ['master', 'f26', 'f25', 'el6']

          actual = dist_git_auth.get_supported_branches('rpms', 'nethack')

          self.assertEquals(set(actual), set(expected))

  
@@ -313,3 +314,88 @@ 

  

  # end of body'''

          self.assertMultiLineEqual(expected, contents.strip())

+ 

+     @mock.patch('dist_git_auth.get_supported_branches')

+     def test_write_gitolite_acls_fork(

+             self, get_supported_branches):

+         """ Test updating the gitolite configuration file when forking a

+         project.

+ 

+         """

+ 

+         get_supported_branches.return_value = ['master', 'f9000']

+         self.test_write_gitolite_acls()

+ 

+         print("Forking the test project.")

+         project = pagure.lib._get_project(self.session, 'test')

+         pagure.lib.fork_project(

+             session=self.session,

+             user='pingou',

+             repo=project,

+             gitfolder=self.path,

+             docfolder=None,

+             ticketfolder=None,

+             requestfolder=None)

+ 

+         print("Rewriting %r" % self.configfile)

+         dist_git_auth.DistGitoliteAuth.write_gitolite_acls(

+             self.session,

+             configfile=self.configfile,

+             project=-1

+         )

+ 

+         print("Checking the contents of %r" % self.configfile)

+         with open(self.configfile, 'r') as f:

+             contents = f.read()

+ 

+         expected = '''repo test

+   R   = @all

+   RWC master = pingou

+   RWC f9000 = pingou

+   -    f[0-9][0-9] = @all

+   -    epel[0-9] = @all

+   -    epel[0-9][0-9] = @all

+   -    el[0-9] = @all

+   -    olpc[0-9] = @all

+   RWC = pingou

+ 

+ repo requests/test

+   RWC = pingou

+ 

+ repo test2

+   R   = @all

+   RWC master = pingou

+   RWC f9000 = pingou

+   -    f[0-9][0-9] = @all

+   -    epel[0-9] = @all

+   -    epel[0-9][0-9] = @all

+   -    el[0-9] = @all

+   -    olpc[0-9] = @all

+   RWC = pingou

+ 

+ repo requests/test2

+   RWC = pingou

+ 

+ repo somenamespace/test3

+   R   = @all

+   RWC master = pingou

+   RWC f9000 = pingou

+   -    f[0-9][0-9] = @all

+   -    epel[0-9] = @all

+   -    epel[0-9][0-9] = @all

+   -    el[0-9] = @all

+   -    olpc[0-9] = @all

+   RWC = pingou

+ 

+ repo requests/somenamespace/test3

+   RWC = pingou

+ 

+ repo forks/pingou/test

+   R   = @all

+   RW+C = pingou

+ 

+ repo requests/forks/pingou/test

+   RW+C = pingou

+ 

+ # end of body'''

+         self.assertMultiLineEqual(expected, contents.strip())

file modified
-3
@@ -1,8 +1,5 @@ 

  from setuptools import setup

  

- import sys

- import os

- 

  f = open('README.rst')

  long_description = f.read().strip()

  long_description = long_description.split('split here', 1)[1]