コード例 #1
0
def get_versions(module=None):
    """Returns a list of versions for a given module.

  Args:
    module: Module to retrieve version for, if None then the current module will
      be used.

  Returns:
    List of strings containing the names of versions associated with the module.
    The current version will also be included in this list.

  Raises:
    InvalidModuleError if the given module isn't valid, TransientError if there
    is an issue fetching the information.
  """
    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb2.ModulesServiceError.INVALID_MODULE,
            modules_service_pb2.ModulesServiceError.TRANSIENT_ERROR
        ]
        _CheckAsyncResult(rpc, mapped_errors, {})

        return rpc.response.version

    request = modules_service_pb2.GetVersionsRequest()
    if module:
        request.module = module
    response = modules_service_pb2.GetVersionsResponse()
    return _MakeAsyncCall('GetVersions', request, response,
                          _ResultHook).get_result()
コード例 #2
0
 def testGetVersions_NoModule(self):
   """Test we return the expected results when no module is passed."""
   expected_request = modules_service_pb2.GetVersionsRequest()
   service_response = modules_service_pb2.GetVersionsResponse()
   service_response.version.append('v1')
   service_response.version.append('v2')
   self.SetSuccessExpectations('GetVersions',
                               expected_request,
                               service_response)
   self.assertEqual(['v1', 'v2'], modules.get_versions())
コード例 #3
0
 def testGetVersions_TransientError(self):
   """Test we raise the right error when a transient error is encountered."""
   self.SetExceptionExpectations(
       'GetVersions', modules_service_pb2.GetVersionsRequest(),
       modules_service_pb2.ModulesServiceError.TRANSIENT_ERROR)
   self.assertRaises(modules.TransientError, modules.get_versions)
コード例 #4
0
 def testGetVersions_InvalidModuleError(self):
   """Test we raise the right error when the given module is invalid."""
   self.SetExceptionExpectations(
       'GetVersions', modules_service_pb2.GetVersionsRequest(),
       modules_service_pb2.ModulesServiceError.INVALID_MODULE)
   self.assertRaises(modules.InvalidModuleError, modules.get_versions)