예제 #1
0
  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)
예제 #2
0
  def test_repo_scan_for_commits(self):
    my_project = model_helpers.create_project()
    my_project.put()
    my_repo = model_helpers.create_repo()
    my_repo.put()
    base_url = my_project.canonical_url_template % {'project': my_project.name}

    log_data = {u'log': [
        {
            'commit': 'deadbeef' * 5,
            'message': 'git-svn-id: svn://svn.chromium.org/chrome/trunk/'
                       'src@200000 0039d316-1c4b-4281-b951-d872f2087c98\n'
                       'Cr-Commit-Position: refs/heads/master@{#301813}',
        },
    ]}

    with self.mock_urlfetch() as urlfetch:
      urlfetch.register_handler(
          base_url + 'cool_src/+log/master?format=json&n=1000',
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('deadbeef' * 5,),
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1' % ('deadbeef' * 5,),
          self._gitiles_json(log_data))
    controller.scan_repos()
    self.execute_queued_tasks()
    self.assertEqual(1, len(list(models.RevisionMap.query())))
    self.assertEqual(
        'deadbeef' * 5,
        models.RevisionMap.query().fetch()[0].git_sha)
    self.assertEqual(4, len(list(models.NumberingMap.query())))
예제 #3
0
  def test_project_scan_lag(self):
    """Test that the project_scan_lag endpoint properly calculates lag."""
    model_helpers.create_project().put()
    my_repo = model_helpers.create_repo()
    my_repo.put()

    generated_time = u'1970-01-02T00:00:00.000000'

    response = self._make_api_call('get_project_lag_list', params={
      'generated': generated_time})

    expected = {
        u'projects': [
          {u'project': my_repo.project,
            u'total_active_repos': u'1',
            u'repos_without_root': u'1',
            u'repos_with_root': u'0',
            u'scanned_repos': u'1',
            u'unscanned_repos': u'0',
            u'generated': generated_time,
            u'most_lagging_repo': u'%s:%s' % (my_repo.project, my_repo.repo),
            u'max': float(24 * 60 * 60),
            u'min': float(24 * 60 * 60),
            u'p50': float(24 * 60 * 60),
            u'p75': float(24 * 60 * 60),
            u'p90': float(24 * 60 * 60),
            u'p95': float(24 * 60 * 60),
            u'p99': float(24 * 60 * 60),
          }
        ],
        u'generated': generated_time,
    }

    self.assertEqual(expected, response.json)
예제 #4
0
    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)
예제 #5
0
  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)
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
  def test_repo_list(self):
    """Test that calling repo.list yields an list of scanned repos."""
    my_repo = model_helpers.create_repo()
    my_repo.put()
    second_repo = model_helpers.create_repo()
    second_repo.repo = 'cooler_src'
    second_repo.put()

    response = self._make_api_call('get_repos')

    expected = {u'items': [
      my_repo.ToMessage(),
      second_repo.ToMessage(),
    ]}

    resp = model_helpers.convert_items_to_protos(models.Repo, response.json)
    self.assertEqual(expected, resp)
예제 #9
0
 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)
예제 #10
0
  def test_get_repo(self):
    """Test getting an explicit repository."""
    my_repo = model_helpers.create_repo()
    my_repo.put()

    response = self._make_api_call('get_repo', params={
      'project': my_repo.project, 'repo': my_repo.repo})

    expected = my_repo.ToMessage()
    resp = model_helpers.convert_json_to_model_proto(models.Repo, response.json)
    self.assertEqual(expected, resp)
예제 #11
0
 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())))
예제 #12
0
 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())))
예제 #13
0
    def test_exclusions(self):
        project = 'test'
        repo = 'test'

        controller.REPO_EXCLUSIONS.setdefault(project, []).append(repo)
        my_repo = model_helpers.create_repo()
        my_repo.project = project
        my_repo.repo = repo
        my_repo.put()

        active_repos = controller.get_active_repos(project)
        self.assertEqual([], active_repos)
예제 #14
0
 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)
예제 #15
0
  def test_exclusions(self):
    project = 'test'
    repo = 'test'

    controller.REPO_EXCLUSIONS.setdefault(project, []).append(repo)
    my_repo = model_helpers.create_repo()
    my_repo.project = project
    my_repo.repo = repo
    my_repo.put()

    active_repos = controller.get_active_repos(project)
    self.assertEqual([], active_repos)
