Пример #1
0
 def test_post(self):
     req_body = {"b": 2}
     self.response.content = ')]}\'{"a":1}'
     actual = gerrit.fetch_json("localhost", "p", method="POST", payload=req_body, params={"p": 1})
     self.assertEqual(actual, {"a": 1})
     _, fetch_kwargs = self.urlfetch_mock.call_args
     self.assertEqual(fetch_kwargs["url"], "https://localhost/a/p?p=1")
     self.assertEqual(json.loads(fetch_kwargs.get("payload")), req_body)
Пример #2
0
 def test_post(self):
   req_body = {'b': 2}
   self.response.content = ')]}\'{"a":1}'
   actual = gerrit.fetch_json(
       'localhost', 'p', method='POST', payload=req_body, params={'p': 1})
   self.assertEqual(actual, {'a': 1})
   _, fetch_kwargs = self.urlfetch_mock.call_args
   self.assertEqual(fetch_kwargs['url'], 'https://localhost/a/p?p=1')
   self.assertEqual(json.loads(fetch_kwargs.get('payload')), req_body)
Пример #3
0
 def test_post(self):
   req_body = {'b': 2}
   self.response.content = ')]}\'{"a":1}'
   actual = gerrit.fetch_json(
       'localhost', 'p', method='POST', payload=req_body, params={'p': 1})
   self.assertEqual(actual, {'a': 1})
   _, fetch_kwargs = self.urlfetch_mock.call_args
   self.assertEqual(fetch_kwargs['url'], 'https://localhost/a/p?p=1')
   self.assertEqual(json.loads(fetch_kwargs.get('payload')), req_body)
Пример #4
0
def get_commit(hostname, project, treeish):
  """Gets a single Git commit.

  Returns:
    Commit object, or None if the commit was not found.
  """
  data = gerrit.fetch_json(hostname, '%s/+/%s' % (project, treeish))
  if data is None:
    return None
  return _parse_commit(data)
Пример #5
0
def get_commit(hostname, project, treeish):
    """Gets a single Git commit.

  Returns:
    Commit object, or None if the commit was not found.
  """
    _validate_args(hostname, project, treeish)
    data = gerrit.fetch_json(hostname, '%s/+/%s' % (project, treeish))
    if data is None:
        return None
    return _parse_commit(data)
Пример #6
0
def get_refs(hostname, project, **fetch_kwargs):
  """Gets refs from the server.

  Returns:
    Dict (ref_name -> last_commit_sha), or None if repository was not found.
  """
  _validate_args(hostname, project)
  res = gerrit.fetch_json(hostname, '%s/+refs' % project, **fetch_kwargs)
  if res is None:
    return None
  return {k: v['value'] for k, v in res.iteritems()}
Пример #7
0
def get_refs(hostname, project, **fetch_kwargs):
    """Gets refs from the server.

  Returns:
    Dict (ref_name -> last_commit_sha), or None if repository was not found.
  """
    _validate_args(hostname, project)
    res = gerrit.fetch_json(hostname, '%s/+refs' % project, **fetch_kwargs)
    if res is None:
        return None
    return {k: v['value'] for k, v in res.iteritems()}
Пример #8
0
def get_log(hostname, project, treeish, path=None, limit=None):
  """Gets a commit log.

  Does not support paging.

  Returns:
    Log object, or None if no log available.
  """
  query_params = {}
  if limit:
    query_params['n'] = limit
  data = gerrit.fetch_json(
      hostname,
      '%s/+log/%s/.%s' % (project, treeish, path or '/'),
      query_params=query_params)
  if data is None:
    return None
  return Log(
      commits=[_parse_commit(c) for c in data.get('log', [])])
Пример #9
0
def get_tree(hostname, project, treeish, path=None):
    """Gets a tree object.

  Returns:
    Tree object, or None if the tree was not found.
  """
    _validate_args(hostname, project, treeish, path)
    data = gerrit.fetch_json(hostname, '%s/+/%s%s' % (project, treeish, path))
    if data is None:
        return None

    return Tree(id=data['id'],
                entries=[
                    TreeEntry(
                        id=e['id'],
                        name=e['name'],
                        type=e['type'],
                        mode=e['mode'],
                    ) for e in data.get('entries', [])
                ])
Пример #10
0
def get_log(hostname, project, treeish, path=None, limit=None, **fetch_kwargs):
    """Gets a commit log.

  Does not support paging.

  Returns:
    Log object, or None if no log available.
  """
    _validate_args(hostname, project, treeish, path)
    query_params = {}
    if limit:
        query_params['n'] = limit
    path = (path or '').strip('/')
    data = gerrit.fetch_json(hostname,
                             '%s/+log/%s/%s' % (project, treeish, path),
                             params=query_params,
                             **fetch_kwargs)
    if data is None:
        return None
    return Log(commits=[_parse_commit(c) for c in data.get('log', [])])
Пример #11
0
def get_tree(hostname, project, treeish, path=None):
  """Gets a tree object.

  Returns:
    Tree object, or None if the tree was not found.
  """
  _validate_args(hostname, project, treeish, path)
  data = gerrit.fetch_json(hostname, '%s/+/%s%s' % (project, treeish, path))
  if data is None:
    return None

  return Tree(
      id=data['id'],
      entries=[
        TreeEntry(
            id=e['id'],
            name=e['name'],
            type=e['type'],
            mode=e['mode'],
        )
        for e in data.get('entries', [])
      ])
Пример #12
0
def get_log(hostname, project, treeish, path=None, limit=None, **fetch_kwargs):
  """Gets a commit log.

  Does not support paging.

  Returns:
    Log object, or None if no log available.
  """
  _validate_args(hostname, project, treeish, path)
  query_params = {}
  if limit:
    query_params['n'] = limit
  path = (path or '').strip('/')
  data = gerrit.fetch_json(
      hostname,
      '%s/+log/%s/%s' % (project, treeish, path),
      params=query_params,
      **fetch_kwargs)
  if data is None:
    return None
  return Log(
      commits=[_parse_commit(c) for c in data.get('log', [])])
Пример #13
0
 def test_bad_prefix(self):
     self.response.content = 'abc'
     with self.assertRaises(net.Error):
         gerrit.fetch_json('localhost', 'a')
Пример #14
0
 def test_auth_failure(self):
     self.response.status_code = httplib.FORBIDDEN
     with self.assertRaises(net.AuthError):
         gerrit.fetch_json('localhost', 'a')
Пример #15
0
 def test_not_found(self):
     self.response.status_code = httplib.NOT_FOUND
     result = gerrit.fetch_json('localhost', 'p')
     self.assertIsNone(result)
Пример #16
0
 def test_bad_prefix(self):
   self.response.content = 'abc'
   with self.assertRaises(net.Error):
     gerrit.fetch_json('localhost', 'a')
Пример #17
0
 def test_auth_failure(self):
   self.response.status_code = httplib.FORBIDDEN
   with self.assertRaises(net.AuthError):
     gerrit.fetch_json('localhost', 'a')
Пример #18
0
 def test_not_found(self):
   self.response.status_code = httplib.NOT_FOUND
   result = gerrit.fetch_json('localhost', 'p')
   self.assertIsNone(result)
Пример #19
0
 def test_bad_prefix(self):
     self.response.content = "abc"
     with self.assertRaises(net.Error):
         gerrit.fetch_json("localhost", "a")