def SetUp(self): self.compute_v1_mtls_endpoint = 'https://compute.mtls.googleapis.com/compute/v1/' self.compute_v1_endpoint = 'https://compute.googleapis.com/compute/v1/' self.compute_v1_api_def = apis_map.APIDef( class_path='googlecloudsdk.third_party.apis.compute.v1', client_classpath='compute_v1_client.ComputeV1', messages_modulepath='compute_v1_messages', default_version=True, enable_mtls=True, mtls_endpoint_override=self.compute_v1_mtls_endpoint) self.spanner_v1_endpoint = 'https://spanner.googleapis.com/' self.spanner_v1_mtls_endpoint = 'https://spanner.mtls.googleapis.com/' self.spanner_v1_api_def = apis_map.APIDef( class_path='googlecloudsdk.third_party.apis.spanner.v1', client_classpath='spanner_v1_client.SpannerV1', messages_modulepath='spanner_v1_messages', default_version=True, enable_mtls=True, mtls_endpoint_override='') self.redis_v1_endpoint = 'https://redis.googleapis.com/' self.redis_v1_api_def = apis_map.APIDef( class_path='googlecloudsdk.third_party.apis.redis.v1', client_classpath='redis_v1_client.RedisV1', messages_modulepath='redis_v1_messages', default_version=True, enable_mtls=False, mtls_endpoint_override='')
def ConstructApiDef(api_name, api_version, is_default, base_pkg='googlecloudsdk.third_party.apis'): """Creates and returns the APIDef specified by the given arguments. Args: api_name: str, The API name (or the command surface name, if different). api_version: str, The version of the API. is_default: bool, Whether this API version is the default. base_pkg: str, Base package from which generated API files are accessed. Returns: APIDef, The APIDef created using the given args. """ # pylint:disable=protected-access api_name, _ = apis_internal._GetApiNameAndAlias(api_name) client_cls_name = _CamelCase(api_name) + _CamelCase(api_version) class_path = '{base}.{api_name}.{api_version}'.format( base=base_pkg, api_name=api_name, api_version=api_version,) common_fmt = '{api_name}_{api_version}_' client_cls_path_fmt = common_fmt + 'client.{api_client_class}' client_cls_path = client_cls_path_fmt.format(api_name=api_name, api_version=api_version, api_client_class=client_cls_name) messages_mod_path_fmt = common_fmt + 'messages' messages_mod_path = messages_mod_path_fmt.format(api_name=api_name, api_version=api_version) return apis_map.APIDef(class_path, client_cls_path, messages_mod_path, is_default)
def MockAPIs(self, *mock_apis): """Mocks out the API list.""" api_list = [] api_map = {} for x in mock_apis: name, version, default = x client_mock = mock.MagicMock() client_mock.BASE_URL = 'https://{}.googleapis.com/'.format(name) api_list.append(registry.API(name, version, default, client_mock)) api_map.setdefault(name, {})[version] = apis_map.APIDef( '', '', '', default) resources.REGISTRY.registered_apis[name] = [version] self.StartObjectPatch(registry, 'GetAllAPIs').return_value = api_list self.StartDictPatch('googlecloudsdk.third_party.apis.apis_map.MAP', api_map)
def testConstructAPIDef(self): expected_api_def = apis_map.APIDef( 'googlecloudsdk.third_party.apis.dns.v1', 'dns_v1_client.DnsV1', 'dns_v1_messages', True) actual_api_def = apis.ConstructApiDef('dns', 'v1', True) self.assertEqual(expected_api_def, actual_api_def)