예제 #16
0
    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)
예제 #17
0
  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)
예제 #18
0
    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)
예제 #19
0
  def test_calculate_lag_stats(self):
    model_helpers.create_project().put()
    my_repo = model_helpers.create_repo()
    my_repo.put()
    second_repo = model_helpers.create_repo()
    second_repo.repo = 'cooler'
    second_repo.root_commit_scanned = True
    second_repo.last_scanned = None
    second_repo.put()

    generated_time = datetime.datetime(1970, 01, 02)
    expected = models.ProjectLagList(
        generated=generated_time,
        projects=[
          models.ProjectLagStats(
            project=my_repo.project,
            total_active_repos=2,
            repos_without_root=1,
            repos_with_root=1,
            scanned_repos=1,
            unscanned_repos=1,
            generated=generated_time,
            most_lagging_repo='%s:%s' % (my_repo.project, my_repo.repo),
            max=float(24 * 60 * 60),
            min=float(24 * 60 * 60),
            p50=float(24 * 60 * 60),
            p75=float(24 * 60 * 60),
            p90=float(24 * 60 * 60),
            p95=float(24 * 60 * 60),
            p99=float(24 * 60 * 60)
          ),
        ],
    )

    generated = controller.calculate_lag_stats(generated=generated_time)

    self.assertEqual(expected, generated)
예제 #20
0
    def test_calculate_lag_stats(self):
        model_helpers.create_project().put()
        my_repo = model_helpers.create_repo()
        my_repo.put()
        second_repo = model_helpers.create_repo()
        second_repo.repo = 'cooler'
        second_repo.root_commit_scanned = True
        second_repo.last_scanned = None
        second_repo.put()

        generated_time = datetime.datetime(1970, 01, 02)
        expected = models.ProjectLagList(
            generated=generated_time,
            projects=[
                models.ProjectLagStats(project=my_repo.project,
                                       total_active_repos=2,
                                       repos_without_root=1,
                                       repos_with_root=1,
                                       scanned_repos=1,
                                       unscanned_repos=1,
                                       generated=generated_time,
                                       most_lagging_repo='%s:%s' %
                                       (my_repo.project, my_repo.repo),
                                       max=float(24 * 60 * 60),
                                       min=float(24 * 60 * 60),
                                       p50=float(24 * 60 * 60),
                                       p75=float(24 * 60 * 60),
                                       p90=float(24 * 60 * 60),
                                       p95=float(24 * 60 * 60),
                                       p99=float(24 * 60 * 60)),
            ],
        )

        generated = controller.calculate_lag_stats(generated=generated_time)

        self.assertEqual(expected, generated)
예제 #21
0
  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)
예제 #22
0
    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)
예제 #23
0
    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)
예제 #24
0
  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)
예제 #25
0
    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)
예제 #26
0
  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)
예제 #27
0
  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)
예제 #28
0
    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)
예제 #29
0
    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)
예제 #30
0
    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)
예제 #31
0
    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)
예제 #32
0
  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)
예제 #33
0
    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)
예제 #34
0
  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)
예제 #35
0
  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)
예제 #36
0
    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)
예제 #37
0
    def test_repo_scan_for_commits(self):
        my_project = model_helpers.create_project()
        my_project.put()
        my_repo = model_helpers.create_repo()
        my_repo.put()
        base_url = my_project.canonical_url_template % {
            'project': my_project.name
        }

        log_data = {
            u'log': [
                {
                    'commit':
                    'deadbeef' * 5,
                    'message':
                    'git-svn-id: svn://svn.chromium.org/chrome/trunk/'
                    'src@200000 0039d316-1c4b-4281-b951-d872f2087c98\n'
                    'Cr-Commit-Position: refs/heads/master@{#301813}',
                },
            ]
        }

        with self.mock_urlfetch() as urlfetch:
            urlfetch.register_handler(
                base_url + 'cool_src/+log/master?format=json&n=1000',
                self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('deadbeef' * 5, ), self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1' %
                ('deadbeef' * 5, ), self._gitiles_json(log_data))
        controller.scan_repos()
        self.execute_queued_tasks()
        self.assertEqual(1, len(list(models.RevisionMap.query())))
        self.assertEqual('deadbeef' * 5,
                         models.RevisionMap.query().fetch()[0].git_sha)
        self.assertEqual(4, len(list(models.NumberingMap.query())))
