def test_git_cmd1(self): request = dispatch.get_request(['git-upload-pack', 'bob/code']) request.data = {'rights': 'r', 'path': 'path/to/code'} cmd = request.get_command() expected = ['git', 'shell', '-c', "git-upload-pack 'path/to/code'"] self.assertEqual(expected, cmd)
def test_repo1(self): '''Repo property fetches objects by name appropriately''' repo = Repo(name='bob/code', vcs='hg') repo.full_clean() repo.save() request = dispatch.get_request(['hg', '--repository', 'bob/code']) self.assertIsInstance(request.repo, Repo) self.assertEqual(repo.pk, request.repo.pk)
def test_hg_cmd2(self): '''Repository specified with --repository ''' request = dispatch.get_request(['hg', '--repository', 'bob/code']) request.data = {'rights': 'rw', 'path': 'path/to/code'} cmd = request.get_command() expected = ['hg', '-R', 'path/to/code', 'serve', '--stdio'] self.assertEqual(expected, cmd)
def test_svn_cmd1(self): '''Without username. ''' request = dispatch.get_request(['svnserve', '--root', 'bob/code']) request.data = {'rights': 'r', 'path': 'path/to/code'} cmd = request.get_command() expected = ['svnserve', '--root', os.path.join(settings.VCSREPO_ROOT, 'svn'), '--tunnel'] self.assertEqual(expected, cmd)
def test_hg_cmd3(self): '''Read-only access. ''' request = dispatch.get_request(['hg', '--repository', 'bob/code']) request.data = {'rights': 'r', 'path': 'path/to/code'} cmd = request.get_command() hook = 'echo "Error: Permission denied (read-only)" >&2; false' expected = [ 'hg', '-R', 'path/to/code', 'serve', '--stdio', '--config', 'hooks.prechangegroup.readonly=' + hook, '--config', 'hooks.prepushkey.readonly=' + hook, ] self.assertEqual(expected, cmd)
def test_hg_write2(self): '''Writes can't happen if they don't have write privilege''' request = dispatch.get_request(['hg', '--repository', 'bob/code']) request.add_data({'rights': 'r', 'path': 'path/to/code'}) self.assertFalse(request.write)
def test_hg_write1(self): '''Writes are assumed to happen if a user has privileges''' request = dispatch.get_request(['hg', '--repository', 'bob/code']) request.add_data({'rights': 'rw', 'path': 'path/to/code'}) self.assertTrue(request.write)
def test_git_write2(self): '''Writes cannot happen for git-upload-pack''' request = dispatch.get_request(['git-upload-pack', 'bob/code']) self.assertFalse(request.write)
def test_git_write1(self): '''Writes can happen for git-receive-pack''' request = dispatch.get_request(['git-receive-pack', 'bob/code']) self.assertTrue(request.write)
def test_hg_postprocess(self): request = dispatch.get_request(['hg', '--repository', 'bob/code']) request.data = {'rights': 'r', 'path': 'path/to/code'} result = request.postprocess('hg: cloning from path/to/code') expected = 'hg: cloning from bob/code' self.assertEqual(expected, result)
def test_git_repo_name2(self): request = dispatch.get_request(['git-upload-pack', 'bob/code.git']) self.assertEqual('bob/code', request.repo_name)
def test_git_cmd3(self): request = dispatch.get_request(['git-receive-pack', 'bob/code']) request.data = {'rights': 'r', 'path': 'path/to/code'} self.assertRaises(dispatch.DispatchException, request.get_command)