示例#1
0
    def test_operation_successful(self):
        test_dir = self.test_dir
        settings_str = (
            """
[kittyconfig]
auth = tests.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)
                request = Request(other_user, "kitty-git fork", test_settings, streams)
                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, str))
        self.assertTrue(repo_name in result)
        self.assertTrue(os.path.isdir(directory))
        self.assertTrue(os.path.isdir(expected_dir))
示例#2
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)
示例#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']))) 
示例#4
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')))
示例#5
0
    def test_successful(self):
        settings_str = (
            """
[kittyconfig]
auth = tests.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:
            request = Request(user, cmd % repo, test_settings, streams)
            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, str))
            self.assertTrue(user in result)
            self.assertTrue(repo_name in result)
            self.mox.UnsetStubs()
            shutil.rmtree(path)
示例#6
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()
示例#7
0
def create_repo(request, repo_name, template_dir=None):
    settings = get_settings(request)
    if auth.has_permission(request, request.user, ('kittygit','create')):
        auth.add_permission(request, request.user, ('kittygit','write','%s/%s' % (request.user, repo_name)))
        auth.add_permission(request, 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)
            return """
                Successfully created a new repository. Clone it at %s:%s.git
            """.strip() % (clone_base, '/'.join([request.user, repo_name]))
        else:
            raise NappingCatException('Create repo failed.') 
    raise KittyGitUnauthorized('You don\'t have permission to create a repo.')