Exemple #1
0
 def test_non_transient_error(self, requests_get):
   requests_get.side_effect = multi(
     self.r('repo/+/revision?name-status=1&format=JSON',
            fetch.GitilesFetchError(403, '')),
   )
   with self.assertRaises(fetch.GitilesFetchError):
     fetch.GitilesBackend('dir', 'repo').commit_metadata(
         'revision')
   self.assertMultiDone(requests_get)
Exemple #2
0
  def test_commit_metadata(self, requests_get):
    requests_get.side_effect = multi(
      self.j('repo/+/revision?name-status=1&format=JSON', self.a_dat),
      self.j('repo/+/%s?name-status=1&format=JSON' % self.a, self.a_dat),
      self.d('repo/+/%s/%s?format=TEXT' % (self.a, IRC), self.proto_text)
    )

    result = fetch.GitilesBackend('dir', 'repo').commit_metadata(
        'revision')
    self.assertEqual(result, self.a_meta)
    self.assertMultiDone(requests_get)
Exemple #3
0
  def test_checkout(self, requests_get, _tarfile_open, makedirs, rmtree):
    requests_get.side_effect = multi(
      self.j('repo/+/revision?name-status=1&format=JSON', self.a_dat),
      self.j('repo/+/%s?name-status=1&format=JSON' % self.a, self.a_dat),
      self.d('repo/+/%s/%s?format=TEXT' % (self.a, IRC),
             self.proto_text),
      self.d('repo/+archive/%s/path/to/recipes.tar.gz' % self.a, ''),
    )

    fetch.GitilesBackend('dir', 'repo').checkout('revision')

    makedirs.assert_has_calls([
      mock.call('dir/infra/config'),
      mock.call('dir/path/to/recipes'),
    ])

    rmtree.assert_called_once_with('dir', ignore_errors=True)
    self.assertMultiDone(requests_get)
Exemple #4
0
  def test_transient_retry(self, _logging_exception, _time_sleep, requests_get):
    requests_get.side_effect = multi(
      self.r('repo/+/revision?name-status=1&format=JSON',
             fetch.GitilesFetchError(500, '')),
      self.r('repo/+/revision?name-status=1&format=JSON',
             fetch.GitilesFetchError(500, '')),
      self.r('repo/+/revision?name-status=1&format=JSON',
             fetch.GitilesFetchError(500, '')),
      self.r('repo/+/revision?name-status=1&format=JSON',
             fetch.GitilesFetchError(500, '')),
      self.j('repo/+/revision?name-status=1&format=JSON', self.a_dat),
      self.j('repo/+/%s?name-status=1&format=JSON' % self.a, self.a_dat),
      self.d('repo/+/%s/%s?format=TEXT' % (self.a, IRC), self.proto_text),
    )

    result = fetch.GitilesBackend('dir', 'repo').commit_metadata(
        'revision')
    self.assertEqual(result, self.a_meta)
    self.assertMultiDone(requests_get)
Exemple #5
0
  def test_updates(self, requests_get):
    sha_a = 'a'*40
    sha_b = 'b'*40
    log_json = {
      'log': [
        {
          'commit': sha_b,
          'author': {'email': '*****@*****.**'},
          'committer': {'time': 'Fri Apr 14 00:58:45 2017'},
          'message': 'message',
          'tree_diff': [
            {
              'old_path': '/dev/null',
              'new_path': 'path/to/recipes/path1/foo',
            },
          ],
        },
        {
          'commit': 'def456',
          'author': {'email': '*****@*****.**'},
          'committer': {'time': 'Fri Apr 14 00:57:45 2017'},
          'message': 'message',
          'tree_diff': [
            {
              'old_path': '/dev/null',
              'new_path': 'path8/foo',
            },
          ],
        },
        {
          'commit': sha_a,
          'author': {'email': '*****@*****.**'},
          'committer': {'time': 'Fri Apr 14 00:56:45 2017'},
          'message': 'message',
          'tree_diff': [
            {
              'old_path': '/dev/null',
              'new_path': 'path/to/recipes/path8/foo',
            },
            {
              'old_path': 'path2/foo',
              'new_path': '/dev/null',
            },
          ],
        },
      ],
    }

    requests_get.side_effect = multi(
      self.j('repo/+/reva?name-status=1&format=JSON', log_json['log'][2]),
      self.j('repo/+/revb?name-status=1&format=JSON', log_json['log'][0]),
      self.j('repo/+log/%s..%s?name-status=1&format=JSON' % (sha_a, sha_b),
             log_json),
      self.d('repo/+/%s/%s?format=TEXT' % (sha_a, IRC), self.proto_text),
      self.d('repo/+/%s/%s?format=TEXT' % ('def456', IRC), self.proto_text),
      self.d('repo/+/%s/%s?format=TEXT' % (sha_b, IRC), self.proto_text),
    )

    be = fetch.GitilesBackend('dir', 'repo')
    self.assertEqual(sha_a, be.resolve_refspec('reva'))
    self.assertEqual(sha_b, be.resolve_refspec('revb'))

    self.assertEqual(
        [self.a_meta,
         fetch.CommitMetadata(
          revision = 'def456',
          author_email = '*****@*****.**',
          commit_timestamp = 1492131465,
          message_lines = ('message',),
          spec = package_pb2.Package(
            api_version = 2,
            project_id = 'foo',
            recipes_path = 'path/to/recipes',
          ),
          roll_candidate = False,
        ),
         fetch.CommitMetadata(
          revision = sha_b,
          author_email = '*****@*****.**',
          commit_timestamp = 1492131525,
          message_lines = ('message',),
          spec = package_pb2.Package(
            api_version = 2,
            project_id = 'foo',
            recipes_path = 'path/to/recipes',
          ),
          roll_candidate = True,
        )],
      be.updates(sha_a, sha_b))
    self.assertMultiDone(requests_get)