def test_post_with_conflicting_repos(self): """Testing the POST validations/diffs/ API with conflicting repositories """ repository = self.create_repository(tool_name='Test') self.create_repository(tool_name='Test', name='Test 2', path='blah', mirror_path=repository.path) diff = SimpleUploadedFile('readme.diff', self.VALID_GIT_DIFF, content_type='text/x-patch') rsp = self.api_post(get_validate_diff_url(), { 'repository': repository.path, 'path': diff, 'basedir': '/trunk', }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_REPOSITORY.code) self.assertEqual( rsp['err']['msg'], 'Too many repositories matched "%s". Try ' 'specifying the repository by name instead.' % repository.path) self.assertEqual(rsp['repository'], repository.path)
def test_post_with_conflicting_repos(self): """Testing the POST validations/diffs/ API with conflicting repositories """ repository = self.create_repository(tool_name='Test') self.create_repository(tool_name='Test', name='Test 2', path='blah', mirror_path=repository.path) diff = SimpleUploadedFile('readme.diff', self.VALID_GIT_DIFF, content_type='text/x-patch') rsp = self.api_post( get_validate_diff_url(), { 'repository': repository.path, 'path': diff, 'basedir': '/trunk', }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_REPOSITORY.code) self.assertEqual(rsp['err']['msg'], 'Too many repositories matched "%s". Try ' 'specifying the repository by name instead.' % repository.path) self.assertEqual(rsp['repository'], repository.path)
def test_post_with_base_commit_id(self): """Testing the POST validation/diffs/ API with base_commit_id""" self.spy_on(DiffSet.objects.create_from_upload, call_original=True) repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') f = open(diff_filename, "r") self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', 'base_commit_id': '1234', }, expected_status=200, expected_mimetype=validate_diff_mimetype) f.close() last_call = DiffSet.objects.create_from_upload.last_call self.assertEqual(last_call.kwargs.get('base_commit_id'), '1234')
def test_post(self): """Testing the POST validation/diffs/ API""" repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, 'basedir': '/trunk', }, expected_status=200, expected_mimetype=validate_diff_mimetype)
def test_post(self): """Testing the POST validation/diffs/ API""" repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, 'basedir': '/trunk', }, expected_status=200, expected_mimetype=validate_diff_mimetype)
def test_post_with_site_no_access(self): """Testing the POST validation/diffs/ API without access to a local site """ repository = self.create_repository(with_local_site=True, tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') self.api_post(get_validate_diff_url(self.local_site_name), { 'repository': repository.pk, 'path': diff, 'basedir': '/trunk', }, expected_status=403)
def test_post_with_missing_basedir(self): """Testing the POST validations/diffs/ API with a missing basedir""" repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') rsp = self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code) self.assertIn('basedir', rsp['fields'])
def test_post(self): """Testing the POST validation/diffs/ API""" repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') f = open(diff_filename, "r") self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=200, expected_mimetype=validate_diff_mimetype) f.close()
def test_post_with_site_no_access(self): """Testing the POST validation/diffs/ API without access to a local site """ repository = self.create_repository(with_local_site=True, tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') with open(diff_filename, 'r') as fp: self.api_post(get_validate_diff_url(self.local_site_name), { 'repository': repository.pk, 'path': fp, 'basedir': '/trunk', }, expected_status=403)
def test_post_with_missing_basedir(self): """Testing the POST validations/diffs/ API with a missing basedir""" repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') rsp = self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code) self.assertIn('basedir', rsp['fields'])
def test_post_with_site_no_access(self): """Testing the POST validation/diffs/ API without access to a local site """ repository = self.create_repository(with_local_site=True, tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') self.api_post( get_validate_diff_url(self.local_site_name), { 'repository': repository.pk, 'path': diff, 'basedir': '/trunk', }, expected_status=403)
def test_post_with_missing_basedir(self): """Testing the POST validations/diffs/ API with a missing basedir""" repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') f = open(diff_filename, 'r') rsp = self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': f, }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code) self.assertIn('basedir', rsp['fields'])
def test_post(self): """Testing the POST validation/diffs/ API""" repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') f = open(diff_filename, "r") self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=200, expected_mimetype=validate_diff_mimetype) f.close()
def test_post_repository_private(self): """Testing the POST <URL> API without access to the requested repository """ repository = self.create_repository(tool_name='Test', public=False) rsp = self.api_post( get_validate_diff_url(), { 'repository': repository.path, 'path': SimpleUploadedFile('readme.diff', self.VALID_GIT_DIFF, content_type='text/x-patch'), 'basedir': '/trunk', }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_REPOSITORY.code)
def test_post_with_site_no_access(self): """Testing the POST validation/diffs/ API without access to a local site """ repository = self.create_repository(with_local_site=True, tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') with open(diff_filename, 'r') as fp: self.api_post( get_validate_diff_url(self.local_site_name), { 'repository': repository.pk, 'path': fp, 'basedir': '/trunk', }, expected_status=403)
def test_post_diff_with_files_not_found(self): """Testing the POST validation/diffs/ API with source files not found""" repository = self.create_repository(tool_name='Subversion') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'svn_file_not_found.diff') f = open(diff_filename, 'r') rsp = self.apiPost(get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], REPO_FILE_NOT_FOUND.code) self.assertEqual(rsp['file'], '/trunk/doc/misc-docs/Makefile2') self.assertEqual(rsp['revision'], '4')
def test_post_with_missing_basedir(self): """Testing the POST validations/diffs/ API with a missing basedir""" repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') f = open(diff_filename, 'r') rsp = self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': f, }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], INVALID_FORM_DATA.code) self.assertIn('basedir', rsp['fields'])
def test_post_with_parse_error(self): """Testing the POST validation/diffs/ API with a malformed diff file""" repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'stunnel.pem') with open(diff_filename, 'rb') as f: rsp = self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], DIFF_PARSE_ERROR.code) self.assertEqual(rsp['reason'], 'This does not appear to be a git diff') self.assertEqual(rsp['linenum'], 0)
def test_post_with_files_not_found(self): """Testing the POST validation/diffs/ API with source files not found """ repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_FILE_NOT_FOUND_DIFF, content_type='text/x-patch') rsp = self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, 'basedir': '', }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], REPO_FILE_NOT_FOUND.code) self.assertEqual(rsp['file'], 'missing-file') self.assertEqual(rsp['revision'], 'd6613f0')
def test_post_with_base_commit_id(self): """Testing the POST validation/diffs/ API with base_commit_id""" self.spy_on(DiffSet.objects.create_from_upload, call_original=True) repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, 'basedir': '/trunk', 'base_commit_id': '1234', }, expected_status=200, expected_mimetype=validate_diff_mimetype) last_call = DiffSet.objects.create_from_upload.last_call self.assertEqual(last_call.kwargs.get('base_commit_id'), '1234')
def test_post_with_base_commit_id(self): """Testing the POST validation/diffs/ API with base_commit_id""" self.spy_on(DiffSet.objects.create_from_upload, call_original=True) repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_README_DIFF, content_type='text/x-patch') self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, 'basedir': '/trunk', 'base_commit_id': '1234', }, expected_status=200, expected_mimetype=validate_diff_mimetype) last_call = DiffSet.objects.create_from_upload.last_call self.assertEqual(last_call.kwargs.get('base_commit_id'), '1234')
def test_post_with_files_not_found(self): """Testing the POST validation/diffs/ API with source files not found """ repository = self.create_repository(tool_name='Test') diff = SimpleUploadedFile('readme.diff', self.DEFAULT_GIT_FILE_NOT_FOUND_DIFF, content_type='text/x-patch') rsp = self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': diff, 'basedir': '', }, expected_status=400) self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], REPO_FILE_NOT_FOUND.code) self.assertEqual(rsp['file'], 'missing-file') self.assertEqual(rsp['revision'], 'd6613f0')
def test_post_diff_with_files_not_found(self): """Testing the POST validation/diffs/ API with source files not found""" repository = self.create_repository(tool_name='Subversion') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'svn_file_not_found.diff') f = open(diff_filename, 'r') rsp = self.apiPost( get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], REPO_FILE_NOT_FOUND.code) self.assertEqual(rsp['file'], '/trunk/doc/misc-docs/Makefile2') self.assertEqual(rsp['revision'], '4')
def test_post_with_parse_error(self): """Testing the POST validation/diffs/ API with a malformed diff file""" repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'stunnel.pem') f = open(diff_filename, 'r') rsp = self.api_post( get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], DIFF_PARSE_ERROR.code) self.assertEqual(rsp['reason'], 'This does not appear to be a git diff') self.assertEqual(rsp['linenum'], 0)
def test_post_diff_with_parse_error(self): """Testing the POST validation/diffs/ API with a malformed diff file""" # Post a git diff against the svn repository repository = self.create_repository(tool_name='Subversion') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_complex.diff') f = open(diff_filename, 'r') rsp = self.apiPost(get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], DIFF_PARSE_ERROR.code) self.assertEqual( rsp['reason'], 'No valid separator after the filename was found in the diff header' ) self.assertEqual(rsp['linenum'], 2)
def test_post_with_base_commit_id(self): """Testing the POST validation/diffs/ API with base_commit_id""" self.spy_on(DiffSet.objects.create_from_upload, call_original=True) repository = self.create_repository(tool_name='Test') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_readme.diff') f = open(diff_filename, "r") self.api_post(get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', 'base_commit_id': '1234', }, expected_status=200, expected_mimetype=validate_diff_mimetype) f.close() last_call = DiffSet.objects.create_from_upload.last_call self.assertEqual(last_call.kwargs.get('base_commit_id'), '1234')
def test_post_diff_with_parse_error(self): """Testing the POST validation/diffs/ API with a malformed diff file""" # Post a git diff against the svn repository repository = self.create_repository(tool_name='Subversion') diff_filename = os.path.join(os.path.dirname(scmtools.__file__), 'testdata', 'git_complex.diff') f = open(diff_filename, 'r') rsp = self.apiPost( get_validate_diff_url(), { 'repository': repository.pk, 'path': f, 'basedir': '/trunk', }, expected_status=400) f.close() self.assertEqual(rsp['stat'], 'fail') self.assertEqual(rsp['err']['code'], DIFF_PARSE_ERROR.code) self.assertEqual( rsp['reason'], 'No valid separator after the filename was found in the diff header') self.assertEqual(rsp['linenum'], 2)
def test_get_with_site_no_access(self): """Testing the GET validation/diffs/ API without access to local site """ self.api_get(get_validate_diff_url(self.local_site_name), expected_status=403)
def test_get_with_site(self): """Testing the GET validation/diffs/ API with access to local site""" self._login_user(local_site=True) self.api_get(get_validate_diff_url(self.local_site_name), expected_mimetype=validate_diff_mimetype)
def test_get(self): """Testing the GET validation/diffs/ API""" self.api_get(get_validate_diff_url(), expected_mimetype=validate_diff_mimetype)
def setup_http_not_allowed_item_test(self, user): return get_validate_diff_url()