Ejemplo n.º 1
0
 def test_repo_already_exists(self):
     from_dir = ".%d" % random.randint(1,100)
     self.cleanup_dirs = [from_dir,]
     git = 'git'
     with open('/dev/null','w') as output:
         operations.create_repository(git, output, output, output, from_dir)
         self.assertRaises(KittyGitRepoExists, operations.create_repository, git, output, output, output, from_dir)
Ejemplo n.º 2
0
    def test_operation_successful(self):
        test_dir = self.test_dir
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % test_dir
        test_settings = fake_settings(settings_str)

        repo_name = 'something-%d' % random.randint(0, 100)
        full_repo_name = 'random-user-%d/%s' % (random.randint(0, 100), repo_name)

        directory = '%s/%s.git' % (test_dir, full_repo_name)
        with open('/dev/null', 'w') as output:
            operations.create_repository('git', output, output, output, directory)

        other_user = '******' % random.randint(0, 100)
        with open('/dev/null', 'w') as out_stream:
            with open('/dev/null', 'w') as err_stream:
                streams = (sys.stdin, out_stream, err_stream)
                random_root_patterns = random.randint(1, 100)
                request = Request(other_user, 'kitty-git fork', test_settings, streams, random_root_patterns)
                expected_dir = os.path.expanduser('%s/%s/%s.git' % (test_dir, other_user, repo_name))
                result = handlers.fork_repo(request, full_repo_name)

        self.assertTrue(isinstance(result, Response))
        self.assertTrue(repo_name in result.content['message'])
        self.assertTrue(os.path.isdir(directory))
        self.assertTrue(os.path.isdir(expected_dir))
Ejemplo n.º 3
0
 def test_actually_forks_repository(self):
     from_dir, to_dir = ".%d" % random.randint(1,100), ".o%d" % random.randint(1,100)
     self.cleanup_dirs = [from_dir, to_dir]
     git = 'git'
     with open('/dev/null','w') as output:
         operations.create_repository(git, output, output, output, from_dir)
         result = operations.fork_repository(git, output, output, output, from_dir, to_dir)
         self.assertTrue(isinstance(result, bool))
         self.assertTrue(result)
         self.assertTrue(os.path.exists('/'.join([to_dir, 'config']))) 
Ejemplo n.º 4
0
def create_repo(request, repo_name, template_dir=None):
    auth = request.auth_backend
    settings = get_settings(request)
    if auth.has_permission(request.user, ('kittygit','create')):
        auth.add_permission(request.user, ('kittygit','write','%s/%s' % (request.user, repo_name)))
        auth.add_permission(request.user, ('kittygit', 'read', '%s/%s' % (request.user, repo_name)))

        full_repo_dir = get_full_repo_dir(settings, request.user, repo_name)
        success = operations.create_repository(
            settings.get('git', 'git'),
            request.stdin,
            request.stdout,
            request.stderr,
            full_repo_dir,
            template_dir
        )
        if success:
            clone_base = get_clone_base_url(settings)
            clone_path = '/'.join([request.user, repo_name]) + '.git'
            return Success({
                'message':"""
                    Successfully created a new repository. Clone it at %s:%s
                """.strip() % (clone_base, clone_path),
                'clone_path':clone_path
            })
        else:
            raise NappingCatException('Create repo failed.') 
    raise KittyGitUnauthorized('You don\'t have permission to create a repo.')
Ejemplo n.º 5
0
 def test_repo_can_create_non_bare(self):
     from_dir = ".%d" % random.randint(1,100)
     self.cleanup_dirs = [from_dir,]
     git = 'git'
     with open('/dev/null','w') as output:
         result = operations.create_repository(git, output, output, output, from_dir, bare=False)
         time.sleep(1)
         self.assertTrue(os.path.exists(os.path.join(from_dir, '.git/config')))
Ejemplo n.º 6
0
    def test_successful(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % self.test_dir
        test_settings = fake_settings(settings_str)
        user = '******' % random.randint(0, 100)
        repo_name = str(random.randint(0,100))
        repo = '%s/%s.git' % (user, repo_name)
        variants = (
            ("git-upload-pack '%s'", "-upload-pack "),
            ("git upload-pack '%s'", " upload-pack "),
            ("git-receive-pack '%s'", "-receive-pack "),
            ("git receive-pack '%s'", " receive-pack "),
        )

        streams = (sys.stdin, sys.stdout, sys.stderr)
        for cmd, action in variants:
            random_root_patterns = random.randint(1, 100)
            request = Request(user, cmd % repo, test_settings, streams, random_root_patterns)
            path = utils.get_full_repo_dir(handlers.get_settings(request), user, repo_name)
            with open('/dev/null', 'w') as output:
                operations.create_repository('git', output, output, output, path, bare=True)
            self.mox.StubOutWithMock(subprocess, 'call')
            subprocess.call(
                args=['git', 'shell', '-c', ' '.join(['git%s'%action.strip(), "'%s'"%path])],
                cwd=path,
                stdout=sys.stdout,
                stderr=sys.stderr,
                stdin=sys.stdin,
            ).AndReturn(0)
            self.mox.ReplayAll()
            result = handlers.handle_git(request, action)

            self.assertTrue(isinstance(result, Response))
            self.assertTrue(user in str(result))
            self.assertTrue(repo_name in str(result))
            self.mox.UnsetStubs()
            shutil.rmtree(path)
Ejemplo n.º 7
0
 def test_repo_can_create_with_templates(self):
     from_dir = ".%d" % random.randint(1,100)
     self.cleanup_dirs = [from_dir,]
     git = 'git'
     with open('/dev/null','w') as output:
         result = operations.create_repository(git, output, output, output, from_dir, 'tests/support')
         hook_path = os.path.join(from_dir, 'hooks/post-commit')
         orig_path = 'tests/support/hooks/post-commit'
         self.assertTrue(os.path.exists(hook_path))
         lhs, rhs = open(hook_path, 'r'), open(orig_path, 'r')
         lhs_results, rhs_results = lhs.read(), rhs.read()
         self.assertEqual(lhs_results, rhs_results)
         lhs.close(); rhs.close()