예제 #1
0
    def test_success_with_template_dir(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 = "repo-%d" % random.randint(0, 100)
        repo = "%s/%s.git" % (user, repo_name)
        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(user, "kitty-git create-repo 'repo'", test_settings, streams)
                settings = handlers.get_settings(request)
                full_repo_dir = utils.get_full_repo_dir(settings, user, repo_name)

                result = handlers.create_repo(request, repo_name, os.path.join(os.getcwd(), "tests/support"))
        self.assertTrue(user in result)
        self.assertTrue(repo_name in result)
        self.assertTrue(os.path.isdir(full_repo_dir))
        self.assertTrue(os.path.isfile("tests/support/hooks/post-commit"))
        import time

        time.sleep(1)  # pass the time for a bit for things to
        # flush to disk
        self.assertTrue(os.path.isfile("%s/hooks/post-commit" % full_repo_dir))
예제 #2
0
    def test_fail(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 = "repo-%d" % random.randint(0, 100)
        repo = "%s/%s.git" % (user, repo_name)
        streams = (sys.stdin, sys.stdout, sys.stderr)
        request = Request(user, "kitty-git create-repo 'repo'", test_settings, streams)
        settings = handlers.get_settings(request)
        full_repo_dir = utils.get_full_repo_dir(settings, user, repo_name)

        self.mox.StubOutWithMock(subprocess, "call")
        subprocess.call(
            args=["git", "--git-dir=.", "init", "--bare"], cwd=full_repo_dir, stdout=sys.stderr, close_fds=True
        ).AndReturn(random.randint(1, 100))

        self.assertRaises(NappingCatException, handlers.create_repo, request, repo_name)
예제 #3
0
    def test_success(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 = "repo-%d" % random.randint(0, 100)
        repo = "%s/%s.git" % (user, repo_name)
        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(user, "kitty-git create-repo 'repo'", test_settings, streams)
                settings = handlers.get_settings(request)
                full_repo_dir = utils.get_full_repo_dir(settings, user, repo_name)

                result = handlers.create_repo(request, repo_name)
        self.assertTrue(user in result)
        self.assertTrue(repo_name in result)
        self.assertTrue(os.path.isdir(full_repo_dir))
예제 #4
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)