コード例 #1
0
 def parent_child_resource(self):
     """A multitype concept spec with four types."""
     project_shelf_book_resource = util.GetBookResource('book')
     project_shelf_resource = util.GetProjShelfResource('shelf')
     return multitype.MultitypeResourceSpec('book',
                                            project_shelf_book_resource,
                                            project_shelf_resource)
コード例 #2
0
 def SetUp(self):
     # The child.
     book_resource = util.GetBookResource(name='book')
     # Shelves are the parent - they contain books.
     shelf_resource = util.GetProjShelfResource(name='shelf')
     self.resource = multitype.MultitypeResourceSpec(
         'shelfbook', book_resource, shelf_resource)
コード例 #3
0
 def two_way_shelf_case_book(self):
     project_shelf_book_resource = util.GetBookResource(name='shelfbook')
     project_case_book_resource = util.GetProjCaseBookResource(
         name='casebook')
     return multitype.MultitypeResourceSpec('book',
                                            project_shelf_book_resource,
                                            project_case_book_resource)
コード例 #4
0
 def testCreateMultiTypeResource(self):
     project_book_resource = util.GetBookResource(name='projectbook')
     organization_book_resource = util.GetOrgShelfBookResource(
         name='orgbook')
     resource = multitype.MultitypeResourceSpec('book',
                                                project_book_resource,
                                                organization_book_resource)
     expected_attributes = (project_book_resource.attributes +
                            organization_book_resource.attributes[:1])
     self.assertEqual(expected_attributes, resource.attributes)
     self.assertNotEqual(resource.type_enum['projectbook'],
                         resource.type_enum['orgbook'])
     self.assertEqual(
         {
             'project': [resource.type_enum['projectbook']],
             'organization': [resource.type_enum['orgbook']],
             'shelf': [
                 resource.type_enum['projectbook'],
                 resource.type_enum['orgbook']
             ],
             'book': [
                 resource.type_enum['projectbook'],
                 resource.type_enum['orgbook']
             ]
         }, resource._attribute_to_types_map)
コード例 #5
0
 def SetUp(self):
     """Get resource with two possible top-level params."""
     project_book_resource = util.GetBookResource(name='projectbook')
     organization_book_resource = util.GetOrgShelfBookResource(
         name='orgbook')
     self.resource = multitype.MultitypeResourceSpec(
         'book', project_book_resource, organization_book_resource)
コード例 #6
0
  def testCompleterWithArbitraryArgFallthrough(self):
    collections = [
        ('example.projects.shelves.books', True),
        ('example.projects.shelves', True),
        ('cloudresourcemanager.projects', True)]
    self.MockCRUDMethods(*collections)
    self.PatchBookResourceReturnTypes()
    parent_name = 'projects/exampleproject/shelves/s0'
    self.mock_client.projects_shelves_books.List.return_value = (
        self.BuildBooksList(['{}/books/b0'.format(parent_name),
                             '{}/books/b1'.format(parent_name)]))
    resource_spec = util.GetBookResource()
    resource_spec.attributes[1].fallthroughs.append(
        deps.ArgFallthrough('--other'))

    expected_results = ['b0', 'b1']
    self.RunResourceCompleter(
        resource_spec,
        'book',
        presentation_name='--book',
        dest='book',
        args={'--book-project': 'exampleproject',
              '--other': 's0'},
        flag_name_overrides={'project': '--book-project'},
        expected_completions=expected_results)
コード例 #7
0
 def testCreateMultiTypeConceptRenamesTypes(self):
     project_book_resource = util.GetBookResource()
     organization_book_resource = util.GetOrgShelfBookResource()
     resource = multitype.MultitypeConceptSpec('book',
                                               project_book_resource,
                                               organization_book_resource)
     self.assertNotEqual(resource.type_enum['book_project_shelf_book'],
                         resource.type_enum['book_organization_shelf_book'])
コード例 #8
0
 def testCreateMultiTypeResourceRenamesTypes(self):
     project_book_resource = util.GetBookResource()
     organization_book_resource = util.GetOrgShelfBookResource()
     resource = multitype.MultitypeResourceSpec('book',
                                                project_book_resource,
                                                organization_book_resource)
     self.assertNotEqual(
         resource.type_enum['example.projects.shelves.books'],
         resource.type_enum['example.organizations.shelves.books'])
コード例 #9
0
 def four_way_parent_child_resource(self):
     """A multitype concept spec with four types."""
     project_shelf_book_resource = util.GetBookResource()
     organization_shelf_book_resource = util.GetOrgShelfBookResource()
     project_shelf_resource = util.GetProjShelfResource()
     organization_shelf_resource = util.GetOrgShelfResource()
     return multitype.MultitypeResourceSpec(
         'book', project_shelf_book_resource,
         organization_shelf_book_resource, project_shelf_resource,
         organization_shelf_resource)
