Exemplo n.º 1
0
    def testGetAPICollections(self):
        c = registry.GetAPICollections()
        self.assertGreater(len(c), 100)
        c = registry.GetAPICollections('compute')
        self.assertLess(len(c), 100)
        self.assertGreater(len(c), 10)
        c = registry.GetAPICollections('compute', 'v1')
        self.assertLess(len(c), 100)
        self.assertGreater(len(c), 10)

        with self.assertRaises(registry.UnknownAPIError):
            registry.GetAPICollections('junk')
        with self.assertRaises(registry.UnknownAPIVersionError):
            registry.GetAPICollections('compute', 'junk')
Exemplo n.º 2
0
  def Run(self, args):
    if args.api_version and not args.api:
      raise exceptions.RequiredArgumentException(
          '--api',
          'The --api-version flag can only be specified when using the --api '
          'flag.')

    collections = registry.GetAPICollections(api_name=args.api,
                                             api_version=args.api_version)
    results = []
    for c in collections:
      methods = registry.GetMethods(c.full_name, api_version=c.api_version)
      if not methods:
        # Synthetic collection
        continue

      list_methods = [m for m in methods if m.IsList()]
      if list_methods:
        method = list_methods[0]
        results.append({'collection': c.full_name,
                        'has_list': True,
                        'resource_arg': bool(method.RequestCollection()),
                        'flattened': bool(method.ListItemField()),
                        'pageable': method.IsPageableList(),
                        'page_size': bool(method.BatchPageSizeField())})
      else:
        results.append({'collection': c.full_name, 'has_list': False})

    # Filter out anything that is fully within spec.
    results = [r for r in results if not (r['has_list'] and
                                          r['resource_arg'] and
                                          r['flattened'] and
                                          r['pageable'] and
                                          r['page_size'])]
    return results
Exemplo n.º 3
0
    def Run(self, args):
        if args.api_version and not args.api:
            raise exceptions.RequiredArgumentException(
                '--api',
                'The --api-version flag can only be specified when using the --api '
                'flag.')

        return registry.GetAPICollections(api_name=args.api,
                                          api_version=args.api_version)
Exemplo n.º 4
0
def _MatchCollection(resource_spec, attribute):
    """Gets the collection for an attribute in a resource."""
    resource_collection_info = resource_spec._collection_info  # pylint: disable=protected-access
    resource_collection = registry.APICollection(resource_collection_info)
    if resource_collection is None:
        return None
    if attribute == resource_spec.attributes[-1]:
        return resource_collection.name
    attribute_idx = resource_spec.attributes.index(attribute)
    api_name = resource_collection_info.api_name
    resource_collections = registry.GetAPICollections(
        api_name, resource_collection_info.api_version)
    params = resource_collection.detailed_params[:attribute_idx + 1]
    for c in resource_collections:
        if c.detailed_params == params:
            return c.name
Exemplo n.º 5
0
    def Run(self, args):
        if not args.collection:
            collections = [
                registry.GetAPICollections(api.name, api.version)
                for api in registry.GetAllAPIs()
            ]
            collections = list(itertools.chain.from_iterable(collections))
            methods = [
                registry.GetMethods(collection.full_name,
                                    api_version=collection.api_version)
                for collection in collections
            ]
            methods = list(itertools.chain.from_iterable(methods))
            return methods

        return registry.GetMethods(args.collection,
                                   api_version=args.api_version)
Exemplo n.º 6
0
    def testGetAPICollection(self):
        # Flat path resource.
        c = registry.GetAPICollection('compute.instances', 'v1')
        self.assertEqual(c.api_name, 'compute')
        self.assertEqual(c.api_version, 'v1')
        self.assertEqual(c.name, 'instances')
        self.assertEqual(c.full_name, 'compute.instances')
        self.assertEqual(c.base_url,
                         'https://compute.googleapis.com/compute/v1/')
        self.assertEqual(
            c.docs_url,
            'https://developers.google.com/compute/docs/reference/latest/')
        self.assertEqual(
            c.detailed_path,
            'projects/{project}/zones/{zone}/instances/{instance}')
        self.assertEqual(c.detailed_params, ['project', 'zone', 'instance'])
        self.assertEqual(
            c.path, 'projects/{project}/zones/{zone}/instances/{instance}')
        self.assertEqual(c.params, ['project', 'zone', 'instance'])

        # Atomic name resource.
        c = registry.GetAPICollection('pubsub.projects.topics', 'v1')
        self.assertEqual(c.api_name, 'pubsub')
        self.assertEqual(c.api_version, 'v1')
        self.assertEqual(c.name, 'projects.topics')
        self.assertEqual(c.full_name, 'pubsub.projects.topics')
        self.assertEqual(c.base_url, 'https://pubsub.googleapis.com/v1/')
        self.assertEqual(c.docs_url, 'https://cloud.google.com/pubsub/docs')
        self.assertEqual(c.detailed_path,
                         'projects/{projectsId}/topics/{topicsId}')
        self.assertEqual(c.detailed_params, ['projectsId', 'topicsId'])
        self.assertEqual(c.path, '{+topic}')
        self.assertEqual(c.params, ['topic'])

        with self.assertRaises(registry.UnknownAPIError):
            registry.GetAPICollections('junk')
        with self.assertRaises(registry.UnknownCollectionError):
            registry.GetAPICollection('compute.junk')
        with self.assertRaises(registry.UnknownAPIVersionError):
            registry.GetAPICollection('compute.instances', 'junk')
Exemplo n.º 7
0
def CollectionCompleter(**_):
    return [c.full_name for c in registry.GetAPICollections()]