def test_redirect_git_numbering(self): my_repo = model_helpers.create_repo() my_repo.project = 'chromium' my_repo.repo = 'chromium/src' my_repo.put() my_commit = model_helpers.create_commit() my_commit.project = my_repo.project my_commit.repo = my_repo.repo my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[1].project = my_repo.project my_numberings[1].repo = my_repo.repo for numbering in my_numberings: numbering.put() generated = controller.calculate_redirect('100') expected = models.Redirect( redirect_type=models.RedirectType.GIT_FROM_NUMBER, redirect_url=my_commit.redirect_url, repo=my_commit.repo, project=my_commit.project, git_sha=my_commit.git_sha, repo_url='https://chromium.googlesource.com/chromium/src/', ) self.assertEqual(generated, expected)
def test_conversion_to_commit_multiple(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() commit_json = { 'commit': 'deadbeef' * 5, 'message': 'This is a revert\n' 'Original message\n' 'Cr-Commit-Position: refs/heads/master@{#298664}\n' 'More stuff\n' 'Cr-Commit-Position: refs/heads/master@{#298668}', } controller.write_commits_to_db( [commit_json], 'cool', 'cool_src') commit = models.NumberingMap.get_key_by_id( 298668, models.NumberingType.COMMIT_POSITION, repo='cool_src', project='cool', ref='refs/heads/master').get() self.assertIsNotNone(commit) commit = models.NumberingMap.get_key_by_id( 298664, models.NumberingType.COMMIT_POSITION, repo='cool_src', project='cool', ref='refs/heads/master').get() self.assertIsNone(commit)
def test_conversion_to_commit_multiple(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() commit_json = { 'commit': 'deadbeef' * 5, 'message': 'This is a revert\n' 'Original message\n' 'Cr-Commit-Position: refs/heads/master@{#298664}\n' 'More stuff\n' 'Cr-Commit-Position: refs/heads/master@{#298668}', } controller.write_commits_to_db([commit_json], 'cool', 'cool_src') commit = models.NumberingMap.get_key_by_id( 298668, models.NumberingType.COMMIT_POSITION, repo='cool_src', project='cool', ref='refs/heads/master').get() self.assertIsNotNone(commit) commit = models.NumberingMap.get_key_by_id( 298664, models.NumberingType.COMMIT_POSITION, repo='cool_src', project='cool', ref='refs/heads/master').get() self.assertIsNone(commit)
def test_get_numberings(self): """Test getting a COMMIT_POSITION or SVN numbering.""" my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() for numbering in my_numberings: numbering.put() svn_numbering = my_numberings[0] git_numbering = my_numberings[1] response = self._make_api_call('get_numbering', params={ 'number': git_numbering.number, 'numbering_type': 'COMMIT_POSITION', 'project': git_numbering.project, 'repo': git_numbering.repo, 'numbering_identifier': git_numbering.numbering_identifier}) expected = git_numbering.ToMessage() resp = model_helpers.convert_json_to_model_proto( models.NumberingMap, response.json) self.assertEqual(expected, resp) response = self._make_api_call('get_numbering', params={ 'number': svn_numbering.number, 'numbering_type': 'SVN', 'numbering_identifier': svn_numbering.numbering_identifier}) expected = svn_numbering.ToMessage() resp = model_helpers.convert_json_to_model_proto( models.NumberingMap, response.json) self.assertEqual(expected, resp)
def test_redirect_numeric_log_fallback(self): # If we don't know about one of the numbers, assume they're short hashes. my_repo = model_helpers.create_repo() my_repo.project = 'chromium' my_repo.repo = 'chromium/src' my_repo.put() first_commit = model_helpers.create_commit() first_commit.git_sha = 'deadbeef' * 5 first_commit.project = my_repo.project first_commit.repo = my_repo.repo first_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[1].git_sha = 'deadbeef' * 5 my_numberings[1].project = my_repo.project my_numberings[1].repo = my_repo.repo for numbering in my_numberings: numbering.put() query = '100..123456' generated = controller.calculate_redirect(query) expected = models.Redirect( redirect_type=models.RedirectType.GIT_LOG, redirect_url=( 'https://chromium.googlesource.com/chromium/src/+log/%s' % query), ) self.assertEquals(generated, expected)
def test_redirect_numeric_log(self): # It's necessary to overwrite the model_helpers defaults with chromium/src # so that the numbering (which only works in chromium/src) can look up # the fake commits we create. my_repo = model_helpers.create_repo() my_repo.project = 'chromium' my_repo.repo = 'chromium/src' my_repo.put() first_commit = model_helpers.create_commit() first_commit.git_sha = 'deadbeef' * 5 first_commit.project = my_repo.project first_commit.repo = my_repo.repo first_commit.put() second_commit = model_helpers.create_commit() second_commit.git_sha = 'baddecaf' * 5 second_commit.project = my_repo.project second_commit.repo = my_repo.repo second_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[1].git_sha = 'deadbeef' * 5 my_numberings[1].project = my_repo.project my_numberings[1].repo = my_repo.repo my_numberings.append( models.NumberingMap( numbering_type=models.NumberingType.COMMIT_POSITION, numbering_identifier='refs/heads/master', number=123456, project='chromium', repo='chromium/src', git_sha=second_commit.git_sha, redirect_url='https://crrev.com/%s' % second_commit.git_sha)) for numbering in my_numberings: numbering.put() generated = controller.calculate_redirect('100..123456') expected_url = ('https://chromium.googlesource.com/chromium/src/+log/' 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef..' 'baddecafbaddecafbaddecafbaddecafbaddecaf') expected = models.Redirect( redirect_type=models.RedirectType.GIT_LOG, redirect_url=expected_url, repo=first_commit.repo, repo_url='https://chromium.googlesource.com/chromium/src/', ) self.assertEqual(generated, expected)
def test_redirect_full_log(self): my_repo = model_helpers.create_repo() my_repo.put() first_commit = model_helpers.create_commit() first_commit.put() second_commit = model_helpers.create_commit() second_commit.git_sha = 'baddecaf' * 5 second_commit.put() query = '%s..%s' % (first_commit.git_sha, second_commit.git_sha) generated = controller.calculate_redirect(query) expected_url = 'https://cool.googlesource.com/cool_src/+log/%s' % query expected = models.Redirect( redirect_type=models.RedirectType.GIT_LOG, redirect_url=expected_url, repo=first_commit.repo, repo_url='https://cool.googlesource.com/cool_src/', ) self.assertEqual(generated, expected)
def test_redirect_numeric_git_sha(self): """Test that a stored numeric git_sha redirects properly.""" my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.git_sha = '11111111' * 5 my_commit.redirect_url = 'https://crrev.com/%s' % my_commit.git_sha my_commit.put() response = self.test_app.get('/%s' % ('11111111' * 5, ), status=302) self.assertEqual(response.location, my_commit.redirect_url)
def test_conversion_to_no_commit(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() commit_json = { 'commit': 'deadbeef' * 5, 'message': '', } controller.write_commits_to_db( [commit_json], 'cool', 'cool_src') self.assertEqual(0, len(list(models.NumberingMap.query())))
def test_conversion_to_no_commit(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() commit_json = { 'commit': 'deadbeef' * 5, 'message': '', } controller.write_commits_to_db([commit_json], 'cool', 'cool_src') self.assertEqual(0, len(list(models.NumberingMap.query())))
def test_get_commit(self): """Test getting information about a single commit.""" my_commit = model_helpers.create_commit() my_commit.put() response = self._make_api_call('get_commit', params={'git_sha': my_commit.git_sha}) expected = my_commit.ToMessage() resp = model_helpers.convert_json_to_model_proto( models.RevisionMap, response.json) self.assertEqual(expected, resp)
def test_redirect_numeric_git_sha(self): """Test that a stored numeric git_sha redirects properly.""" my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.git_sha = '11111111' * 5 my_commit.redirect_url = 'https://crrev.com/%s' % my_commit.git_sha my_commit.put() response = self.test_app.get('/%s' % ('11111111' * 5,), status=302) self.assertEqual( response.location, my_commit.redirect_url)
def test_redirect_svn_numbering_not_found(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' for numbering in my_numberings: numbering.put() generated = controller.calculate_redirect('101') self.assertEqual(generated, None)
def test_get_commit(self): """Test getting information about a single commit.""" my_commit = model_helpers.create_commit() my_commit.put() response = self._make_api_call('get_commit', params={ 'git_sha': my_commit.git_sha}) expected = my_commit.ToMessage() resp = model_helpers.convert_json_to_model_proto( models.RevisionMap, response.json) self.assertEqual(expected, resp)
def test_redirect_git_sha(self): """Test that a stored git_sha redirects properly.""" my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' for numbering in my_numberings: numbering.put() response = self.test_app.get('/%s' % ('b0b1beef' * 5, ), status=302) self.assertEqual(response.location, my_commit.redirect_url)
def test_redirect_git_sha(self): """Test that a stored git_sha redirects properly.""" my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' for numbering in my_numberings: numbering.put() response = self.test_app.get('/%s' % ('b0b1beef' * 5,), status=302) self.assertEqual( response.location, my_commit.redirect_url)
def test_redirect_over_breakpoint(self): """Test that requesting a number above the SVN->git switch goes to git.""" my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' my_numberings[0].number = 291562 for numbering in my_numberings: numbering.put() generated = controller.calculate_redirect('291562') self.assertEqual(generated, None)
def test_redirect_crazy_log(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() query = '%s^^!...FEEDCAFEB33F@' % my_commit.git_sha generated = controller.calculate_redirect(query) expected_url = 'https://cool.googlesource.com/cool_src/+log/%s' % query expected = models.Redirect( redirect_type=models.RedirectType.GIT_LOG, redirect_url=expected_url, repo=my_commit.repo, repo_url='https://cool.googlesource.com/cool_src/', ) self.assertEqual(generated, expected)
def test_redirect_git_sha(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() response = self._make_api_call('get_redirect', params={'query': my_commit.git_sha}) expected = { u'git_sha': unicode(my_commit.git_sha), u'repo': unicode(my_commit.repo), u'project': unicode(my_commit.project), u'redirect_url': unicode(my_commit.redirect_url), u'redirect_type': u'GIT_FULL', u'repo_url': u'https://cool.googlesource.com/cool_src/', } self.assertEqual(expected, response.json)
def test_redirect_git_sha(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() response = self._make_api_call('get_redirect', params={ 'query': my_commit.git_sha}) expected = { u'git_sha': unicode(my_commit.git_sha), u'repo': unicode(my_commit.repo), u'project': unicode(my_commit.project), u'redirect_url': unicode(my_commit.redirect_url), u'redirect_type': u'GIT_FULL', u'repo_url': u'https://cool.googlesource.com/cool_src/', } self.assertEqual(expected, response.json)
def test_redirect_git_sha(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() generated = controller.calculate_redirect(my_commit.git_sha) expected = models.Redirect( redirect_type=models.RedirectType.GIT_FULL, redirect_url=my_commit.redirect_url, repo=my_commit.repo, project=my_commit.project, git_sha=my_commit.git_sha, repo_url='https://cool.googlesource.com/cool_src/', ) self.assertEqual(expected, generated)
def test_conversion_to_svn_commit(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() commit_json = { 'commit': 'deadbeef' * 5, 'message': 'git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200000 ' '0039d316-1c4b-4281-b951-d872f2087c98', } controller.write_commits_to_db([commit_json], 'cool', 'cool_src') for ref in ('svn://svn.chromium.org/chrome', 'svn://svn.chromium.org/chrome/trunk', 'svn://svn.chromium.org/chrome/trunk/src'): commit = models.NumberingMap.get_key_by_id( 200000, models.NumberingType.SVN, ref=ref).get() self.assertIsNotNone(commit)
def test_conversion_to_svn_commit(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() commit_json = { 'commit': 'deadbeef' * 5, 'message': 'git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200000 ' '0039d316-1c4b-4281-b951-d872f2087c98', } controller.write_commits_to_db( [commit_json], 'cool', 'cool_src') for ref in ('svn://svn.chromium.org/chrome', 'svn://svn.chromium.org/chrome/trunk', 'svn://svn.chromium.org/chrome/trunk/src'): commit = models.NumberingMap.get_key_by_id( 200000, models.NumberingType.SVN, ref=ref).get() self.assertIsNotNone(commit)
def test_redirect_numbering(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' for numbering in my_numberings: numbering.put() response = self._make_api_call('get_redirect', params={'query': '100'}) expected = { u'git_sha': unicode(my_commit.git_sha), u'repo': unicode(my_commit.repo), u'project': unicode(my_commit.project), u'redirect_url': unicode(my_commit.redirect_url), u'redirect_type': u'GIT_FROM_NUMBER', u'repo_url': u'https://cool.googlesource.com/cool_src/', } self.assertEqual(expected, response.json)
def test_redirect_numbering(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' for numbering in my_numberings: numbering.put() response = self._make_api_call('get_redirect', params={ 'query': '100'}) expected = { u'git_sha': unicode(my_commit.git_sha), u'repo': unicode(my_commit.repo), u'project': unicode(my_commit.project), u'redirect_url': unicode(my_commit.redirect_url), u'redirect_type': u'GIT_FROM_NUMBER', u'repo_url': u'https://cool.googlesource.com/cool_src/', } self.assertEqual(expected, response.json)
def test_redirect_svn_numbering(self): my_repo = model_helpers.create_repo() my_repo.put() my_commit = model_helpers.create_commit() my_commit.put() my_numberings = model_helpers.create_numberings() my_numberings[0].numbering_identifier = 'svn://svn.chromium.org/chrome' for numbering in my_numberings: numbering.put() generated = controller.calculate_redirect('100') expected = models.Redirect( redirect_type=models.RedirectType.GIT_FROM_NUMBER, redirect_url=my_commit.redirect_url, repo=my_commit.repo, project=my_commit.project, git_sha=my_commit.git_sha, repo_url='https://cool.googlesource.com/cool_src/', ) self.assertEqual(generated, expected)
def test_revision_put_hooks(self): my_commit = model_helpers.create_commit() generated = my_commit.put() expected = ndb.Key(models.RevisionMap, my_commit.git_sha) self.assertEquals(generated, expected)