コード例 #10
0
 def four_way_resource(self):
     """A multitype concept spec with four types."""
     project_shelf_book_resource = util.GetBookResource(name='projectbook')
     organization_shelf_book_resource = util.GetOrgShelfBookResource(
         name='orgshelfbook')
     project_case_book_resource = util.GetProjCaseBookResource(
         name='projcasebook')
     organization_case_book_resource = util.GetOrgCaseBookResource(
         name='orgcasebook')
     return multitype.MultitypeResourceSpec(
         'book', project_shelf_book_resource,
         organization_shelf_book_resource, project_case_book_resource,
         organization_case_book_resource)
コード例 #11
0
 def testCreateMultiTypeResourceFailsWithMismatchedAttribute(self):
     book_resource = util.GetBookResource()
     # Create a second resource with an attribute named "project" that doesn't
     # match the book resource's project attribute.
     project_resource = concepts.ResourceSpec(
         'example.projects',
         'project',
         projectsId=concepts.ResourceParameterAttributeConfig(
             name='project',
             help_text='The Cloud project of the {resource}.'))
     with self.assertRaisesRegexp(multitype.ConfigurationError,
                                  re.escape('[project]')):
         multitype.MultitypeResourceSpec('book', book_resource,
                                         project_resource)
コード例 #12
0
 def SetUpConceptParserWithFallthroughs(self, name, fallthroughs_map=None):
     resource_spec = util.GetBookResource()
     fallthroughs_map = fallthroughs_map or {}
     for attribute in resource_spec.attributes:
         fallthroughs = fallthroughs_map.get(attribute.name, [])
         attribute.fallthroughs = fallthroughs
     flag_name_overrides = {'project': '--book-project'}
     concept_parsers.ConceptParser([
         presentation_specs.ResourcePresentationSpec(
             name,
             resource_spec,
             'a resource',
             flag_name_overrides=flag_name_overrides)
     ]).AddToParser(self.parser)
コード例 #13
0
  def testCompleterForAttribute_DifferentVersions(self):
    collections = [
        ('example.projects.shelves.books', True),
        ('example.projects.shelves', True),
        ('example.projects', True),
        ('example.projects.shelves.books', True, 'v1beta1'),
        ('example.projects.shelves', True, 'v1beta1'),
        ('example.projects', True, 'v1beta1')]
    self.MockCRUDMethods(*collections)
    book_collection = registry.GetAPICollection(
        'example.projects.shelves.books', 'v1beta1')
    resource_spec = util.GetBookResource(api_version='v1beta1')

    expected_completer = completers.ResourceArgumentCompleter(
        resource_spec,
        book_collection,
        registry.GetMethod('example.projects.shelves.books', 'list',
                           api_version='v1beta1'),
        param='booksId',
        static_params={})
    completer = completers.CompleterForAttribute(self.resource_spec, 'book')()

    self.assertEqual(expected_completer, completer)
    expected_completer = completers.ResourceArgumentCompleter(
        resource_spec,
        registry.GetAPICollection('example.projects.shelves', 'v1beta1'),
        registry.GetMethod('example.projects.shelves', 'list',
                           api_version='v1beta1'),
        param='shelvesId',
        static_params={})
    completer = completers.CompleterForAttribute(self.resource_spec, 'shelf')()
    self.assertEqual(expected_completer, completer)

    expected_completer = completers.ResourceArgumentCompleter(
        self.resource_spec,
        registry.GetAPICollection('example.projects', 'v1beta1'),
        registry.GetMethod('example.projects', 'list', api_version='v1beta1'),
        param='projectsId',
        static_params={})
    completer = completers.CompleterForAttribute(
        self.resource_spec, 'project')()
    self.assertEqual(expected_completer, completer)
コード例 #14
0
 def resource_spec_auto_completers(self):
     """A basic resource spec for the fake "book" resource with auto complete."""
     # Lazy creation allows checking of the GetCollectionInfo mock.
     return util.GetBookResource(auto_completers=True)
コード例 #15
0
 def resource_spec_completers(self):
     """A basic resource spec for the fake "book" resource, with completers."""
     return util.GetBookResource(with_completers=True)
コード例 #16
0
 def resource_spec(self):
     """A basic resource spec for the fake "book" resource."""
     # Lazy creation allows checking of the GetCollectionInfo mock.
     return util.GetBookResource()
コード例 #17
0
 def multitype_extra_attribute_in_path(self):
     plain_resource = util.GetBookResource(name='book')
     # Shelves are the parent - they contain books.
     with_case_resource = util.GetProjCaseShelfBookResource(name='book')
     return multitype.MultitypeResourceSpec('book', plain_resource,
                                            with_case_resource)
コード例 #18
0
 def testCreateMultitypeResourceFailsWithDuplicateCollection(self):
     project_book_resource = util.GetBookResource()
     with self.assertRaisesRegexp(ValueError, 'projects.shelves.books'):
         multitype.MultitypeResourceSpec('book', project_book_resource,
                                         project_book_resource)
コード例 #19
0
 def two_way_resource(self):
     project_book_resource = util.GetBookResource(name='projectbook')
     organization_book_resource = util.GetOrgShelfBookResource(
         name='orgbook')
     return multitype.MultitypeResourceSpec('book', project_book_resource,
                                            organization_book_resource)