예제 #38
0
 def test_repo_put_hooks(self):
   """Test that they key is set automatically when you put()."""
   expected = models.Repo.get_key_by_id('cool', 'cool_src')
   generated = model_helpers.create_repo().put()
   self.assertEquals(generated, expected)
예제 #39
0
  def test_repo_scan_for_new_commits(self):
    """Test all forms of new commits, before and after what has been seen."""
    my_project = model_helpers.create_project()
    my_project.put()
    my_repo = model_helpers.create_repo()
    my_repo.put()
    base_url = my_project.canonical_url_template % {'project': my_project.name}

    commits = [
        {
            'commit': 'f007beef' * 5,
            'message': '',
        },
        {
            'commit': '000fbeef' * 5,
            'message': '',
        },
        {
            'commit': '700fbeef' * 5,
            'message': '',
        },
        {
            'commit': 'deadbeef' * 5,
            'message': '',
        },
        {
            'commit': 'feedbeef' * 5,
            'message': '',
        },
        {
            'commit': 'f00fbeef' * 5,
            'message': '',
        },
        {
            'commit': 'f33dbeef' * 5,
            'message': '',
        },
    ]

    log_data = {u'log': [
        commits[3],
    ]}

    with self.mock_urlfetch() as urlfetch:
      urlfetch.register_handler(
          base_url + 'cool_src/+log/master?format=json&n=1000',
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('deadbeef' * 5,),
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1' % ('deadbeef' * 5,),
          self._gitiles_json(log_data))

    controller.scan_repos()
    self.execute_queued_tasks()

    log_data = {u'log': [
        commits[3],
    ]}

    with self.mock_urlfetch() as urlfetch:
      urlfetch.register_handler(
          base_url + 'cool_src/+log/master?format=json&n=1000',
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('deadbeef' * 5,),
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1' % ('deadbeef' * 5,),
          self._gitiles_json(log_data))

    controller.scan_repos()
    self.execute_queued_tasks()

    my_repo = models.Repo.get_key_by_id(my_project.name, my_repo.repo).get()
    my_repo.root_commit_scanned = False
    my_repo.first_commit = None
    my_repo.put()

    log_data = {
        u'log': commits[0:2],
        'next': '000fbeef' * 5,
    }
    ooofbeef_data = {
        u'log': commits[1:3],
        'next': 'deadbeef',
    }
    deadbeef_data = {
        u'log': commits[3:5],
        'next': 'feedbeef' * 5,
    }
    feedbeef_data = {
        u'log':  commits[-3:-1],
        'next': 'f00fbeef' * 5,
    }
    toofbeef_data = {
        u'log': commits[2:4],
        'next': 'feedbeef' * 5,
    }
    foofbeef_data = {
        u'log': commits[-2:],
    }
    with self.mock_urlfetch() as urlfetch:
      urlfetch.register_handler(
          base_url + 'cool_src/+log/master?format=json&n=1000',
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=2' % ('f007beef' * 5,),
          self._gitiles_json(log_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('000fbeef' * 5,),
          self._gitiles_json(ooofbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=2' % ('000fbeef' * 5,),
          self._gitiles_json(ooofbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('deadbeef' * 5,),
          self._gitiles_json(deadbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=2' % ('deadbeef' * 5,),
          self._gitiles_json(deadbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('700fbeef' * 5,),
          self._gitiles_json(toofbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1' % ('700fbeef' * 5,),
          self._gitiles_json(toofbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=2' % ('700fbeef' * 5,),
          self._gitiles_json(toofbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('feedbeef' * 5,),
          self._gitiles_json(feedbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=2' % ('feedbeef' * 5,),
          self._gitiles_json(feedbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=1000' % ('f00fbeef' * 5,),
          self._gitiles_json(foofbeef_data))
      urlfetch.register_handler(
          base_url + 'cool_src/+log/%s?format=json&n=2' % ('f00fbeef' * 5,),
          self._gitiles_json(foofbeef_data))
    controller.scan_repos()
    self.execute_queued_tasks()

    self.assertEqual(7, len(list(models.RevisionMap.query())))
    my_repo = models.Repo.get_key_by_id(my_project.name, my_repo.repo).get()
    self.assertTrue(my_repo.root_commit_scanned)
예제 #40
0
    def test_repo_scan_for_new_commits(self):
        """Test all forms of new commits, before and after what has been seen."""
        my_project = model_helpers.create_project()
        my_project.put()
        my_repo = model_helpers.create_repo()
        my_repo.put()
        base_url = my_project.canonical_url_template % {
            'project': my_project.name
        }

        commits = [
            {
                'commit': 'f007beef' * 5,
                'message': '',
            },
            {
                'commit': '000fbeef' * 5,
                'message': '',
            },
            {
                'commit': '700fbeef' * 5,
                'message': '',
            },
            {
                'commit': 'deadbeef' * 5,
                'message': '',
            },
            {
                'commit': 'feedbeef' * 5,
                'message': '',
            },
            {
                'commit': 'f00fbeef' * 5,
                'message': '',
            },
            {
                'commit': 'f33dbeef' * 5,
                'message': '',
            },
        ]

        log_data = {
            u'log': [
                commits[3],
            ]
        }

        with self.mock_urlfetch() as urlfetch:
            urlfetch.register_handler(
                base_url + 'cool_src/+log/master?format=json&n=1000',
                self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('deadbeef' * 5, ), self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1' %
                ('deadbeef' * 5, ), self._gitiles_json(log_data))

        controller.scan_repos()
        self.execute_queued_tasks()

        log_data = {
            u'log': [
                commits[3],
            ]
        }

        with self.mock_urlfetch() as urlfetch:
            urlfetch.register_handler(
                base_url + 'cool_src/+log/master?format=json&n=1000',
                self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('deadbeef' * 5, ), self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1' %
                ('deadbeef' * 5, ), self._gitiles_json(log_data))

        controller.scan_repos()
        self.execute_queued_tasks()

        my_repo = models.Repo.get_key_by_id(my_project.name,
                                            my_repo.repo).get()
        my_repo.root_commit_scanned = False
        my_repo.first_commit = None
        my_repo.put()

        log_data = {
            u'log': commits[0:2],
            'next': '000fbeef' * 5,
        }
        ooofbeef_data = {
            u'log': commits[1:3],
            'next': 'deadbeef',
        }
        deadbeef_data = {
            u'log': commits[3:5],
            'next': 'feedbeef' * 5,
        }
        feedbeef_data = {
            u'log': commits[-3:-1],
            'next': 'f00fbeef' * 5,
        }
        toofbeef_data = {
            u'log': commits[2:4],
            'next': 'feedbeef' * 5,
        }
        foofbeef_data = {
            u'log': commits[-2:],
        }
        with self.mock_urlfetch() as urlfetch:
            urlfetch.register_handler(
                base_url + 'cool_src/+log/master?format=json&n=1000',
                self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=2' %
                ('f007beef' * 5, ), self._gitiles_json(log_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('000fbeef' * 5, ), self._gitiles_json(ooofbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=2' %
                ('000fbeef' * 5, ), self._gitiles_json(ooofbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('deadbeef' * 5, ), self._gitiles_json(deadbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=2' %
                ('deadbeef' * 5, ), self._gitiles_json(deadbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('700fbeef' * 5, ), self._gitiles_json(toofbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1' %
                ('700fbeef' * 5, ), self._gitiles_json(toofbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=2' %
                ('700fbeef' * 5, ), self._gitiles_json(toofbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('feedbeef' * 5, ), self._gitiles_json(feedbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=2' %
                ('feedbeef' * 5, ), self._gitiles_json(feedbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=1000' %
                ('f00fbeef' * 5, ), self._gitiles_json(foofbeef_data))
            urlfetch.register_handler(
                base_url + 'cool_src/+log/%s?format=json&n=2' %
                ('f00fbeef' * 5, ), self._gitiles_json(foofbeef_data))
        controller.scan_repos()
        self.execute_queued_tasks()

        self.assertEqual(7, len(list(models.RevisionMap.query())))
        my_repo = models.Repo.get_key_by_id(my_project.name,
                                            my_repo.repo).get()
        self.assertTrue(my_repo.root_commit_scanned)