Example #1
0
    def testGetDefaultVersion(self):
        api_name = 'dns'
        default_api_def = apis_internal._GetApiDef(api_name, 'v1')

        default_version = apis_internal._GetDefaultVersion(api_name)
        also_default_api_def = apis_internal._GetApiDef(
            api_name, default_version)

        self.assertEqual(default_api_def, also_default_api_def)
Example #2
0
 def testAddToApisMap_NoDefault(self):
     apis.AddToApisMap('hello', 'v1')
     self.assertTrue(
         apis_internal._GetApiDef('hello', 'v1').default_version)
     apis.AddToApisMap('hello', 'v2')
     self.assertFalse(
         apis_internal._GetApiDef('hello', 'v2').default_version)
     self.assertTrue(
         apis_internal._GetApiDef('hello', 'v1').default_version)
Example #3
0
def SetDefaultVersion(api_name, api_version):
    """Resets default version for given api."""
    # pylint:disable=protected-access
    api_def = apis_internal._GetApiDef(api_name, api_version)
    # pylint:disable=protected-access
    default_version = apis_internal._GetDefaultVersion(api_name)
    # pylint:disable=protected-access
    default_api_def = apis_internal._GetApiDef(api_name, default_version)
    default_api_def.default_version = False
    api_def.default_version = True
Example #4
0
def SetDefaultVersion(api_name, api_version):
  """Resets default version for given api."""
  # pylint:disable=protected-access
  api_def = apis_internal._GetApiDef(api_name, api_version)
  # pylint:disable=protected-access
  default_version = apis_internal._GetDefaultVersion(api_name)
  # pylint:disable=protected-access
  default_api_def = apis_internal._GetApiDef(api_name, default_version)
  default_api_def.default_version = False
  api_def.default_version = True
Example #5
0
    def testAddToApisMap(self):
        with self.assertRaisesRegex(
                apis_util.UnknownAPIError,
                r'API named \[hello\] does not exist in the APIs map'):
            apis_internal._GetApiDef('hello', 'v1')

        expected_api_def = apis.ConstructApiDef('hello', 'v1', True)
        apis.AddToApisMap('hello', 'v1', True)
        self.assertEqual('v1', apis_internal._GetDefaultVersion('hello'))
        self.assertEqual(expected_api_def,
                         apis_internal._GetApiDef('hello', 'v1'))
Example #6
0
def GetMessagesModule(api_name, api_version):
    """Returns the messages module for the API specified in the args.

  Args:
    api_name: str, The API name (or the command surface name, if different).
    api_version: str, The version of the API.

  Returns:
    Module containing the definitions of messages for the specified API.
  """
    # pylint:disable=protected-access
    api_def = apis_internal._GetApiDef(api_name, api_version)
    # fromlist below must not be empty, see:
    # http://stackoverflow.com/questions/2724260/why-does-pythons-import-require-fromlist.
    return __import__(api_def.messages_full_modulepath, fromlist=['something'])
Example #7
0
def GetAPI(api_name, api_version=None):
  """Get a specific API definition.

  Args:
    api_name: str, The name of the API.
    api_version: str, The version string of the API.

  Returns:
    API, The API definition.
  """
  api_version = _ValidateAndGetDefaultVersion(api_name, api_version)
  # pylint: disable=protected-access
  api_def = apis_internal._GetApiDef(api_name, api_version)
  api_client = apis_internal._GetClientClassFromDef(api_def)
  return API(api_name, api_version, api_def.default_version, api_client)
Example #8
0
def GetAPI(api_name, api_version=None):
  """Get a specific API definition.

  Args:
    api_name: str, The name of the API.
    api_version: str, The version string of the API.

  Returns:
    API, The API definition.
  """
  api_version = _ValidateAndGetDefaultVersion(api_name, api_version)
  # pylint: disable=protected-access
  api_def = apis_internal._GetApiDef(api_name, api_version)
  api_client = apis_internal._GetClientClassFromDef(api_def)
  return API(api_name, api_version, api_def.default_version, api_client)
Example #9
0
def GetMessagesModule(api_name, api_version):
  """Returns the messages module for the API specified in the args.

  Args:
    api_name: str, The API name (or the command surface name, if different).
    api_version: str, The version of the API.

  Returns:
    Module containing the definitions of messages for the specified API.
  """
  # pylint:disable=protected-access
  api_def = apis_internal._GetApiDef(api_name, api_version)
  # fromlist below must not be empty, see:
  # http://stackoverflow.com/questions/2724260/why-does-pythons-import-require-fromlist.
  return __import__(api_def.messages_full_modulepath, fromlist=['something'])
Example #10
0
 def testGetApiDefUnknownVersion(self):
     with self.assertRaisesRegex(
             apis_util.UnknownVersionError,
             r'The \[compute\] API does not have version \[hello\] in the APIs map'
     ):
         apis_internal._GetApiDef('compute', 'hello')
Example #11
0
 def testGetApiDefUnknownAPI(self):
     with self.assertRaisesRegex(
             apis_util.UnknownAPIError,
             r'API named \[hello\] does not exist in the APIs map'):
         apis_internal._GetApiDef('hello', 'v1')
Example #12
0
 def testGetApiDefWithOverride(self):
     expected_api_def = apis.ConstructApiDef('compute', 'alpha', False)
     properties.VALUES.api_client_overrides.compute.Set('alpha')
     actual_api_def = apis_internal._GetApiDef('compute', 'v1')
     self.assertEqual(expected_api_def, actual_api_def)
Example #13
0
 def testGetDefaultApiDef(self):
     expected_api_def = apis.ConstructApiDef('dns', 'v1', True)
     actual_api_def = apis_internal._GetApiDef('dns', 'v1')
     self.assertEqual(expected_api_def, actual_api_def)
 def testSanityOfGeneratedApisMap(self):
     for api_name, ver_map in six.iteritems(apis_map.MAP):
         for ver, api_definition in six.iteritems(ver_map):
             self.assertEqual(api_definition,
                              core_apis._GetApiDef(api_name, ver))