Пример #1
0
def _translate_grpc_error():
    try:
        yield
    except grpc.RpcError as e:
        if e.code() == grpc.StatusCode.INVALID_ARGUMENT:
            raise errors.InvalidArgumentError(e.details())
        if e.code() == grpc.StatusCode.NOT_FOUND:
            raise errors.NotFoundError(e.details())
        if e.code() == grpc.StatusCode.PERMISSION_DENIED:
            raise errors.PermissionDeniedError(e.details())
        raise
Пример #2
0
 def test_http_code(self):
     self.assertEqual(errors.PermissionDeniedError().http_code, 403)
Пример #3
0
 def test_no_details(self):
     e = errors.PermissionDeniedError()
     expected_msg = "Permission denied"
     self.assertEqual(str(e), expected_msg)
Пример #4
0
 def test_with_details(self):
     e = errors.PermissionDeniedError("this data is top secret")
     expected_msg = "Permission denied: this data is top secret"
     self.assertEqual(str(e), expected_msg)
Пример #5
0
 def test_headers(self):
     e1 = errors.PermissionDeniedError()
     e2 = errors.PermissionDeniedError()
     self.assertEmpty(e1.headers)
     self.assertIsNot(e1.headers, e2.headers)