Esempio n. 1
0
def get_build_async(req, res, _ctx, mask):
    """Retrieves a build by id or number."""
    validation.validate_get_build_request(req)

    if req.id:
        logging.info('Build id: %s', req.id)
        build = yield service.get_async(req.id)
    else:
        logging.info(
            'Build id: %s/%d',
            config.builder_id_string(req.builder),
            req.build_number,
        )
        tag = buildtags.build_address_tag(req.builder, req.build_number)
        q = search.Query(
            bucket_ids=[bucket_id_string(req.builder)],
            tags=[tag],
            include_experimental=True,
        )
        found, _ = yield search.search_async(q)
        build = found[0] if found else None

    if not build:
        raise not_found()
    yield build_to_proto_async(build, res, mask)
Esempio n. 2
0
 def get(self, request):
     """Returns a build by id."""
     try:
         build = service.get_async(request.id).get_result()
     except auth.AuthorizationError:
         build = None
     if build is None:
         raise errors.BuildNotFoundError()
     return build_to_response_message(build)
Esempio n. 3
0
 def test_get_with_auth_error(self):
     self.mock_cannot(user.Action.VIEW_BUILD)
     self.classic_build(id=1).put()
     with self.assertRaises(auth.AuthorizationError):
         service.get_async(1).get_result()
Esempio n. 4
0
 def test_get_nonexistent_build(self):
     self.assertIsNone(service.get_async(42).get_result())
Esempio n. 5
0
 def test_get(self):
     self.classic_build(id=1).put()
     build = service.get_async(1).get_result()
     self.assertEqual(build, build)